@temboplus/frontend-core 0.2.17 → 0.2.20-beta.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 (37) hide show
  1. package/dist/constants/index.d.ts +1 -1
  2. package/dist/constants/payout-countries.d.ts +1 -1
  3. package/dist/index.cjs.js +3 -3
  4. package/dist/index.cjs.js.map +1 -1
  5. package/dist/index.d.ts +5 -5
  6. package/dist/index.esm.js +2 -2
  7. package/dist/index.esm.js.map +1 -1
  8. package/dist/models/amount/amount.d.ts +1 -1
  9. package/dist/models/amount/index.d.ts +1 -1
  10. package/dist/models/bank/bank.d.ts +76 -2
  11. package/dist/models/bank/bank.validation.d.ts +2 -2
  12. package/dist/models/bank/index.d.ts +4 -4
  13. package/dist/models/country/country.d.ts +3 -3
  14. package/dist/models/country/country.validation.d.ts +1 -2
  15. package/dist/models/country/index.d.ts +4 -4
  16. package/dist/models/currency/currency.d.ts +1 -1
  17. package/dist/models/currency/currency.validation.d.ts +1 -1
  18. package/dist/models/currency/index.d.ts +4 -4
  19. package/dist/models/index.d.ts +5 -5
  20. package/dist/models/phone-number/index.d.ts +6 -6
  21. package/dist/models/phone-number/mno/index.d.ts +6 -6
  22. package/dist/models/phone-number/mno/ke/mobile-number.ke-mnos.d.ts +2 -2
  23. package/dist/models/phone-number/mno/ke/mobile-number.ke.d.ts +5 -5
  24. package/dist/models/phone-number/mno/mno.types.d.ts +1 -1
  25. package/dist/models/phone-number/mno/mno.utils.d.ts +2 -2
  26. package/dist/models/phone-number/mno/tz/mobile-number.tz-mnos.d.ts +2 -2
  27. package/dist/models/phone-number/mno/tz/mobile-number.tz.d.ts +5 -5
  28. package/dist/models/phone-number/phone-number.d.ts +4 -4
  29. package/dist/models/phone-number/phone-number.factory.d.ts +2 -2
  30. package/dist/models/phone-number/phone-number.service.d.ts +2 -2
  31. package/dist/models/phone-number/phone-number.types.d.ts +2 -2
  32. package/dist/models/phone-number/phone-number.utils.d.ts +2 -2
  33. package/dist/reports/index.d.ts +1 -1
  34. package/dist/services/index.d.ts +2 -2
  35. package/dist/services/logger.d.ts +2 -1
  36. package/dist/utils/index.d.ts +3 -3
  37. package/package.json +11 -17
@@ -1,4 +1,4 @@
1
- import { CurrencyCode } from "../../models/currency";
1
+ import { CurrencyCode } from "../currency/index.js";
2
2
  /**
3
3
  * Regular expression for validating amount strings
4
4
  * Supports both positive and negative amounts with optional comma separators and decimals
@@ -1 +1 @@
1
- export * from "./amount";
1
+ export * from "./amount.js";
@@ -1,5 +1,5 @@
1
- import { ISO2CountryCode } from "../country/country.types";
2
- import type { BankSwiftCode, KEBankSwiftCode, TZBankSwiftCode } from "./bank.types";
1
+ import { ISO2CountryCode } from "../country/country.types.js";
2
+ import type { BankSwiftCode, KEBankSwiftCode, TZBankSwiftCode } from "./bank.types.js";
3
3
  export declare class Bank {
4
4
  /**
5
5
  * The full registered name of the bank.
@@ -32,6 +32,80 @@ export declare class Bank {
32
32
  */
33
33
  toString(): string;
34
34
  static from(swiftCode: BankSwiftCode, countryCode: ISO2CountryCode): Bank;
35
+ /**
36
+ * Creates a Bank instance from a JSON string.
37
+ *
38
+ * The JSON should contain swiftCode and countryCode fields.
39
+ * The bank data is then looked up from the bank service to ensure validity.
40
+ *
41
+ * @static
42
+ * @param {string} jsonString - JSON string containing bank data
43
+ * @returns {Bank | undefined} A new Bank instance if successful, undefined if parsing fails
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * const jsonString = '{"swiftCode":"CORUTZTZ","countryCode":"TZ"}';
48
+ * const bank = Bank.fromJSON(jsonString);
49
+ * if (bank) {
50
+ * console.log(bank.fullName); // "CRDB BANK PLC"
51
+ * }
52
+ *
53
+ * // Also works with full bank data
54
+ * const fullJson = '{"fullName":"CRDB BANK PLC","shortName":"CRDB","swiftCode":"CORUTZTZ","countryCode":"TZ"}';
55
+ * const bank2 = Bank.fromJSON(fullJson);
56
+ * ```
57
+ */
58
+ static fromJSON(jsonString: string): Bank | undefined;
59
+ /**
60
+ * Converts the Bank instance to a plain JavaScript object.
61
+ * Suitable for serialization or data transfer.
62
+ *
63
+ * @returns {Object} Plain object representation of the bank
64
+ * @returns {string} returns.fullName - The full registered name of the bank
65
+ * @returns {string} returns.shortName - The commonly used short name
66
+ * @returns {string} returns.swiftCode - The SWIFT/BIC code
67
+ * @returns {ISO2CountryCode} returns.countryCode - The ISO 3166-1 alpha-2 country code
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * const bank = Bank.from("CORUTZTZ", "TZ");
72
+ * const obj = bank.toObject();
73
+ * console.log(obj);
74
+ * // {
75
+ * // fullName: "CRDB BANK PLC",
76
+ * // shortName: "CRDB",
77
+ * // swiftCode: "CORUTZTZ",
78
+ * // countryCode: "TZ"
79
+ * // }
80
+ * ```
81
+ */
82
+ toObject(): {
83
+ fullName: string;
84
+ shortName: string;
85
+ swiftCode: TZBankSwiftCode | KEBankSwiftCode;
86
+ countryCode: ISO2CountryCode;
87
+ };
88
+ /**
89
+ * Serializes the Bank instance to a JSON string.
90
+ *
91
+ * @returns {string} JSON string representation of the bank
92
+ *
93
+ * @example
94
+ * ```typescript
95
+ * const bank = Bank.from("CORUTZTZ", "TZ");
96
+ * const jsonString = bank.toJSON();
97
+ * console.log(jsonString);
98
+ * // '{"fullName":"CRDB BANK PLC","shortName":"CRDB","swiftCode":"CORUTZTZ","countryCode":"TZ"}'
99
+ *
100
+ * // Store or transmit
101
+ * localStorage.setItem('selectedBank', jsonString);
102
+ *
103
+ * // Later, retrieve and reconstruct
104
+ * const stored = localStorage.getItem('selectedBank');
105
+ * const reconstructed = Bank.fromJSON(stored);
106
+ * ```
107
+ */
108
+ toJSON(): string;
35
109
  /**
36
110
  * Static method to determine if an unknown object is a valid Bank object.
37
111
  *
@@ -1,5 +1,5 @@
1
- import { ISO2CountryCode } from "../country";
2
- import { BankSwiftCode } from "./bank.types";
1
+ import { ISO2CountryCode } from "@models/country/country.types.js";
2
+ import { BankSwiftCode } from "./bank.types.js";
3
3
  export declare const BankValidation: {
4
4
  /**
5
5
  * Validates a bank account number format for a specific country.
@@ -1,4 +1,4 @@
1
- export * from "./bank";
2
- export * from "./bank.types";
3
- export * from "./bank.validation";
4
- export * from "./bank.schema";
1
+ export * from "./bank.js";
2
+ export * from "./bank.types.js";
3
+ export * from "./bank.validation.js";
4
+ export * from "./bank.schema.js";
@@ -24,9 +24,9 @@
24
24
  * The addition of currency support through the getCurrency() method leverages
25
25
  * the Currency model while maintaining a clean separation of concerns.
26
26
  */
27
- import { Currency } from "../../models/currency";
28
- import type { CurrencyCode } from "../../models/currency";
29
- import type { CountryCode, ISO2CountryCode, ISO3CountryCode } from "./country.types";
27
+ import { Currency } from "@models/currency/currency.js";
28
+ import { CurrencyCode } from "@models/currency/currency.types.js";
29
+ import { ISO2CountryCode, ISO3CountryCode, CountryCode } from "./country.types.js";
30
30
  /**
31
31
  * Enum for continents
32
32
  */
@@ -1,5 +1,4 @@
1
- import { type ISO2CountryCode, type ISO3CountryCode } from "./country.types";
2
- import type { CountryCode } from "..";
1
+ import { ISO2CountryCode, ISO3CountryCode, CountryCode } from "./country.types.js";
3
2
  export declare const CountryValidation: {
4
3
  isISO2CountryCode: typeof isISO2CountryCode;
5
4
  isISO3CountryCode: typeof isISO3CountryCode;
@@ -1,4 +1,4 @@
1
- export * from "./country";
2
- export * from "./country.types";
3
- export * from "./country.validation";
4
- export * from "./country.schema";
1
+ export * from "./country.js";
2
+ export * from "./country.types.js";
3
+ export * from "./country.validation.js";
4
+ export * from "./country.schema.js";
@@ -26,7 +26,7 @@
26
26
  * This approach follows the principle that closely related classes with circular
27
27
  * dependencies are best managed in a unified module.
28
28
  */
29
- import type { CurrencyCode } from "./currency.types";
29
+ import type { CurrencyCode } from "./currency.types.js";
30
30
  /**
31
31
  * Represents a currency with essential details.
32
32
  * @class Currency
@@ -1,4 +1,4 @@
1
- import { type CurrencyCode } from "./currency.types";
1
+ import { type CurrencyCode } from "./currency.types.js";
2
2
  export declare const CurrencyValidation: {
3
3
  isCurrencyCode: typeof isCurrencyCode;
4
4
  };
@@ -1,4 +1,4 @@
1
- export * from "./currency";
2
- export * from "./currency.types";
3
- export * from "./currency.validation";
4
- export * from "./currency.schema";
1
+ export * from "./currency.js";
2
+ export * from "./currency.types.js";
3
+ export * from "./currency.validation.js";
4
+ export * from "./currency.schema.js";
@@ -1,5 +1,5 @@
1
- export * from "./amount/index";
2
- export * from "./bank/index";
3
- export * from "./phone-number/index";
4
- export * from "./country/index";
5
- export * from "./currency/index";
1
+ export * from "./amount/index.js";
2
+ export * from "./bank/index.js";
3
+ export * from "./phone-number/index.js";
4
+ export * from "./country/index.js";
5
+ export * from "./currency/index.js";
@@ -1,6 +1,6 @@
1
- export * from "./phone-number.factory";
2
- export * from "./phone-number.types";
3
- export * from "./mno/mno.utils";
4
- export * from "./mno/mno.types";
5
- export * from "./phone-number";
6
- export * from "./mno";
1
+ export * from "./phone-number.factory.js";
2
+ export * from "./phone-number.types.js";
3
+ export * from "./mno/mno.utils.js";
4
+ export * from "./mno/mno.types.js";
5
+ export * from "./phone-number.js";
6
+ export * from "./mno/index.js";
@@ -1,6 +1,6 @@
1
- export * from "./ke/mobile-number.ke";
2
- export * from "./ke/mobile-number.ke-mnos";
3
- export * from "./tz/mobile-number.tz";
4
- export * from "./tz/mobile-number.tz-mnos";
5
- export * from "./mno.types";
6
- export * from "./mno.utils";
1
+ export * from "./ke/mobile-number.ke.js";
2
+ export * from "./ke/mobile-number.ke-mnos.js";
3
+ export * from "./tz/mobile-number.tz.js";
4
+ export * from "./tz/mobile-number.tz-mnos.js";
5
+ export * from "./mno.types.js";
6
+ export * from "./mno.utils.js";
@@ -1,5 +1,5 @@
1
- import { ISO2CountryCode } from "../../../country/country.types";
2
- import { CountryMNOImplementation, KEMNOId, MNOInfo } from "../mno.types";
1
+ import { ISO2CountryCode } from "@models/country/country.types.js";
2
+ import { CountryMNOImplementation, KEMNOId, MNOInfo } from "@models/phone-number/mno/mno.types.js";
3
3
  /**
4
4
  * Configuration object for Kenyan mobile network operators.
5
5
  * Conforms to the generic MNOInfo interface.
@@ -1,8 +1,8 @@
1
- import { ISO2CountryCode } from "../../../country";
2
- import { MNOInfo } from "../mno.types";
3
- import { PhoneNumber } from "../../phone-number";
4
- import { type ParsedPhoneNumber, PhoneNumberService } from "../../phone-number.service";
5
- import { type PhoneNumberContract, type PhoneNumberParseOptions, PhoneNumberType } from "../../phone-number.types";
1
+ import { ISO2CountryCode } from "@models/country/country.types.js";
2
+ import { MNOInfo } from "@models/phone-number/mno/mno.types.js";
3
+ import { PhoneNumber } from "@models/phone-number/phone-number.js";
4
+ import { type ParsedPhoneNumber, PhoneNumberService } from "@models/phone-number/phone-number.service.js";
5
+ import { type PhoneNumberContract, type PhoneNumberParseOptions, PhoneNumberType } from "@models/phone-number/phone-number.types.js";
6
6
  /**
7
7
  * Represents a validated Kenyan (KE) **mobile** phone number.
8
8
  * Extends the generic PhoneNumber class and implements the common PhoneNumberContract interface.
@@ -2,7 +2,7 @@
2
2
  * Tanzanian mobile network operator identifiers.
3
3
  * Values are used in payout channel-code field and should not change.
4
4
  */
5
- import { ISO2CountryCode } from "../../country/country.types";
5
+ import { ISO2CountryCode } from "@models/country/country.types.js";
6
6
  export declare enum TZMNOId {
7
7
  VODACOM = "VODACOM",
8
8
  AIRTEL = "AIRTEL",
@@ -1,5 +1,5 @@
1
- import { CountryCode, ISO2CountryCode } from "../../country";
2
- import { CountryMNOImplementation, MNOInfo } from "./mno.types";
1
+ import { CountryCode, ISO2CountryCode } from "@models/country/country.types.js";
2
+ import { CountryMNOImplementation, MNOInfo } from "./mno.types.js";
3
3
  /**
4
4
  * Utility functions for working with MNO data across countries.
5
5
  */
@@ -1,5 +1,5 @@
1
- import { ISO2CountryCode } from "../../../country";
2
- import { CountryMNOImplementation, MNOInfo, TZMNOId } from "../mno.types";
1
+ import { ISO2CountryCode } from "@models/country/country.types.js";
2
+ import { CountryMNOImplementation, MNOInfo, TZMNOId } from "@models/phone-number/mno/mno.types.js";
3
3
  /**
4
4
  * Configuration object for Tanzanian mobile network operators.
5
5
  * Conforms to the generic NetworkOperatorInfo interface.
@@ -1,8 +1,8 @@
1
- import { PhoneNumber } from "../../phone-number";
2
- import { type ParsedPhoneNumber, PhoneNumberService } from "../../phone-number.service";
3
- import { type PhoneNumberContract, type PhoneNumberParseOptions, PhoneNumberType } from "../../phone-number.types";
4
- import { ISO2CountryCode } from "../../../country";
5
- import { MNOInfo } from "../mno.types";
1
+ import { ISO2CountryCode } from "@models/country/country.types.js";
2
+ import { MNOInfo } from "@models/phone-number/mno/mno.types.js";
3
+ import { PhoneNumber } from "@models/phone-number/phone-number.js";
4
+ import { type ParsedPhoneNumber, PhoneNumberService } from "@models/phone-number/phone-number.service.js";
5
+ import { type PhoneNumberContract, type PhoneNumberParseOptions, PhoneNumberType } from "@models/phone-number/phone-number.types.js";
6
6
  /**
7
7
  * Represents a validated Tanzanian (TZ) **mobile** phone number.
8
8
  * Extends the generic PhoneNumber class and provides TZ-specific behavior.
@@ -1,8 +1,8 @@
1
- import { type ParsedPhoneNumber, PhoneNumberService } from "./phone-number.service";
2
- import { PhoneNumberContract, PhoneNumberFormat, PhoneNumberParseOptions, PhoneNumberType } from "./phone-number.types";
3
- import type { ISO2CountryCode } from "../country/country.types";
1
+ import { ISO2CountryCode } from "@models/country/country.types.js";
4
2
  import type { PhoneNumber as LibPhoneNumberInstance } from "libphonenumber-js";
5
- import { MNOInfo } from "./mno";
3
+ import { MNOInfo } from "./mno/mno.types.js";
4
+ import { PhoneNumberService, ParsedPhoneNumber } from "./phone-number.service.js";
5
+ import { PhoneNumberContract, PhoneNumberFormat, PhoneNumberType, PhoneNumberParseOptions } from "./phone-number.types.js";
6
6
  /**
7
7
  * Represents a generic international phone number, validated using libphonenumber-js
8
8
  * via the PhoneNumberService. Implements the common PhoneNumberContract interface.
@@ -1,5 +1,5 @@
1
- import { type PhoneNumberContract, type PhoneNumberParseOptions } from "./phone-number.types";
2
- import { MNOInfo } from "./mno";
1
+ import { MNOInfo } from "./mno/mno.types.js";
2
+ import { PhoneNumberParseOptions, PhoneNumberContract } from "./phone-number.types.js";
3
3
  /**
4
4
  * Factory class for creating phone number objects that conform to PhoneNumberContract.
5
5
  * It attempts to use country-specific implementations (like TZMobileNumber, KEMobileNumber)
@@ -1,6 +1,6 @@
1
1
  import { type NumberType, type PhoneNumber as LibPhoneNumber } from "libphonenumber-js/max";
2
- import type { ISO2CountryCode } from "../country";
3
- import { PhoneNumberFormat } from "./phone-number.types";
2
+ import { PhoneNumberFormat } from "./phone-number.types.js";
3
+ import { ISO2CountryCode } from "@models/country/country.types.js";
4
4
  export interface ParsedPhoneNumber {
5
5
  libInstance: LibPhoneNumber;
6
6
  countryCode: ISO2CountryCode | undefined;
@@ -1,5 +1,5 @@
1
- import type { ISO2CountryCode } from "../country";
2
- import { MNOInfo } from "./mno/mno.types";
1
+ import { ISO2CountryCode } from "@models/country/country.types.js";
2
+ import { MNOInfo } from "./mno/mno.types.js";
3
3
  /**
4
4
  * Enumeration for various phone number formats used for display and processing.
5
5
  */
@@ -1,5 +1,5 @@
1
- import { CountryCode } from "../country";
2
- export declare const phoneLogger: import("pino").default.Logger<never, boolean>;
1
+ import { CountryCode } from "@models/country/country.types.js";
2
+ export declare const phoneLogger: import("pino").Logger<never, boolean>;
3
3
  export declare const PhoneNumberUtils: {
4
4
  /**
5
5
  * Removes all whitespace characters from the given string.
@@ -1 +1 @@
1
- export * from "./report-manager";
1
+ export * from "./report-manager.js";
@@ -1,2 +1,2 @@
1
- export * from "./config";
2
- export * from "./logger";
1
+ export * from "./config.js";
2
+ export * from "./logger.js";
@@ -1 +1,2 @@
1
- export declare const logger: import("pino").Logger<never, boolean>;
1
+ import pino from "pino";
2
+ export declare const logger: pino.Logger<never, boolean>;
@@ -1,3 +1,3 @@
1
- export * from "./id";
2
- export * from "./time";
3
- export * from "./text";
1
+ export * from "./id.js";
2
+ export * from "./time.js";
3
+ export * from "./text.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temboplus/frontend-core",
3
- "version": "0.2.17",
3
+ "version": "0.2.20-beta.0",
4
4
  "description": "A JavaScript/TypeScript package providing common utilities and logic shared across front-end TemboPlus projects.",
5
5
  "author": "Okello Gerald",
6
6
  "license": "MIT",
@@ -9,10 +9,13 @@
9
9
  "frontend-core"
10
10
  ],
11
11
  "type": "module",
12
+ "main": "./dist/index.cjs.js",
13
+ "module": "./dist/index.esm.js",
14
+ "types": "./dist/index.d.ts",
12
15
  "exports": {
13
16
  ".": {
14
- "import": "./dist/index.js",
15
- "require": "./dist/index.cjs",
17
+ "import": "./dist/index.esm.js",
18
+ "require": "./dist/index.cjs.js",
16
19
  "types": "./dist/index.d.ts"
17
20
  }
18
21
  },
@@ -23,14 +26,7 @@
23
26
  "build": "rollup -c rollup.config.js --configTsconfig tsconfig.build.json",
24
27
  "prepare": "npm run build",
25
28
  "dev": "npm run build -- --watch",
26
- "test": "jest",
27
- "test:watch": "jest --watch",
28
- "test:coverage": "jest --coverage",
29
- "test:amount": "jest /src/models/amount/__tests__/amount.test.ts",
30
- "test:phone-number": "jest /src/models/phone-number",
31
- "test:bank": "jest /src/models/bank/__tests__/bank.test.ts",
32
- "test:country": "jest /src/models/country/__tests__/country.test.ts",
33
- "test:currency": "jest /src/models/currency/__tests__/currency.test.ts"
29
+ "test": "vitest"
34
30
  },
35
31
  "repository": {
36
32
  "type": "git",
@@ -43,7 +39,7 @@
43
39
  "dependencies": {
44
40
  "file-saver": "^2.0.5",
45
41
  "libphonenumber-js": "^1.12.6",
46
- "pino": "^9.7.0",
42
+ "pino": "^9.13.1",
47
43
  "tslib": "^2.8.1",
48
44
  "uuid": "^11.1.0",
49
45
  "zod": "^3.24.2"
@@ -56,12 +52,10 @@
56
52
  "@rollup/plugin-terser": "^0.4.4",
57
53
  "@rollup/plugin-typescript": "^12.1.2",
58
54
  "@types/file-saver": "^2.0.7",
59
- "@types/jest": "^29.5.14",
60
- "jest": "^29.7.0",
61
- "pino-pretty": "^13.0.0",
55
+ "pino-pretty": "^13.1.1",
62
56
  "rollup": "^4.39.0",
63
- "ts-jest": "^29.4.0",
64
57
  "ts-node": "^10.9.2",
65
- "typescript": "^5.8.3"
58
+ "typescript": "^5.9.3",
59
+ "vitest": "^3.2.4"
66
60
  }
67
61
  }