pesafy 0.4.2 → 0.5.0

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 (58) hide show
  1. package/CHANGELOG.md +171 -0
  2. package/README.md +981 -108
  3. package/dist/adapters/fastify.cjs +1607 -0
  4. package/dist/adapters/fastify.cjs.map +1 -0
  5. package/dist/adapters/fastify.d.cts +49 -0
  6. package/dist/adapters/fastify.d.mts +49 -0
  7. package/dist/adapters/fastify.mjs +1606 -0
  8. package/dist/adapters/fastify.mjs.map +1 -0
  9. package/dist/adapters/hono.cjs +1651 -0
  10. package/dist/adapters/hono.cjs.map +1 -0
  11. package/dist/adapters/hono.d.cts +55 -0
  12. package/dist/adapters/hono.d.mts +55 -0
  13. package/dist/adapters/hono.mjs +1650 -0
  14. package/dist/adapters/hono.mjs.map +1 -0
  15. package/dist/adapters/nextjs.cjs +1655 -0
  16. package/dist/adapters/nextjs.cjs.map +1 -0
  17. package/dist/adapters/nextjs.d.cts +79 -0
  18. package/dist/adapters/nextjs.d.mts +79 -0
  19. package/dist/adapters/nextjs.mjs +1651 -0
  20. package/dist/adapters/nextjs.mjs.map +1 -0
  21. package/dist/cli/encryption-BA-_xrIW.mjs +45 -0
  22. package/dist/cli/encryption-CkSveeYj.cjs +45 -0
  23. package/dist/cli/errors-Bscvlb7X.cjs +45 -0
  24. package/dist/cli/errors-DL4bkMZV.mjs +40 -0
  25. package/dist/cli/index.cjs +559 -0
  26. package/dist/cli/index.mjs +560 -0
  27. package/dist/cli/phone-5wwAaQ_8.mjs +21 -0
  28. package/dist/cli/phone-BD4QmEyl.cjs +21 -0
  29. package/dist/cli/utils-BzEKV3nJ.mjs +30 -0
  30. package/dist/cli/utils-Dg9Gv_D3.cjs +31 -0
  31. package/dist/components/react/index.cjs +0 -19
  32. package/dist/components/react/index.d.cts +1 -2
  33. package/dist/components/react/index.d.mts +1 -0
  34. package/dist/components/react/index.mjs +1 -0
  35. package/dist/express/index.cjs +2201 -0
  36. package/dist/express/index.cjs.map +1 -0
  37. package/dist/express/index.d.cts +1322 -0
  38. package/dist/express/index.d.mts +1322 -0
  39. package/dist/express/index.mjs +2199 -0
  40. package/dist/express/index.mjs.map +1 -0
  41. package/dist/index.cjs +1961 -1088
  42. package/dist/index.cjs.map +1 -1
  43. package/dist/index.d.cts +1477 -1071
  44. package/dist/index.d.mts +1907 -0
  45. package/dist/index.mjs +2050 -0
  46. package/dist/index.mjs.map +1 -0
  47. package/package.json +100 -74
  48. package/dist/components/react/index.cjs.map +0 -1
  49. package/dist/components/react/index.d.ts +0 -2
  50. package/dist/components/react/index.js +0 -1
  51. package/dist/components/react/index.js.map +0 -1
  52. package/dist/components/react/styles.css +0 -2
  53. package/dist/components/react/styles.css.map +0 -1
  54. package/dist/components/react/styles.d.cts +0 -2
  55. package/dist/components/react/styles.d.ts +0 -2
  56. package/dist/index.d.ts +0 -1501
  57. package/dist/index.js +0 -1209
  58. package/dist/index.js.map +0 -1
package/CHANGELOG.md ADDED
@@ -0,0 +1,171 @@
1
+ # pesafy
2
+
3
+ ## 0.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - migration to vite+
8
+
9
+ ## 0.4.3
10
+
11
+ ### Patch Changes
12
+
13
+ - b2c functions added
14
+
15
+ ## 0.4.2
16
+
17
+ ### Patch Changes
18
+
19
+ - fix the missing exports
20
+
21
+ ## 0.4.1
22
+
23
+ ### Patch Changes
24
+
25
+ - added b2b express checkout capability
26
+
27
+ ## 0.4.0
28
+
29
+ ### Minor Changes
30
+
31
+ - added tax-remittance
32
+
33
+ ## 0.3.13
34
+
35
+ ### Patch Changes
36
+
37
+ - C2B URL registration panel with per-shortcode tracking (Paybill + Buy Goods), dual registration support, and session-persisted status badges"
38
+
39
+ ## 0.3.12
40
+
41
+ ### Patch Changes
42
+
43
+ - 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
44
+ - fix error handling and URLs only registered for 600977, never for 600000. The log shows registerC2BUrls shortCode=600977 but then simulateC2B shortCode=600000
45
+
46
+ ## 0.3.11
47
+
48
+ ### Patch Changes
49
+
50
+ - add c2b feature
51
+
52
+ ## 0.3.10
53
+
54
+ ### Patch Changes
55
+
56
+ - 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.
57
+
58
+ ## 0.3.9
59
+
60
+ ### Patch Changes
61
+
62
+ - retry logic
63
+
64
+ ## 0.3.8
65
+
66
+ ### Patch Changes
67
+
68
+ - 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.
69
+
70
+ ## 0.3.7
71
+
72
+ ### Patch Changes
73
+
74
+ - add transaction status
75
+
76
+ ## 0.3.6
77
+
78
+ ### Patch Changes
79
+
80
+ - add new version
81
+
82
+ ## 0.3.5
83
+
84
+ ### Patch Changes
85
+
86
+ - d066c9c: conditional bill reference for bu goods
87
+
88
+ ## 0.3.4
89
+
90
+ ### Patch Changes
91
+
92
+ - 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.
93
+
94
+ ## 0.3.3
95
+
96
+ ### Patch Changes
97
+
98
+ - 2790c0f: The v2 path for registerurl does not exist on Daraja
99
+
100
+ ## 0.3.2
101
+
102
+ ### Patch Changes
103
+
104
+ - 4115f0a: fix
105
+
106
+ ## 0.3.1
107
+
108
+ ### Patch Changes
109
+
110
+ - **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.
111
+ - fbfa311: fix url patch and add elemt accountref
112
+ - 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.
113
+
114
+ ## 0.3.0
115
+
116
+ ### Minor Changes
117
+
118
+ - 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.
119
+
120
+ ## 0.2.4
121
+
122
+ ### Patch Changes
123
+
124
+ - 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.
125
+
126
+ ## 0.2.3
127
+
128
+ ### Patch Changes
129
+
130
+ - 16a7a59: error code fix
131
+
132
+ ## 0.2.2
133
+
134
+ ### Patch Changes
135
+
136
+ - fix the missing pieces
137
+
138
+ ## 0.2.1
139
+
140
+ ### Patch Changes
141
+
142
+ - fix versioning
143
+
144
+ ## 0.2.0
145
+
146
+ ### Minor Changes
147
+
148
+ - Add M-Pesa Express (STK Push) support
149
+ - Add `processStkPush` to initiate STK Push payment prompts on a
150
+ customer's phone via POST /mpesa/stkpush/v1/processrequest
151
+ - Add `queryStkPush` to check the status of an STK Push transaction
152
+ via POST /mpesa/stkpushquery/v1/query
153
+ - Add `StkPushRequest`, `StkPushResponse`, `StkQueryRequest`,
154
+ `StkQueryResponse` and `TransactionType` types
155
+ - Add `formatPhoneNumber` utility to normalize Kenyan phone numbers
156
+ to 254 format
157
+ - Add `getStkPushPassword` to generate Base64(Shortcode+Passkey+Timestamp)
158
+ - Add `getTimestamp` helper for Daraja-formatted timestamps
159
+ - Export all STK Push types and utilities from the package root
160
+
161
+ ## 0.1.0
162
+
163
+ ### Minor Changes
164
+
165
+ - d988767: ready for phase one
166
+
167
+ ## 0.0.1
168
+
169
+ ### Patch Changes
170
+
171
+ - init changeset/cli