pesafy 0.4.3 → 0.5.1

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.
Files changed (49) hide show
  1. package/CHANGELOG.md +177 -0
  2. package/LICENSE +21 -0
  3. package/README.md +981 -108
  4. package/dist/adapters/express.cjs +1 -0
  5. package/dist/adapters/express.d.cts +1294 -0
  6. package/dist/adapters/express.d.ts +1294 -0
  7. package/dist/adapters/express.js +1 -0
  8. package/dist/adapters/fastify.cjs +1 -0
  9. package/dist/adapters/fastify.d.cts +21 -0
  10. package/dist/adapters/fastify.d.ts +21 -0
  11. package/dist/adapters/fastify.js +1 -0
  12. package/dist/adapters/hono.cjs +1 -0
  13. package/dist/adapters/hono.d.cts +27 -0
  14. package/dist/adapters/hono.d.ts +27 -0
  15. package/dist/adapters/hono.js +1 -0
  16. package/dist/adapters/nextjs.cjs +1 -0
  17. package/dist/adapters/nextjs.d.cts +52 -0
  18. package/dist/adapters/nextjs.d.ts +52 -0
  19. package/dist/adapters/nextjs.js +1 -0
  20. package/dist/cli.js +561 -0
  21. package/dist/encryption.js +22 -0
  22. package/dist/errors.js +41 -0
  23. package/dist/index.cjs +1 -1434
  24. package/dist/index.d.cts +1342 -1262
  25. package/dist/index.d.ts +1342 -1262
  26. package/dist/index.js +1 -1376
  27. package/dist/phone.js +23 -0
  28. package/dist/react/index.d.ts +1 -0
  29. package/dist/react/index.js +0 -0
  30. package/dist/signature-verifier.cjs +1 -0
  31. package/dist/signature-verifier.js +1 -0
  32. package/dist/types.d.cts +29 -0
  33. package/dist/types.d.ts +29 -0
  34. package/dist/utils.js +32 -0
  35. package/dist/webhook-handler.cjs +1 -0
  36. package/dist/webhook-handler.js +1 -0
  37. package/package.json +149 -78
  38. package/dist/components/react/index.cjs +0 -19
  39. package/dist/components/react/index.cjs.map +0 -1
  40. package/dist/components/react/index.d.cts +0 -2
  41. package/dist/components/react/index.d.ts +0 -2
  42. package/dist/components/react/index.js +0 -1
  43. package/dist/components/react/index.js.map +0 -1
  44. package/dist/components/react/styles.css +0 -2
  45. package/dist/components/react/styles.css.map +0 -1
  46. package/dist/components/react/styles.d.cts +0 -2
  47. package/dist/components/react/styles.d.ts +0 -2
  48. package/dist/index.cjs.map +0 -1
  49. package/dist/index.js.map +0 -1
package/CHANGELOG.md ADDED
@@ -0,0 +1,177 @@
1
+ # pesafy
2
+
3
+ ## 0.5.1
4
+
5
+ ### Patch Changes
6
+
7
+ - reduce size increase speed
8
+
9
+ ## 0.5.0
10
+
11
+ ### Minor Changes
12
+
13
+ - migration to vite+
14
+
15
+ ## 0.4.3
16
+
17
+ ### Patch Changes
18
+
19
+ - b2c functions added
20
+
21
+ ## 0.4.2
22
+
23
+ ### Patch Changes
24
+
25
+ - fix the missing exports
26
+
27
+ ## 0.4.1
28
+
29
+ ### Patch Changes
30
+
31
+ - added b2b express checkout capability
32
+
33
+ ## 0.4.0
34
+
35
+ ### Minor Changes
36
+
37
+ - added tax-remittance
38
+
39
+ ## 0.3.13
40
+
41
+ ### Patch Changes
42
+
43
+ - C2B URL registration panel with per-shortcode tracking (Paybill + Buy Goods), dual registration support, and session-persisted status badges"
44
+
45
+ ## 0.3.12
46
+
47
+ ### Patch Changes
48
+
49
+ - 047c30f: The payload was always sending BillRefNumber: request.billRefNumber ?? "". For CustomerBuyGoodsOnline, Daraja treats any BillRefNumber field — even "" — as an invalid AccountReference and rejects the request (400 or 503). The fix conditionally includes the field only for Paybill
50
+ - fix error handling and URLs only registered for 600977, never for 600000. The log shows registerC2BUrls shortCode=600977 but then simulateC2B shortCode=600000
51
+
52
+ ## 0.3.11
53
+
54
+ ### Patch Changes
55
+
56
+ - add c2b feature
57
+
58
+ ## 0.3.10
59
+
60
+ ### Patch Changes
61
+
62
+ - Added Dynamic QR Code support to the pesafy SDK as a new mpesa/dynamic-qr module. This introduces three new files — types.ts, generate.ts, and index.ts — under src/mpesa/dynamic-qr/, implementing the Safaricom Daraja POST /mpesa/qrcode/v1/generate endpoint. The Mpesa class gains a new generateDynamicQR() method that handles token retrieval and delegates to the internal generateDynamicQR function, which validates all inputs (merchant name, reference, amount, transaction code, CPI, and size) before dispatching the request via the existing httpRequest utility. Three new public types — DynamicQRRequest, DynamicQRResponse, and QRTransactionCode — are exported from the root src/index.ts. No breaking changes were introduced; all existing APIs remain untouched.
63
+
64
+ ## 0.3.9
65
+
66
+ ### Patch Changes
67
+
68
+ - retry logic
69
+
70
+ ## 0.3.8
71
+
72
+ ### Patch Changes
73
+
74
+ - Fixed four blocking TypeScript compilation errors before prepublish by extending the `ErrorCode` union to include `API_ERROR`, `NETWORK_ERROR`, and `TIMEOUT`, which resolved type assignment issues in the HTTP layer. Consolidated a duplicate `PesafyError` class (previously split between `index.ts` and `types.ts`) into a single authoritative implementation that preserves all fields, including `requestId`, `toJSON()`, and stack trace handling. Also corrected `x-forwarded-for` IP extraction in the Express webhook handler using safe optional chaining to prevent potential undefined access from the `split()` result.
75
+
76
+ ## 0.3.7
77
+
78
+ ### Patch Changes
79
+
80
+ - add transaction status
81
+
82
+ ## 0.3.6
83
+
84
+ ### Patch Changes
85
+
86
+ - add new version
87
+
88
+ ## 0.3.5
89
+
90
+ ### Patch Changes
91
+
92
+ - d066c9c: conditional bill reference for bu goods
93
+
94
+ ## 0.3.4
95
+
96
+ ### Patch Changes
97
+
98
+ - f983f64: The /v2/simulate path is the most critical bug — it will cause persistent 500.003.1001 errors in sandbox just like the /v2/registerurl issue you already fixed.
99
+
100
+ ## 0.3.3
101
+
102
+ ### Patch Changes
103
+
104
+ - 2790c0f: The v2 path for registerurl does not exist on Daraja
105
+
106
+ ## 0.3.2
107
+
108
+ ### Patch Changes
109
+
110
+ - 4115f0a: fix
111
+
112
+ ## 0.3.1
113
+
114
+ ### Patch Changes
115
+
116
+ - **C2B module rewrite & phone utility refactor** — Fixed `simulateC2B` where `CommandID` was hardcoded to `CustomerPayBillOnline`, making `CustomerBuyGoodsOnline` (Till) payments impossible. Corrected `BillRefNumber` logic so the field is omitted entirely for BuyGoods requests rather than defaulting to the string `"default"`, which caused a `400` from Daraja. Fixed `Msisdn` being sent as a quoted string instead of a JSON number as the spec requires. Removed the phantom `ConversationID` field from both `C2BSimulateResponse` and `C2BRegisterUrlResponse` — Daraja never returns this field for C2B, only `OriginatorCoversationID`. Extracted phone formatting into a shared `src/utils/phone.ts` module with two intentionally separate formatters: `formatSafaricomPhone` (strict, Safaricom/Airtel only, for STK Push) and `formatKenyanMsisdn` (permissive, all Kenyan networks, for C2B and B2C), eliminating duplicated logic across modules. Added the `C2BCommandId` union type and full callback payload types — `C2BValidationPayload`, `C2BConfirmationPayload`, and `C2BCallbackPayload` — to enable type-safe webhook handlers.
117
+ - fbfa311: fix url patch and add elemt accountref
118
+ - aa9c176: **C2B module rewrite & phone utility refactor** — Fixed `simulateC2B` where `CommandID` was hardcoded to `CustomerPayBillOnline`, making `CustomerBuyGoodsOnline` (Till) payments impossible. Corrected `BillRefNumber` logic so the field is omitted entirely for BuyGoods requests rather than defaulting to the string `"default"`, which caused a `400` from Daraja. Fixed `Msisdn` being sent as a quoted string instead of a JSON number as the spec requires. Removed the phantom `ConversationID` field from both `C2BSimulateResponse` and `C2BRegisterUrlResponse` — Daraja never returns this field for C2B, only `OriginatorCoversationID`. Extracted phone formatting into a shared `src/utils/phone.ts` module with two intentionally separate formatters: `formatSafaricomPhone` (strict, Safaricom/Airtel only, for STK Push) and `formatKenyanMsisdn` (permissive, all Kenyan networks, for C2B and B2C), eliminating duplicated logic across modules. Added the `C2BCommandId` union type and full callback payload types — `C2BValidationPayload`, `C2BConfirmationPayload`, and `C2BCallbackPayload` — to enable type-safe webhook handlers.
119
+
120
+ ## 0.3.0
121
+
122
+ ### Minor Changes
123
+
124
+ - fe95c2b: The C2B M-Pesa implementation in the pesafy package has been comprehensively overhauled for full Daraja C2B v2 compliance, including a complete rewrite of types.ts with all 13 callback fields (C2BCallbackPayload), validation responses, rejection codes, and command/response unions; fixes to register-url.ts ensuring ValidationURL is always sent (defaulting to confirmationUrl); enhanced simulate.ts supporting both CustomerPayBillOnline and CustomerBuyGoodsOnline with proper BillRefNumber handling, amount validation, and Msisdn casting; new c2b index exports; root index public exports; and improved http client error reporting. Dashboard updates add c2bRegisterUrls and c2bSimulate actions in mpesaActions.ts, fix http.ts webhook handlers with 6 missing fields (TransactionType, TransTime, etc.), upsert logic via createTransaction, a new getByShortCode query in businesses.ts, and a complete C2B tab in PaymentsPage.tsx featuring URL registration, simulation forms, and unified transactions—addressing prior gaps like hardcoded commands, missing UI, incomplete types, and non-upserting handlers.
125
+
126
+ ## 0.2.4
127
+
128
+ ### Patch Changes
129
+
130
+ - 4a535ef: Request failed with status 500 but swallows the actual Daraja error body — it parses it into data but never includes it in the error message.
131
+
132
+ ## 0.2.3
133
+
134
+ ### Patch Changes
135
+
136
+ - 16a7a59: error code fix
137
+
138
+ ## 0.2.2
139
+
140
+ ### Patch Changes
141
+
142
+ - fix the missing pieces
143
+
144
+ ## 0.2.1
145
+
146
+ ### Patch Changes
147
+
148
+ - fix versioning
149
+
150
+ ## 0.2.0
151
+
152
+ ### Minor Changes
153
+
154
+ - Add M-Pesa Express (STK Push) support
155
+ - Add `processStkPush` to initiate STK Push payment prompts on a
156
+ customer's phone via POST /mpesa/stkpush/v1/processrequest
157
+ - Add `queryStkPush` to check the status of an STK Push transaction
158
+ via POST /mpesa/stkpushquery/v1/query
159
+ - Add `StkPushRequest`, `StkPushResponse`, `StkQueryRequest`,
160
+ `StkQueryResponse` and `TransactionType` types
161
+ - Add `formatPhoneNumber` utility to normalize Kenyan phone numbers
162
+ to 254 format
163
+ - Add `getStkPushPassword` to generate Base64(Shortcode+Passkey+Timestamp)
164
+ - Add `getTimestamp` helper for Daraja-formatted timestamps
165
+ - Export all STK Push types and utilities from the package root
166
+
167
+ ## 0.1.0
168
+
169
+ ### Minor Changes
170
+
171
+ - d988767: ready for phase one
172
+
173
+ ## 0.0.1
174
+
175
+ ### Patch Changes
176
+
177
+ - init changeset/cli
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.