pesafy 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +126 -0
- package/LICENSE +21 -0
- package/README.md +1519 -0
- package/dist/adapters/express.d.ts +106 -0
- package/dist/adapters/express.js +1 -0
- package/dist/adapters/fastify.d.ts +82 -0
- package/dist/adapters/fastify.js +1 -0
- package/dist/adapters/hono.d.ts +106 -0
- package/dist/adapters/hono.js +1 -0
- package/dist/adapters/nextjs.d.ts +183 -0
- package/dist/adapters/nextjs.js +1 -0
- package/dist/chunk.js +1 -0
- package/dist/cli.mjs +641 -0
- package/dist/encryption.mjs +22 -0
- package/dist/errors.mjs +41 -0
- package/dist/index.d.ts +837 -0
- package/dist/index.js +1 -0
- package/dist/phone.mjs +23 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +0 -0
- package/dist/types.d.ts +1259 -0
- package/dist/utils.mjs +32 -0
- package/dist/webhook-guard.js +1 -0
- package/package.json +213 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
# pesafy
|
|
2
|
+
|
|
3
|
+
## 0.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- b8dd427: # pesafy 0.0.1 — first public release
|
|
8
|
+
|
|
9
|
+
First publish of the **pesafy** M-PESA Daraja SDK to npm.
|
|
10
|
+
|
|
11
|
+
## Package foundation
|
|
12
|
+
- Official npm registry only (`.npmrc`, pinned lockfile, `zod` runtime
|
|
13
|
+
dependency)
|
|
14
|
+
- Version **0.0.1** with Changesets, `CHANGELOG.md`, and npm provenance
|
|
15
|
+
- Hardened `prepublishOnly`: lint, format, typecheck, coverage, build,
|
|
16
|
+
size-limit
|
|
17
|
+
- CI publish workflow: lint, format, coverage, build before release
|
|
18
|
+
|
|
19
|
+
## Features
|
|
20
|
+
- **Mpesa client** — STK Push, C2B, B2C/B2B, account balance, transaction
|
|
21
|
+
status, reversal, tax remittance, dynamic QR, bill manager
|
|
22
|
+
- **Idempotency** — automatic `Idempotency-Key` on mutating POSTs,
|
|
23
|
+
`IdempotencyManager`, pluggable store, auto `OriginatorConversationID` for
|
|
24
|
+
B2C disbursement
|
|
25
|
+
- **Zod validation** — runtime schemas for STK Push, B2C Disbursement, B2B
|
|
26
|
+
Express Checkout, webhooks; exported from `pesafy`
|
|
27
|
+
- **Webhooks** — Safaricom IP allowlist, STK/callback helpers, opt-in HMAC
|
|
28
|
+
preview (`verifyWebhook`, `verifyWebhookHMAC`)
|
|
29
|
+
- **Framework adapters** — Express, Hono, Fastify, Next.js
|
|
30
|
+
- **CLI**, branded types, `Result<T>` safe methods, encryption, phone
|
|
31
|
+
utilities
|
|
32
|
+
|
|
33
|
+
## Breaking note
|
|
34
|
+
|
|
35
|
+
Initial public API at 0.0.1; stricter Zod validation may reject payloads that
|
|
36
|
+
previously passed loose checks.
|
|
37
|
+
|
|
38
|
+
- 0a01848: Security hardening and production safety fixes.
|
|
39
|
+
|
|
40
|
+
**Fixes**
|
|
41
|
+
- Idempotency: remove global HTTP context race; pass `idempotency` explicitly
|
|
42
|
+
via `DarajaHttpOptions` on every outbound call
|
|
43
|
+
- C2B simulate: require `billRefNumber` for `CustomerPayBillOnline`
|
|
44
|
+
- `KesAmountSchema`: reject amounts that round below 1 KES
|
|
45
|
+
|
|
46
|
+
**Breaking**
|
|
47
|
+
- `verifyWebhook` and `verifyWebhookHMAC` are now **async** (Web Crypto,
|
|
48
|
+
portable across Node/Bun/Deno/Workers)
|
|
49
|
+
|
|
50
|
+
**Features**
|
|
51
|
+
- Zod validation on all outbound Daraja APIs (request + response)
|
|
52
|
+
- Framework adapters: optional `webhookSecret`, `requireHMAC`,
|
|
53
|
+
`signatureHeader` with `verifyWebhook` + raw body
|
|
54
|
+
- `C2BBaseResponse` shared type for register/simulate responses
|
|
55
|
+
|
|
56
|
+
**Chore**
|
|
57
|
+
- `pnpm.overrides`: `fastify >= 5.8.5`
|
|
58
|
+
- Security docs: trusted proxies, multi-instance idempotency, HMAC opt-in
|
|
59
|
+
|
|
60
|
+
## Unreleased
|
|
61
|
+
|
|
62
|
+
### Security hardening (0.0.2)
|
|
63
|
+
|
|
64
|
+
#### Fixes
|
|
65
|
+
|
|
66
|
+
- **Idempotency concurrency** — removed module-level HTTP context;
|
|
67
|
+
`IdempotencyManager` is passed explicitly via `DarajaHttpOptions` /
|
|
68
|
+
`HttpRequestOptions.idempotency` (no cross-request key leakage under
|
|
69
|
+
concurrent `Mpesa` calls)
|
|
70
|
+
- **C2B simulate** — `billRefNumber` required for `CustomerPayBillOnline`
|
|
71
|
+
- **Amount validation** — `KesAmountSchema` rejects values that round below 1
|
|
72
|
+
KES
|
|
73
|
+
|
|
74
|
+
#### Breaking
|
|
75
|
+
|
|
76
|
+
- `verifyWebhook` and `verifyWebhookHMAC` are **async** (Web Crypto; works on
|
|
77
|
+
Node, Bun, Deno, Workers)
|
|
78
|
+
|
|
79
|
+
#### Features
|
|
80
|
+
|
|
81
|
+
- **Zod** on all outbound Daraja APIs (request + response parsing at HTTP
|
|
82
|
+
boundaries)
|
|
83
|
+
- **Adapters** — optional HMAC webhook verification (`webhookSecret`,
|
|
84
|
+
`requireHMAC`, `signatureHeader`) using raw body + `verifyWebhook`
|
|
85
|
+
- **`C2BBaseResponse`** — shared type for C2B register/simulate responses
|
|
86
|
+
|
|
87
|
+
#### Chore
|
|
88
|
+
|
|
89
|
+
- `pnpm.overrides`: `fastify >= 5.8.5`
|
|
90
|
+
- Docs: trusted reverse proxies, multi-instance idempotency stores, HMAC preview
|
|
91
|
+
constraints
|
|
92
|
+
|
|
93
|
+
## 0.0.1
|
|
94
|
+
|
|
95
|
+
### First public release
|
|
96
|
+
|
|
97
|
+
First publish of the **pesafy** M-PESA Daraja SDK to npm.
|
|
98
|
+
|
|
99
|
+
#### Package foundation
|
|
100
|
+
|
|
101
|
+
- Official npm registry only (`.npmrc`, pinned lockfile, `zod` runtime
|
|
102
|
+
dependency)
|
|
103
|
+
- Version **0.0.1** with Changesets, npm provenance, and hardened publish gates
|
|
104
|
+
- `prepublishOnly`: lint, format, typecheck, coverage, build, size-limit
|
|
105
|
+
- CI publish workflow: lint, format, coverage, build before release
|
|
106
|
+
|
|
107
|
+
#### Features
|
|
108
|
+
|
|
109
|
+
- **Mpesa client** — STK Push, C2B, B2C/B2B, account balance, transaction
|
|
110
|
+
status, reversal, tax remittance, dynamic QR, bill manager
|
|
111
|
+
- **Idempotency** — automatic `Idempotency-Key` on mutating POSTs,
|
|
112
|
+
`IdempotencyManager`, pluggable store, auto `OriginatorConversationID` for B2C
|
|
113
|
+
disbursement
|
|
114
|
+
- **Zod validation** — runtime schemas for STK Push, B2C Disbursement, B2B
|
|
115
|
+
Express Checkout, webhooks; exported from `pesafy`
|
|
116
|
+
- **Webhooks** — Safaricom IP allowlist, STK/callback helpers, opt-in HMAC
|
|
117
|
+
preview (`verifyWebhook`, `verifyWebhookHMAC`)
|
|
118
|
+
- **Framework adapters** — Express, Hono, Fastify, Next.js
|
|
119
|
+
- **CLI**, branded types, `Result<T>` safe methods, encryption, phone utilities
|
|
120
|
+
|
|
121
|
+
#### Notes
|
|
122
|
+
|
|
123
|
+
- Stricter Zod validation may reject payloads that previously passed loose
|
|
124
|
+
checks
|
|
125
|
+
- HMAC verification is opt-in until Safaricom documents the official signing
|
|
126
|
+
spec
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Lewis Odero
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|