The connectors behind Harambee: sources that read beneficiary submissions, a writer for the instruction file the Stellar Disbursement Platform (SDP) takes, and a client for the SDP itself.
The data types and the validation, dedupe and pricing logic live in
@harambee-aid/core. The command line that ties
it together is cli.
pnpm add @harambee-aid/connectors @harambee-aid/coreNeeds Node 22 or newer. The package is ESM only.
| Export | What it does |
|---|---|
CsvSource |
Reads submissions from a CSV file, such as a KoboToolbox export |
KoboSource |
Reads submissions from the KoboToolbox API, page by page |
KoboWriteback |
Marks submissions Approved, Not Approved or On Hold in Kobo |
buildInstructionsCsv |
Turns transfers from core into the file the SDP expects |
SdpClient |
Creates a disbursement, uploads the file, lists payments |
This reads a CSV, builds a batch, stages it in the SDP and lists the payments.
import { buildBatch } from '@harambee-aid/core';
import { CsvSource, SdpClient, buildInstructionsCsv } from '@harambee-aid/connectors';
const submissions = [];
for await (const s of new CsvSource({ path: './registrations.csv' }).read()) submissions.push(s);
const batch = buildBatch(submissions, {
name: 'November payout',
mapping: { name: 'name', phone: 'phone', verification: 'dob', householdSize: 'members' },
validation: { contact: 'PHONE_NUMBER', defaultCountry: 'KE', verification: 'DATE_OF_BIRTH' },
amount: { rule: { type: 'per_household', base: '10', perMember: '5' } },
});
const sdp = new SdpClient({ baseUrl: process.env.SDP_URL, apiKey: process.env.SDP_API_KEY });
const disbursement = await sdp.createDisbursement({
name: batch.name,
assetId: process.env.SDP_ASSET_ID,
walletId: process.env.SDP_WALLET_ID,
contactType: 'PHONE_NUMBER',
verificationField: 'DATE_OF_BIRTH',
});
const csv = buildInstructionsCsv(batch.transfers, { contact: 'PHONE_NUMBER', verification: true });
await sdp.uploadInstructions(disbursement.id, csv);
// the disbursement is now READY. Someone with approval rights starts it in the SDP.
for await (const p of sdp.listPayments({ type: 'DISBURSEMENT' })) {
console.log(p.externalPaymentId, p.status);
}SdpClient has no method to start, pause or approve a disbursement, and a test keeps it
that way. Uploading the instruction file moves a disbursement from DRAFT to READY.
Only a person in the SDP can start it, and starting is what begins payments.
buildInstructionsCsv writes each submission id into the paymentID column. The SDP
returns it as externalPaymentId on every payment, so a payment can always be traced to
the submission it came from. The SDP allows at most 64 characters in the id columns, and
the writer checks that before anything is uploaded.
CsvSource
- Needs an id column,
_idby default (setidColumnto change it). Repeated ids are an error. - Reads
_submission_timewhen it is there. Kobo writes it in UTC without a zone, and it is read that way. delimiterdefaults to a comma.- Set
delimiter: 'auto'to detect commas, semicolons, or tabs from the header. Delimiters inside quoted header cells are ignored; ambiguous or single-column headers fall back to a comma. Explicit delimiters still take precedence.
KoboSource
- Accepts
fields: ['group/question', 'household_size']to request only selected questions on every page._idand_submission_timeare always included in that selection, and duplicate field names are removed. Omittingfieldskeeps the full submission behavior;fields: []requests metadata only. - Authenticates with your API token and asks for submissions in id order.
- Follows the
nextlink only when it stays on the configured server, so the token never goes to another host. - Repeat groups come through as arrays and are read with
core's field mapping, for examplemembers[0]/name.
KoboWriteback
- Kobo only lets a client set the validation status, so that is all this does. It never edits the answers a respondent gave.
- Sends submissions in batches and refuses ids that are not numbers before sending any.
SdpClient
- Authenticates with
Authorization: Bearer SDP_.... The key is never put in an error message. - The SDP is multi-tenant and picks the tenant from the subdomain, so
baseUrllooks likehttp://acme.stellar.local:8000. - Failures raise
SdpErrorwith the HTTP status. When the SDP rejects the instruction file, the line-by-line reasons are inerror.extras.
pnpm install
pnpm lint
pnpm typecheck
pnpm test
pnpm buildSee the contributing guide.
Apache-2.0