@temboplus/frontend-core 0.2.1 → 0.2.3

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 (200) hide show
  1. package/README.md +126 -25
  2. package/esm/deps/jsr.io/@std/internal/1.0.5/assertion_state.d.ts.map +1 -0
  3. package/esm/deps/jsr.io/@std/testing/1.0.9/_test_suite.d.ts.map +1 -0
  4. package/esm/deps/jsr.io/@std/testing/1.0.9/bdd.d.ts.map +1 -0
  5. package/esm/mod.d.ts +2 -0
  6. package/esm/mod.d.ts.map +1 -1
  7. package/esm/mod.js +2 -0
  8. package/esm/src/config/config_service.d.ts +11 -0
  9. package/esm/src/config/config_service.d.ts.map +1 -0
  10. package/esm/src/config/config_service.js +19 -0
  11. package/esm/src/config/index.d.ts +2 -0
  12. package/esm/src/config/index.d.ts.map +1 -0
  13. package/esm/src/config/index.js +1 -0
  14. package/esm/src/{models/bank/banks.d.ts → data/banks_tz.d.ts} +1 -1
  15. package/esm/src/data/banks_tz.d.ts.map +1 -0
  16. package/esm/src/data/countries.d.ts +6 -0
  17. package/esm/src/data/countries.d.ts.map +1 -0
  18. package/esm/src/data/countries.js +974 -0
  19. package/esm/src/data/currencies.d.ts +1901 -0
  20. package/esm/src/data/currencies.d.ts.map +1 -0
  21. package/esm/src/data/currencies.js +1073 -0
  22. package/esm/src/data/phone_patterns.d.ts +3809 -0
  23. package/esm/src/data/phone_patterns.d.ts.map +1 -0
  24. package/esm/src/data/phone_patterns.js +2325 -0
  25. package/esm/src/models/amount/amount.d.ts +10 -12
  26. package/esm/src/models/amount/amount.d.ts.map +1 -1
  27. package/esm/src/models/amount/amount.js +58 -96
  28. package/esm/src/models/bank/bank.d.ts +58 -53
  29. package/esm/src/models/bank/bank.d.ts.map +1 -1
  30. package/esm/src/models/bank/bank.js +49 -84
  31. package/esm/src/models/bank/index.d.ts +1 -1
  32. package/esm/src/models/bank/index.d.ts.map +1 -1
  33. package/esm/src/models/bank/index.js +1 -1
  34. package/esm/src/models/bank/service.d.ts +106 -0
  35. package/esm/src/models/bank/service.d.ts.map +1 -0
  36. package/esm/src/models/bank/service.js +240 -0
  37. package/esm/src/models/country/country.d.ts +568 -0
  38. package/esm/src/models/country/country.d.ts.map +1 -0
  39. package/esm/src/models/country/country.js +165 -0
  40. package/esm/src/models/country/country.test.d.ts.map +1 -0
  41. package/esm/src/models/country/index.d.ts +3 -0
  42. package/esm/src/models/country/index.d.ts.map +1 -0
  43. package/esm/src/models/country/index.js +2 -0
  44. package/esm/src/models/country/service.d.ts +75 -0
  45. package/esm/src/models/country/service.d.ts.map +1 -0
  46. package/esm/src/models/country/service.js +267 -0
  47. package/esm/src/models/currency/currency.d.ts +341 -0
  48. package/esm/src/models/currency/currency.d.ts.map +1 -0
  49. package/esm/src/models/currency/currency.js +225 -0
  50. package/esm/src/models/currency/currency.test.d.ts.map +1 -0
  51. package/esm/src/models/currency/index.d.ts +3 -0
  52. package/esm/src/models/currency/index.d.ts.map +1 -0
  53. package/esm/src/models/currency/index.js +2 -0
  54. package/esm/src/models/currency/service.d.ts +96 -0
  55. package/esm/src/models/currency/service.d.ts.map +1 -0
  56. package/esm/src/models/currency/service.js +194 -0
  57. package/esm/src/models/index.d.ts +2 -0
  58. package/esm/src/models/index.d.ts.map +1 -1
  59. package/esm/src/models/index.js +2 -0
  60. package/esm/src/models/phone_number/format.d.ts +14 -0
  61. package/esm/src/models/phone_number/format.d.ts.map +1 -0
  62. package/esm/src/models/phone_number/format.js +14 -0
  63. package/esm/src/models/phone_number/global/phone_number.d.ts +160 -0
  64. package/esm/src/models/phone_number/global/phone_number.d.ts.map +1 -0
  65. package/esm/src/models/phone_number/global/phone_number.js +453 -0
  66. package/esm/src/models/phone_number/global/phone_number.test.d.ts.map +1 -0
  67. package/esm/src/models/phone_number/global/service.d.ts +260 -0
  68. package/esm/src/models/phone_number/global/service.d.ts.map +1 -0
  69. package/esm/src/models/phone_number/global/service.js +477 -0
  70. package/esm/src/models/phone_number/global/service.test.d.ts.map +1 -0
  71. package/esm/src/models/phone_number/index.d.ts +5 -3
  72. package/esm/src/models/phone_number/index.d.ts.map +1 -1
  73. package/esm/src/models/phone_number/index.js +5 -3
  74. package/esm/src/models/phone_number/{antd_validator.d.ts → tz/antd_validator.d.ts} +2 -2
  75. package/esm/src/models/phone_number/tz/antd_validator.d.ts.map +1 -0
  76. package/esm/src/models/phone_number/{antd_validator.js → tz/antd_validator.js} +2 -2
  77. package/esm/src/models/phone_number/tz/antdvalidator.test.d.ts.map +1 -0
  78. package/esm/src/models/phone_number/tz/network_operator.d.ts.map +1 -0
  79. package/{script/src/models/phone_number → esm/src/models/phone_number/tz}/phone_number.d.ts +46 -29
  80. package/esm/src/models/phone_number/tz/phone_number.d.ts.map +1 -0
  81. package/esm/src/models/phone_number/{phone_number.js → tz/phone_number.js} +87 -41
  82. package/esm/src/models/phone_number/tz/phone_number.test.d.ts.map +1 -0
  83. package/esm/src/reports/index.d.ts +2 -0
  84. package/esm/src/reports/index.d.ts.map +1 -0
  85. package/esm/src/reports/index.js +1 -0
  86. package/esm/src/reports/report_manager.d.ts +144 -0
  87. package/esm/src/reports/report_manager.d.ts.map +1 -0
  88. package/esm/src/reports/report_manager.js +315 -0
  89. package/package.json +4 -3
  90. package/script/deps/jsr.io/@std/internal/1.0.5/assertion_state.d.ts.map +1 -0
  91. package/script/deps/jsr.io/@std/testing/1.0.9/_test_suite.d.ts.map +1 -0
  92. package/script/deps/jsr.io/@std/testing/1.0.9/bdd.d.ts.map +1 -0
  93. package/script/mod.d.ts +2 -0
  94. package/script/mod.d.ts.map +1 -1
  95. package/script/mod.js +2 -0
  96. package/script/src/config/config_service.d.ts +11 -0
  97. package/script/src/config/config_service.d.ts.map +1 -0
  98. package/script/src/config/config_service.js +23 -0
  99. package/script/src/config/index.d.ts +2 -0
  100. package/script/src/config/index.d.ts.map +1 -0
  101. package/script/src/config/index.js +17 -0
  102. package/script/src/{models/bank/banks.d.ts → data/banks_tz.d.ts} +1 -1
  103. package/script/src/data/banks_tz.d.ts.map +1 -0
  104. package/script/src/data/countries.d.ts +6 -0
  105. package/script/src/data/countries.d.ts.map +1 -0
  106. package/script/src/data/countries.js +976 -0
  107. package/script/src/data/currencies.d.ts +1901 -0
  108. package/script/src/data/currencies.d.ts.map +1 -0
  109. package/script/src/data/currencies.js +1075 -0
  110. package/script/src/data/phone_patterns.d.ts +3809 -0
  111. package/script/src/data/phone_patterns.d.ts.map +1 -0
  112. package/script/src/data/phone_patterns.js +2327 -0
  113. package/script/src/models/amount/amount.d.ts +10 -12
  114. package/script/src/models/amount/amount.d.ts.map +1 -1
  115. package/script/src/models/amount/amount.js +60 -98
  116. package/script/src/models/bank/bank.d.ts +58 -53
  117. package/script/src/models/bank/bank.d.ts.map +1 -1
  118. package/script/src/models/bank/bank.js +49 -87
  119. package/script/src/models/bank/index.d.ts +1 -1
  120. package/script/src/models/bank/index.d.ts.map +1 -1
  121. package/script/src/models/bank/index.js +1 -1
  122. package/script/src/models/bank/service.d.ts +106 -0
  123. package/script/src/models/bank/service.d.ts.map +1 -0
  124. package/script/src/models/bank/service.js +247 -0
  125. package/script/src/models/country/country.d.ts +568 -0
  126. package/script/src/models/country/country.d.ts.map +1 -0
  127. package/script/src/models/country/country.js +169 -0
  128. package/script/src/models/country/country.test.d.ts.map +1 -0
  129. package/script/src/models/country/index.d.ts +3 -0
  130. package/script/src/models/country/index.d.ts.map +1 -0
  131. package/script/src/models/country/index.js +18 -0
  132. package/script/src/models/country/service.d.ts +75 -0
  133. package/script/src/models/country/service.d.ts.map +1 -0
  134. package/script/src/models/country/service.js +274 -0
  135. package/script/src/models/currency/currency.d.ts +341 -0
  136. package/script/src/models/currency/currency.d.ts.map +1 -0
  137. package/script/src/models/currency/currency.js +229 -0
  138. package/script/src/models/currency/currency.test.d.ts.map +1 -0
  139. package/script/src/models/currency/index.d.ts +3 -0
  140. package/script/src/models/currency/index.d.ts.map +1 -0
  141. package/script/src/models/currency/index.js +18 -0
  142. package/script/src/models/currency/service.d.ts +96 -0
  143. package/script/src/models/currency/service.d.ts.map +1 -0
  144. package/script/src/models/currency/service.js +201 -0
  145. package/script/src/models/index.d.ts +2 -0
  146. package/script/src/models/index.d.ts.map +1 -1
  147. package/script/src/models/index.js +2 -0
  148. package/script/src/models/phone_number/format.d.ts +14 -0
  149. package/script/src/models/phone_number/format.d.ts.map +1 -0
  150. package/script/src/models/phone_number/format.js +17 -0
  151. package/script/src/models/phone_number/global/phone_number.d.ts +160 -0
  152. package/script/src/models/phone_number/global/phone_number.d.ts.map +1 -0
  153. package/script/src/models/phone_number/global/phone_number.js +457 -0
  154. package/script/src/models/phone_number/global/phone_number.test.d.ts.map +1 -0
  155. package/script/src/models/phone_number/global/service.d.ts +260 -0
  156. package/script/src/models/phone_number/global/service.d.ts.map +1 -0
  157. package/script/src/models/phone_number/global/service.js +485 -0
  158. package/script/src/models/phone_number/global/service.test.d.ts.map +1 -0
  159. package/script/src/models/phone_number/index.d.ts +5 -3
  160. package/script/src/models/phone_number/index.d.ts.map +1 -1
  161. package/script/src/models/phone_number/index.js +5 -3
  162. package/script/src/models/phone_number/{antd_validator.d.ts → tz/antd_validator.d.ts} +2 -2
  163. package/script/src/models/phone_number/tz/antd_validator.d.ts.map +1 -0
  164. package/script/src/models/phone_number/{antd_validator.js → tz/antd_validator.js} +1 -1
  165. package/script/src/models/phone_number/tz/antdvalidator.test.d.ts.map +1 -0
  166. package/script/src/models/phone_number/tz/network_operator.d.ts.map +1 -0
  167. package/{esm/src/models/phone_number → script/src/models/phone_number/tz}/phone_number.d.ts +46 -29
  168. package/script/src/models/phone_number/tz/phone_number.d.ts.map +1 -0
  169. package/script/src/models/phone_number/{phone_number.js → tz/phone_number.js} +89 -43
  170. package/script/src/models/phone_number/tz/phone_number.test.d.ts.map +1 -0
  171. package/script/src/reports/index.d.ts +2 -0
  172. package/script/src/reports/index.d.ts.map +1 -0
  173. package/script/src/reports/index.js +17 -0
  174. package/script/src/reports/report_manager.d.ts +144 -0
  175. package/script/src/reports/report_manager.d.ts.map +1 -0
  176. package/script/src/reports/report_manager.js +325 -0
  177. package/esm/src/models/bank/banks.d.ts.map +0 -1
  178. package/esm/src/models/bank/utils.d.ts +0 -25
  179. package/esm/src/models/bank/utils.d.ts.map +0 -1
  180. package/esm/src/models/bank/utils.js +0 -35
  181. package/esm/src/models/phone_number/antd_validator.d.ts.map +0 -1
  182. package/esm/src/models/phone_number/antdvalidator.test.d.ts.map +0 -1
  183. package/esm/src/models/phone_number/network_operator.d.ts.map +0 -1
  184. package/esm/src/models/phone_number/phone_number.d.ts.map +0 -1
  185. package/esm/src/models/phone_number/phone_number.test.d.ts.map +0 -1
  186. package/script/src/models/bank/banks.d.ts.map +0 -1
  187. package/script/src/models/bank/utils.d.ts +0 -25
  188. package/script/src/models/bank/utils.d.ts.map +0 -1
  189. package/script/src/models/bank/utils.js +0 -41
  190. package/script/src/models/phone_number/antd_validator.d.ts.map +0 -1
  191. package/script/src/models/phone_number/antdvalidator.test.d.ts.map +0 -1
  192. package/script/src/models/phone_number/network_operator.d.ts.map +0 -1
  193. package/script/src/models/phone_number/phone_number.d.ts.map +0 -1
  194. package/script/src/models/phone_number/phone_number.test.d.ts.map +0 -1
  195. /package/esm/src/{models/bank/banks.js → data/banks_tz.js} +0 -0
  196. /package/esm/src/models/phone_number/{network_operator.d.ts → tz/network_operator.d.ts} +0 -0
  197. /package/esm/src/models/phone_number/{network_operator.js → tz/network_operator.js} +0 -0
  198. /package/script/src/{models/bank/banks.js → data/banks_tz.js} +0 -0
  199. /package/script/src/models/phone_number/{network_operator.d.ts → tz/network_operator.d.ts} +0 -0
  200. /package/script/src/models/phone_number/{network_operator.js → tz/network_operator.js} +0 -0
@@ -0,0 +1,325 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ReportManager = exports.REPORTS = exports.ReportType = exports.ProjectType = exports.FileFormat = void 0;
7
+ exports.getReportsByProject = getReportsByProject;
8
+ exports.getReportByType = getReportByType;
9
+ exports.isReportAvailableForProject = isReportAvailableForProject;
10
+ const file_saver_1 = __importDefault(require("file-saver"));
11
+ const index_js_1 = require("../config/index.js");
12
+ /**
13
+ * Available file formats for reports
14
+ */
15
+ var FileFormat;
16
+ (function (FileFormat) {
17
+ /** PDF file format */
18
+ FileFormat["PDF"] = "pdf";
19
+ /** Excel file format */
20
+ FileFormat["EXCEL"] = "excel";
21
+ })(FileFormat || (exports.FileFormat = FileFormat = {}));
22
+ /**
23
+ * Available project types
24
+ */
25
+ var ProjectType;
26
+ (function (ProjectType) {
27
+ /** Tembo Dashboard project */
28
+ ProjectType["DASHBOARD"] = "dashboard";
29
+ /** Afloat project */
30
+ ProjectType["AFLOAT"] = "afloat";
31
+ /** VertoX project */
32
+ ProjectType["VERTO_X"] = "verto_x";
33
+ })(ProjectType || (exports.ProjectType = ProjectType = {}));
34
+ /**
35
+ * Available report types with improved naming
36
+ */
37
+ var ReportType;
38
+ (function (ReportType) {
39
+ /** Merchant payout statement (Dashboard) */
40
+ ReportType["MERCHANT_DISBURSEMENT_REPORT"] = "merchant_disbursement_report";
41
+ /** Transaction revenue summary (Dashboard) */
42
+ ReportType["TRANSACTION_REVENUE_SUMMARY"] = "transaction_revenue_summary";
43
+ /** Customer wallet activity (Afloat) */
44
+ ReportType["CUSTOMER_WALLET_ACTIVITY"] = "customer_wallet_activity";
45
+ /** Customer profile information (Afloat) */
46
+ ReportType["CUSTOMER_PROFILE_SNAPSHOT"] = "customer_profile_snapshot";
47
+ /** Gateway transaction log (VertoX) */
48
+ ReportType["GATEWAY_TRANSACTION_LOG"] = "gateway_transaction_log";
49
+ })(ReportType || (exports.ReportType = ReportType = {}));
50
+ /**
51
+ * Registry of all available reports
52
+ */
53
+ exports.REPORTS = {
54
+ // Dashboard Reports
55
+ [ReportType.MERCHANT_DISBURSEMENT_REPORT]: {
56
+ id: "merchant_disbursement_report",
57
+ displayName: "Merchant Disbursement Report",
58
+ endpoint: "/dashboard/merchant_disbursements",
59
+ availableFormats: [FileFormat.PDF, FileFormat.EXCEL],
60
+ projectType: ProjectType.DASHBOARD,
61
+ reportType: ReportType.MERCHANT_DISBURSEMENT_REPORT,
62
+ description: "Detailed breakdown of payments made to merchants",
63
+ },
64
+ [ReportType.TRANSACTION_REVENUE_SUMMARY]: {
65
+ id: "transaction_revenue_summary",
66
+ displayName: "Transaction Revenue Summary",
67
+ endpoint: "/dashboard/revenue_summary",
68
+ availableFormats: [FileFormat.PDF, FileFormat.EXCEL],
69
+ projectType: ProjectType.DASHBOARD,
70
+ reportType: ReportType.TRANSACTION_REVENUE_SUMMARY,
71
+ description: "Summary of all revenue transactions by period",
72
+ },
73
+ // Afloat Reports
74
+ [ReportType.CUSTOMER_WALLET_ACTIVITY]: {
75
+ id: "customer_wallet_activity",
76
+ displayName: "Customer Wallet Activity",
77
+ endpoint: "/afloat/wallet_activity",
78
+ availableFormats: [FileFormat.PDF, FileFormat.EXCEL],
79
+ projectType: ProjectType.AFLOAT,
80
+ reportType: ReportType.CUSTOMER_WALLET_ACTIVITY,
81
+ description: "Detailed record of all customer wallet transactions",
82
+ },
83
+ [ReportType.CUSTOMER_PROFILE_SNAPSHOT]: {
84
+ id: "customer_profile_snapshot",
85
+ displayName: "Customer Profile Snapshot",
86
+ endpoint: "/afloat/profile_snapshot",
87
+ availableFormats: [FileFormat.PDF],
88
+ projectType: ProjectType.AFLOAT,
89
+ reportType: ReportType.CUSTOMER_PROFILE_SNAPSHOT,
90
+ description: "Current account information and status",
91
+ },
92
+ // VertoX Reports
93
+ [ReportType.GATEWAY_TRANSACTION_LOG]: {
94
+ id: "gateway_transaction_log",
95
+ displayName: "Gateway Transaction Log",
96
+ endpoint: "/vertox/gateway_transactions",
97
+ availableFormats: [FileFormat.EXCEL],
98
+ projectType: ProjectType.VERTO_X,
99
+ reportType: ReportType.GATEWAY_TRANSACTION_LOG,
100
+ description: "Log of all payment gateway API transactions",
101
+ },
102
+ };
103
+ /**
104
+ * Get all reports for a specific project
105
+ * @param projectType The project type to filter by
106
+ * @returns Array of report definitions for the project
107
+ */
108
+ function getReportsByProject(projectType) {
109
+ return Object.values(exports.REPORTS).filter((report) => report.projectType === projectType);
110
+ }
111
+ /**
112
+ * Get a report by its type
113
+ * @param reportType The report type to retrieve
114
+ * @returns The report definition or undefined if not found
115
+ */
116
+ function getReportByType(reportType) {
117
+ return exports.REPORTS[reportType];
118
+ }
119
+ /**
120
+ * Validates if a report type is available for a project
121
+ * @param projectType The project type
122
+ * @param reportType The report type
123
+ * @returns True if the report is available for the project, false otherwise
124
+ */
125
+ function isReportAvailableForProject(projectType, reportType) {
126
+ const report = exports.REPORTS[reportType];
127
+ return report !== undefined && report.projectType === projectType;
128
+ }
129
+ /**
130
+ * Report Manager class for handling report downloads
131
+ */
132
+ class ReportManager {
133
+ constructor() {
134
+ /**
135
+ * Get the base URL for the report API
136
+ * @returns The base URL
137
+ */
138
+ Object.defineProperty(this, "getBaseURL", {
139
+ enumerable: true,
140
+ configurable: true,
141
+ writable: true,
142
+ value: () => {
143
+ const url = index_js_1.ConfigService.instance.pdfMakerBaseUrl;
144
+ if (url.endsWith("/"))
145
+ return url.slice(0, -1);
146
+ return url;
147
+ }
148
+ });
149
+ /**
150
+ * Converts a base64 string to a Blob
151
+ * @param base64 The base64 string
152
+ * @returns A Blob
153
+ */
154
+ Object.defineProperty(this, "b64toBlob", {
155
+ enumerable: true,
156
+ configurable: true,
157
+ writable: true,
158
+ value: (base64) => fetch(base64).then((res) => res.blob())
159
+ });
160
+ }
161
+ /**
162
+ * Get the singleton instance of ReportManager
163
+ */
164
+ static get instance() {
165
+ return this._instance || (this._instance = new this());
166
+ }
167
+ /**
168
+ * Downloads a report based on project type and report type
169
+ * @param args Arguments for the report download
170
+ * @returns Promise that resolves when download is complete
171
+ */
172
+ async downloadReport(args) {
173
+ try {
174
+ // Get the report from the registry
175
+ const report = exports.REPORTS[args.reportType];
176
+ if (!report) {
177
+ throw new Error(`Report type ${args.reportType} not configured`);
178
+ }
179
+ // Validate that the report belongs to the specified project
180
+ if (report.projectType !== args.projectType) {
181
+ throw new Error(`Report type ${args.reportType} does not belong to project ${args.projectType}`);
182
+ }
183
+ // Check if requested format is supported
184
+ if (!report.availableFormats.includes(args.fileFormat)) {
185
+ throw new Error(`File format ${args.fileFormat} not supported for ${report.displayName}`);
186
+ }
187
+ // Build URL using the report's endpoint
188
+ let url = `${this.getBaseURL()}${report.endpoint}`;
189
+ // Create a properly typed query parameters object
190
+ // deno-lint-ignore no-explicit-any
191
+ const queryParams = {
192
+ ...(args.query || {}),
193
+ format: args.fileFormat,
194
+ };
195
+ // Build the query string
196
+ const searchParams = new URLSearchParams();
197
+ for (const key in queryParams) {
198
+ if (Object.prototype.hasOwnProperty.call(queryParams, key)) {
199
+ const value = queryParams[key];
200
+ if (value !== undefined && value !== null) {
201
+ if (Array.isArray(value)) {
202
+ value.forEach((item) => {
203
+ searchParams.append(key + "[]", String(item));
204
+ });
205
+ }
206
+ else {
207
+ searchParams.append(key, String(value));
208
+ }
209
+ }
210
+ }
211
+ }
212
+ const queryString = searchParams.toString();
213
+ if (queryString) {
214
+ url += `?${queryString}`;
215
+ }
216
+ // Make the request
217
+ const response = await fetch(url, {
218
+ method: "GET",
219
+ headers: {
220
+ "Accept": "*/*",
221
+ "Content-Type": "application/json",
222
+ "Authorization": `Bearer ${args.token}`,
223
+ },
224
+ });
225
+ if (response.status !== 200) {
226
+ await this.handleErrorResponse(response);
227
+ }
228
+ // Process the download
229
+ await this.processDownload(response, report, args.fileFormat);
230
+ }
231
+ catch (error) {
232
+ console.error("Report download failed:", error);
233
+ throw error;
234
+ }
235
+ }
236
+ /**
237
+ * Process the download
238
+ * @param response The response from the API
239
+ * @param report The report definition
240
+ * @param fileFormat The requested file format
241
+ */
242
+ async processDownload(response, report, fileFormat) {
243
+ const contentDisposition = response.headers.get("Content-Disposition");
244
+ // Get default filename based on report and file format
245
+ const defaultFilename = this.getDefaultFilename(report, fileFormat);
246
+ // Try to get filename from Content-Disposition, fall back to default
247
+ const fileName = this.extractFilenameFromContentDisposition(contentDisposition) ||
248
+ defaultFilename;
249
+ // Handle the response based on content type
250
+ // deno-lint-ignore no-explicit-any
251
+ const blob = await this.b64toBlob(await response.text());
252
+ file_saver_1.default.saveAs(blob, fileName);
253
+ }
254
+ /**
255
+ * Handle error responses from the API
256
+ * @param response The response from the API
257
+ * @throws Error with appropriate message
258
+ */
259
+ async handleErrorResponse(response) {
260
+ let errorMessage = "Encountered an error while generating report";
261
+ try {
262
+ // Try to parse as JSON first
263
+ const contentType = response.headers.get("Content-Type");
264
+ if (contentType && contentType.includes("application/json")) {
265
+ const errorData = await response.json();
266
+ errorMessage = errorData.message || errorData.error ||
267
+ errorMessage;
268
+ }
269
+ else {
270
+ // Try to get error as text
271
+ const textError = await response.text();
272
+ if (textError) {
273
+ errorMessage = textError;
274
+ }
275
+ }
276
+ }
277
+ catch (parseError) {
278
+ console.error("Error parsing error response:", parseError);
279
+ }
280
+ throw new Error(errorMessage);
281
+ }
282
+ /**
283
+ * Generates a default filename based on report and file format
284
+ * @param report The report definition
285
+ * @param fileFormat The requested file format
286
+ * @returns A suitable default filename with proper extension
287
+ */
288
+ getDefaultFilename(report, fileFormat) {
289
+ const date = new Date().toISOString().slice(0, 10); // YYYY-MM-DD format
290
+ // Build the filename with project, report type, and date
291
+ const baseFilename = `${report.id}_${date}`;
292
+ // Add the extension based on the file format
293
+ return fileFormat === FileFormat.PDF
294
+ ? `${baseFilename}.pdf`
295
+ : `${baseFilename}.xlsx`;
296
+ }
297
+ /**
298
+ * Extracts the filename from the Content-Disposition header
299
+ * @param contentDisposition The Content-Disposition header value
300
+ * @returns The extracted filename or null if not found
301
+ */
302
+ extractFilenameFromContentDisposition(contentDisposition) {
303
+ // Check if the header exists
304
+ if (!contentDisposition) {
305
+ return null;
306
+ }
307
+ // Try to match the filename pattern
308
+ const filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
309
+ const matches = filenameRegex.exec(contentDisposition);
310
+ if (matches && matches[1]) {
311
+ // Clean up the filename by removing quotes if present
312
+ let filename = matches[1].trim();
313
+ // Remove surrounding quotes if they exist
314
+ if (filename.startsWith('"') && filename.endsWith('"')) {
315
+ filename = filename.substring(1, filename.length - 1);
316
+ }
317
+ else if (filename.startsWith("'") && filename.endsWith("'")) {
318
+ filename = filename.substring(1, filename.length - 1);
319
+ }
320
+ return filename;
321
+ }
322
+ return null;
323
+ }
324
+ }
325
+ exports.ReportManager = ReportManager;
@@ -1 +0,0 @@
1
- {"version":3,"file":"banks.d.ts","sourceRoot":"","sources":["../../../../src/src/models/bank/banks.js"],"names":[],"mappings":""}
@@ -1,25 +0,0 @@
1
- /**
2
- * Regex pattern to validate SWIFT codes.
3
- * The SWIFT code must follow the format: XXXX XX XX XXX (optional last part for branches).
4
- * @constant {RegExp}
5
- */
6
- export declare const SWIFT_CODE_REGEX: RegExp;
7
- /**
8
- * Retrieves all SWIFT codes from the TZ_BANKS list.
9
- * @returns {string[]} A list of all SWIFT codes in uppercase.
10
- */
11
- export declare function getAllSwiftCodes(): string[];
12
- /**
13
- * Checks whether a given SWIFT code is in the correct format.
14
- * @param {string} swiftCode The SWIFT code to check.
15
- * @returns {boolean} `true` if the SWIFT code matches the expected format; `false` otherwise.
16
- */
17
- export declare function isValidSwiftCodeFormat(swiftCode: string): boolean;
18
- /**
19
- * Validates whether a given SWIFT code is correct.
20
- * It checks both the SWIFT code format and if the SWIFT code exists in the list of valid codes.
21
- * @param {string} [swiftCode] The SWIFT code to validate.
22
- * @returns {boolean} `true` if valid, otherwise `false`.
23
- */
24
- export declare const validateSWIFTCode: (swiftCode?: string) => boolean;
25
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/src/models/bank/utils.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,QAAgD,CAAC;AAE9E;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,EAAE,CAE3C;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAEjE;AAED;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,eAAgB,MAAM,KAAG,OAQtD,CAAC"}
@@ -1,35 +0,0 @@
1
- import { Bank } from "./bank.js";
2
- /**
3
- * Regex pattern to validate SWIFT codes.
4
- * The SWIFT code must follow the format: XXXX XX XX XXX (optional last part for branches).
5
- * @constant {RegExp}
6
- */
7
- export const SWIFT_CODE_REGEX = /^[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?$/;
8
- /**
9
- * Retrieves all SWIFT codes from the TZ_BANKS list.
10
- * @returns {string[]} A list of all SWIFT codes in uppercase.
11
- */
12
- export function getAllSwiftCodes() {
13
- return Bank.getAll().map((bank) => bank.swiftCode.toUpperCase());
14
- }
15
- /**
16
- * Checks whether a given SWIFT code is in the correct format.
17
- * @param {string} swiftCode The SWIFT code to check.
18
- * @returns {boolean} `true` if the SWIFT code matches the expected format; `false` otherwise.
19
- */
20
- export function isValidSwiftCodeFormat(swiftCode) {
21
- return SWIFT_CODE_REGEX.test(swiftCode);
22
- }
23
- /**
24
- * Validates whether a given SWIFT code is correct.
25
- * It checks both the SWIFT code format and if the SWIFT code exists in the list of valid codes.
26
- * @param {string} [swiftCode] The SWIFT code to validate.
27
- * @returns {boolean} `true` if valid, otherwise `false`.
28
- */
29
- export const validateSWIFTCode = (swiftCode) => {
30
- if (!swiftCode)
31
- return false;
32
- const normalizedCode = swiftCode.trim().toUpperCase();
33
- return (isValidSwiftCodeFormat(normalizedCode) &&
34
- getAllSwiftCodes().includes(normalizedCode));
35
- };
@@ -1 +0,0 @@
1
- {"version":3,"file":"antd_validator.d.ts","sourceRoot":"","sources":["../../../../src/src/models/phone_number/antd_validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuEG;AACH,eAAO,MAAM,qBAAqB,QACkF,CAAC;AAErH,eAAO,MAAM,qBAAqB,SAC1B,UAAU,SACT,MAAM,GAAG,IAAI,GAAG,SAAS,KAC/B,OAAO,CAAC,WAAW,GAAG,SAAS,CAiBjC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"antdvalidator.test.d.ts","sourceRoot":"","sources":["../../../../src/src/models/phone_number/antdvalidator.test.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"network_operator.d.ts","sourceRoot":"","sources":["../../../../src/src/models/phone_number/network_operator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,oBAAY,eAAe;IACzB,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,OAAO,YAAY;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,iDAAiD;IACjD,EAAE,EAAE,eAAe,CAAC;IAEpB,+DAA+D;IAC/D,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAE/B,2CAA2C;IAC3C,WAAW,EAAE,MAAM,CAAC;IAEpB,wDAAwD;IACxD,kBAAkB,EAAE,MAAM,CAAC;IAE3B,+CAA+C;IAC/C,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAC1C,eAAe,EACf,mBAAmB,CA8BpB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"phone_number.d.ts","sourceRoot":"","sources":["../../../../src/src/models/phone_number/phone_number.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,uBAAuB,CAAC;AAE/B;;;GAGG;AACH,oBAAY,kBAAkB;IAC5B,IAAI,QAAQ,CAAE,mCAAmC;IACjD,KAAK,SAAS,CAAE,oCAAoC;IACpD,EAAE,MAAM,CAAE,iCAAiC;IAC3C,IAAI,KAAK;CACV;AAED;;GAEG;AACH,qBAAa,WAAW;IACtB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;;;OAIG;gBACS,aAAa,EAAE,MAAM;IAIjC;;;;;OAKG;IACH,mBAAmB,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM;IAIvD;;;;OAIG;IACH,IAAI,KAAK,IAAI,MAAM,CAElB;IAED;;;;OAIG;IACH,IAAI,eAAe,IAAI,mBAAmB,CAMzC;IAED;;;;;OAKG;WACW,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS;IAqCtD;;;;;OAKG;WACW,YAAY,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO;IAW1D;;;;;;;;;;;;;;;;;;;OAmBG;WACW,EAAE,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,WAAW;IAYlD;;;OAGG;IACI,QAAQ,IAAI,OAAO;CAO3B"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"phone_number.test.d.ts","sourceRoot":"","sources":["../../../../src/src/models/phone_number/phone_number.test.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"banks.d.ts","sourceRoot":"","sources":["../../../../src/src/models/bank/banks.js"],"names":[],"mappings":""}
@@ -1,25 +0,0 @@
1
- /**
2
- * Regex pattern to validate SWIFT codes.
3
- * The SWIFT code must follow the format: XXXX XX XX XXX (optional last part for branches).
4
- * @constant {RegExp}
5
- */
6
- export declare const SWIFT_CODE_REGEX: RegExp;
7
- /**
8
- * Retrieves all SWIFT codes from the TZ_BANKS list.
9
- * @returns {string[]} A list of all SWIFT codes in uppercase.
10
- */
11
- export declare function getAllSwiftCodes(): string[];
12
- /**
13
- * Checks whether a given SWIFT code is in the correct format.
14
- * @param {string} swiftCode The SWIFT code to check.
15
- * @returns {boolean} `true` if the SWIFT code matches the expected format; `false` otherwise.
16
- */
17
- export declare function isValidSwiftCodeFormat(swiftCode: string): boolean;
18
- /**
19
- * Validates whether a given SWIFT code is correct.
20
- * It checks both the SWIFT code format and if the SWIFT code exists in the list of valid codes.
21
- * @param {string} [swiftCode] The SWIFT code to validate.
22
- * @returns {boolean} `true` if valid, otherwise `false`.
23
- */
24
- export declare const validateSWIFTCode: (swiftCode?: string) => boolean;
25
- //# sourceMappingURL=utils.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/src/models/bank/utils.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,eAAO,MAAM,gBAAgB,QAAgD,CAAC;AAE9E;;;GAGG;AACH,wBAAgB,gBAAgB,IAAI,MAAM,EAAE,CAE3C;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAEjE;AAED;;;;;GAKG;AACH,eAAO,MAAM,iBAAiB,eAAgB,MAAM,KAAG,OAQtD,CAAC"}
@@ -1,41 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.validateSWIFTCode = exports.SWIFT_CODE_REGEX = void 0;
4
- exports.getAllSwiftCodes = getAllSwiftCodes;
5
- exports.isValidSwiftCodeFormat = isValidSwiftCodeFormat;
6
- const bank_js_1 = require("./bank.js");
7
- /**
8
- * Regex pattern to validate SWIFT codes.
9
- * The SWIFT code must follow the format: XXXX XX XX XXX (optional last part for branches).
10
- * @constant {RegExp}
11
- */
12
- exports.SWIFT_CODE_REGEX = /^[A-Z]{4}[A-Z]{2}[A-Z0-9]{2}([A-Z0-9]{3})?$/;
13
- /**
14
- * Retrieves all SWIFT codes from the TZ_BANKS list.
15
- * @returns {string[]} A list of all SWIFT codes in uppercase.
16
- */
17
- function getAllSwiftCodes() {
18
- return bank_js_1.Bank.getAll().map((bank) => bank.swiftCode.toUpperCase());
19
- }
20
- /**
21
- * Checks whether a given SWIFT code is in the correct format.
22
- * @param {string} swiftCode The SWIFT code to check.
23
- * @returns {boolean} `true` if the SWIFT code matches the expected format; `false` otherwise.
24
- */
25
- function isValidSwiftCodeFormat(swiftCode) {
26
- return exports.SWIFT_CODE_REGEX.test(swiftCode);
27
- }
28
- /**
29
- * Validates whether a given SWIFT code is correct.
30
- * It checks both the SWIFT code format and if the SWIFT code exists in the list of valid codes.
31
- * @param {string} [swiftCode] The SWIFT code to validate.
32
- * @returns {boolean} `true` if valid, otherwise `false`.
33
- */
34
- const validateSWIFTCode = (swiftCode) => {
35
- if (!swiftCode)
36
- return false;
37
- const normalizedCode = swiftCode.trim().toUpperCase();
38
- return (isValidSwiftCodeFormat(normalizedCode) &&
39
- getAllSwiftCodes().includes(normalizedCode));
40
- };
41
- exports.validateSWIFTCode = validateSWIFTCode;
@@ -1 +0,0 @@
1
- {"version":3,"file":"antd_validator.d.ts","sourceRoot":"","sources":["../../../../src/src/models/phone_number/antd_validator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuEG;AACH,eAAO,MAAM,qBAAqB,QACkF,CAAC;AAErH,eAAO,MAAM,qBAAqB,SAC1B,UAAU,SACT,MAAM,GAAG,IAAI,GAAG,SAAS,KAC/B,OAAO,CAAC,WAAW,GAAG,SAAS,CAiBjC,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"antdvalidator.test.d.ts","sourceRoot":"","sources":["../../../../src/src/models/phone_number/antdvalidator.test.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"network_operator.d.ts","sourceRoot":"","sources":["../../../../src/src/models/phone_number/network_operator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,oBAAY,eAAe;IACzB,OAAO,YAAY;IACnB,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,OAAO,YAAY;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,iDAAiD;IACjD,EAAE,EAAE,eAAe,CAAC;IAEpB,+DAA+D;IAC/D,oBAAoB,EAAE,MAAM,EAAE,CAAC;IAE/B,2CAA2C;IAC3C,WAAW,EAAE,MAAM,CAAC;IAEpB,wDAAwD;IACxD,kBAAkB,EAAE,MAAM,CAAC;IAE3B,+CAA+C;IAC/C,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAC1C,eAAe,EACf,mBAAmB,CA8BpB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"phone_number.d.ts","sourceRoot":"","sources":["../../../../src/src/models/phone_number/phone_number.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,uBAAuB,CAAC;AAE/B;;;GAGG;AACH,oBAAY,kBAAkB;IAC5B,IAAI,QAAQ,CAAE,mCAAmC;IACjD,KAAK,SAAS,CAAE,oCAAoC;IACpD,EAAE,MAAM,CAAE,iCAAiC;IAC3C,IAAI,KAAK;CACV;AAED;;GAEG;AACH,qBAAa,WAAW;IACtB;;OAEG;IACH,aAAa,EAAE,MAAM,CAAC;IAEtB;;;;OAIG;gBACS,aAAa,EAAE,MAAM;IAIjC;;;;;OAKG;IACH,mBAAmB,CAAC,MAAM,EAAE,kBAAkB,GAAG,MAAM;IAIvD;;;;OAIG;IACH,IAAI,KAAK,IAAI,MAAM,CAElB;IAED;;;;OAIG;IACH,IAAI,eAAe,IAAI,mBAAmB,CAMzC;IAED;;;;;OAKG;WACW,IAAI,CAAC,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS;IAqCtD;;;;;OAKG;WACW,YAAY,CAAC,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO;IAW1D;;;;;;;;;;;;;;;;;;;OAmBG;WACW,EAAE,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,WAAW;IAYlD;;;OAGG;IACI,QAAQ,IAAI,OAAO;CAO3B"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"phone_number.test.d.ts","sourceRoot":"","sources":["../../../../src/src/models/phone_number/phone_number.test.ts"],"names":[],"mappings":""}