@temboplus/frontend-core 0.3.0-beta.3 → 0.3.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.
package/README.md CHANGED
@@ -1,77 +1,28 @@
1
1
  # @temboplus/frontend-core
2
2
 
3
- A foundational JavaScript/TypeScript library designed to provide common utilities, shared logic, and standardized components for all TemboPlus frontend applications. This package aims to streamline development, ensure consistency, and reduce code duplication across our entire frontend ecosystem.
3
+ Shared TypeScript package for TemboPlus domain models, validators, and constants. Originally built by the frontend team (hence the name), but contains no UI components and works in any JavaScript runtime frontend, backend, or otherwise.
4
4
 
5
- ## Core Features
6
-
7
- * **Utility Functions:** A collection of pre-built helper functions to simplify common development tasks.
8
- * **Standardized Data Models:** Consistent and reliable data structures for managing essential data types, including phone numbers, amounts, currencies, countries, and bank details.
9
- * **Comprehensive Report Management:** A powerful `ReportManager` for generating and downloading reports in various formats across different TemboPlus projects.
10
- * **Centralized Configuration Service:** A flexible `ConfigService` for managing application settings and environment configurations.
11
-
12
- ## Data Models
13
-
14
- This library offers a set of meticulously crafted data models, each designed to handle specific data types with precision:
15
-
16
- * **PhoneNumber:** Robust international phone number validation and formatting.
17
- * **TZPhoneNumber:** Specialized phone number handling for Tanzania, including network operator identification.
18
- * **Amount:** Precise currency value management, with support for formatting and conversion.
19
- * **Currency:** Detailed currency information, including symbols, formatting rules, and validation.
20
- * **Country:** Enhanced country data handling with ISO-2 and ISO-3 codes, official names, flag emojis, and strongly-typed geographical categorization.
21
- * **Bank:** Consistent bank account information management.
22
-
23
- ## Report Management with `ReportManager`
24
-
25
- The `ReportManager` simplifies the process of generating and downloading reports across various TemboPlus projects.
26
-
27
- ```typescript
28
- import { ReportManager, FileFormat, ReportType, ProjectType } from '@temboplus/frontend-core';
29
-
30
- // Download a report
31
- async function downloadMerchantDisbursementReport() {
32
- await ReportManager.instance.downloadReport({
33
- token: "your-auth-token",
34
- projectType: ProjectType.DASHBOARD,
35
- reportType: ReportType.MERCHANT_DISBURSEMENT_REPORT,
36
- fileFormat: FileFormat.PDF,
37
- query: {
38
- startDate: "2023-01-01T00:00:00.000Z",
39
- endDate: "2023-01-31T00:00:00.000Z"
40
- }
41
- });
42
- }
5
+ ## Installation
43
6
 
44
- // Get all reports for a specific project
45
- import { getReportsByProject } from '@temboplus/frontend-core';
46
- function getAllDashboardReports(){
47
- const dashboardReports = getReportsByProject(ProjectType.DASHBOARD);
48
- return dashboardReports;
49
- }
7
+ ```bash
8
+ npm install @temboplus/frontend-core
50
9
  ```
51
10
 
52
- ### Supported Report Types
53
-
54
- * **Dashboard Reports:**
55
- * `MERCHANT_DISBURSEMENT_REPORT`: Detailed merchant disbursement reports.
56
- * `TRANSACTION_REVENUE_SUMMARY`: Revenue transaction summaries.
57
- * **Afloat Reports:**
58
- * `CUSTOMER_WALLET_ACTIVITY`: Customer wallet activity logs.
59
- * `CUSTOMER_PROFILE_SNAPSHOT`: Customer profile snapshots.
60
- * **VertoX Reports:**
61
- * `GATEWAY_TRANSACTION_LOG`: Payment gateway transaction logs.
11
+ ## What's Included
62
12
 
63
- ## Configuration Service with `ConfigService`
13
+ * **Data models** for phone numbers, amounts, currencies, countries, and banks
14
+ * **Validation and parsing** helpers for constructing normalized model instances
15
+ * **Constants** for supported payout countries and related domain logic
16
+ * **Type-safe string literals** for country codes (ISO-2, ISO-3) and currency codes
64
17
 
65
- The `ConfigService` provides a centralized mechanism for managing application configurations.
66
-
67
- ```typescript
68
- import { ConfigService } from '@temboplus/frontend-core';
18
+ ## Data Models
69
19
 
70
- // Initialize configuration at application startup
71
- ConfigService.instance.initialize({
72
- pdfMakerBaseUrl: 'http://localhost:3000' // Optional: Override default PDF maker base URL.
73
- });
74
- ```
20
+ * **PhoneNumber:** International phone number validation and formatting.
21
+ * **TZPhoneNumber:** Tanzania phone numbers with network operator identification.
22
+ * **Amount:** Currency value handling with formatting and conversion.
23
+ * **Currency:** Currency info including symbols, formatting rules, and validation.
24
+ * **Country:** Country data with ISO codes, flag emojis, and geographical categorization.
25
+ * **Bank:** Bank account information management.
75
26
 
76
27
  ## Data Model Validation
77
28
 
@@ -103,17 +54,10 @@ if (phoneNumber.validate()) {
103
54
 
104
55
  ## Type-Safe String Literals
105
56
 
106
- This library provides strongly-typed string literals for standardized codes:
107
-
108
- * **Country Codes:**
109
- * `ISO2CountryCode`: Two-letter country codes (e.g., "US", "GB", "DE")
110
- * `ISO3CountryCode`: Three-letter country codes (e.g., "USA", "GBR", "DEU")
111
- * `CountryCode`: A union type that accepts either ISO-2 or ISO-3 formats
57
+ Typed string literals for country and currency codes with compile-time checking:
112
58
 
113
- * **Currency Codes:**
114
- * `CurrencyCode`: Three-letter currency codes (e.g., "USD", "EUR", "JPY")
115
-
116
- These types provide compile-time validation and auto-completion while having zero runtime overhead:
59
+ * `ISO2CountryCode` / `ISO3CountryCode` / `CountryCode` (union of both)
60
+ * `CurrencyCode`
117
61
 
118
62
  ```typescript
119
63
  import {
@@ -132,48 +76,48 @@ function processTransaction(
132
76
  // Implementation
133
77
  }
134
78
 
135
- // Valid calls - compile-time checking ensures only valid codes are accepted
79
+ // Valid calls
136
80
  processTransaction(100, "USD", "US"); // ISO-2 country code
137
81
  processTransaction(200, "EUR", "DEU"); // ISO-3 country code
138
82
 
139
- // Invalid calls - caught by TypeScript at compile time
83
+ // Invalid caught at compile time
140
84
  processTransaction(300, "XYZ", "US"); // Error: "XYZ" is not a valid CurrencyCode
141
85
  processTransaction(400, "USD", "ZZZ"); // Error: "ZZZ" is not a valid CountryCode
142
86
  ```
143
87
 
144
- ## Static Data Access
88
+ ## Data Lookup
145
89
 
146
- Convenient static properties are available for accessing common data:
90
+ Use the lookup methods to access countries, currencies, and banks:
147
91
 
148
92
  ```typescript
149
- import { Country, Currency, Bank, CONTINENT, SUB_REGION } from '@temboplus/frontend-core';
93
+ import { Country, Currency, Bank, BankService, CONTINENT, SUB_REGION } from '@temboplus/frontend-core';
150
94
 
151
- // Country access with enhanced features
152
- const tanzania = Country.TZ;
153
- console.log(tanzania.flagEmoji); // 🇹🇿
154
- console.log(tanzania.continent); // CONTINENT.AFRICA
155
- console.log(tanzania.region); // SUB_REGION.EASTERN_AFRICA
95
+ // Country lookup
96
+ const tanzania = Country.fromCode("TZ");
97
+ console.log(tanzania?.flagEmoji); // 🇹🇿
98
+ console.log(tanzania?.continent); // CONTINENT.AFRICA
99
+ console.log(tanzania?.region); // SUB_REGION.EASTERN_AFRICA
156
100
 
157
- // Regional country grouping with type-safe enums
101
+ // Regional grouping
158
102
  const africanCountries = Country.getByContinent(CONTINENT.AFRICA);
159
103
  const caribbeanCountries = Country.getByRegion(SUB_REGION.CARIBBEAN);
160
104
 
161
- // Currency access
162
- const usd = Currency.USD;
163
- const tzs = Currency.TANZANIAN_SHILLING;
105
+ // Currency lookup
106
+ const usd = Currency.fromCode("USD");
107
+ const tzs = Currency.fromCode("TZS");
164
108
 
165
109
  // Access country's currency
166
- const japan = Country.JP;
167
- const yen = japan.getCurrency();
110
+ const japan = Country.fromCode("JP");
111
+ const yen = japan?.getCurrency();
168
112
  console.log(yen?.code); // "JPY"
169
113
 
170
114
  // Find countries using a specific currency
171
- const euroCountries = Country.getByCurrencyCode("EUR");
115
+ const euroCountries = Country.getAll().filter((country) => country.currencyCode === "EUR");
172
116
  console.log(`${euroCountries.length} countries use the Euro`);
173
117
 
174
118
  // Bank access
175
- const crdb = Bank.CRDB;
176
- const nmb = Bank.NMB;
119
+ const crdb = Bank.from("CORUTZTZ", "TZ");
120
+ const kenyanBanks = BankService.getInstance().getAllBanks("KE");
177
121
  ```
178
122
 
179
123
  ## Phone Number Usage
@@ -198,9 +142,3 @@ console.log(tanzaniaPhone.networkOperator.name); // "Yas"
198
142
  * [Bank](./docs/bank.md)
199
143
  * [Currency](./docs/currency.md)
200
144
  * [Country](./docs/country.md)
201
-
202
- ## Installation
203
-
204
- ```bash
205
- npm install @temboplus/frontend-core
206
- ```