@temboplus/frontend-core 0.2.2 → 0.2.4

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 (36) hide show
  1. package/README.md +101 -49
  2. package/esm/mod.d.ts +2 -0
  3. package/esm/mod.d.ts.map +1 -1
  4. package/esm/mod.js +2 -0
  5. package/esm/src/config/config_service.d.ts +11 -0
  6. package/esm/src/config/config_service.d.ts.map +1 -0
  7. package/esm/src/config/config_service.js +19 -0
  8. package/esm/src/config/index.d.ts +2 -0
  9. package/esm/src/config/index.d.ts.map +1 -0
  10. package/esm/src/config/index.js +1 -0
  11. package/esm/src/models/phone_number/tz/network_operator.d.ts.map +1 -1
  12. package/esm/src/models/phone_number/tz/network_operator.js +5 -2
  13. package/esm/src/reports/index.d.ts +2 -0
  14. package/esm/src/reports/index.d.ts.map +1 -0
  15. package/esm/src/reports/index.js +1 -0
  16. package/esm/src/reports/report_manager.d.ts +144 -0
  17. package/esm/src/reports/report_manager.d.ts.map +1 -0
  18. package/esm/src/reports/report_manager.js +318 -0
  19. package/package.json +2 -1
  20. package/script/mod.d.ts +2 -0
  21. package/script/mod.d.ts.map +1 -1
  22. package/script/mod.js +2 -0
  23. package/script/src/config/config_service.d.ts +11 -0
  24. package/script/src/config/config_service.d.ts.map +1 -0
  25. package/script/src/config/config_service.js +23 -0
  26. package/script/src/config/index.d.ts +2 -0
  27. package/script/src/config/index.d.ts.map +1 -0
  28. package/script/src/config/index.js +17 -0
  29. package/script/src/models/phone_number/tz/network_operator.d.ts.map +1 -1
  30. package/script/src/models/phone_number/tz/network_operator.js +5 -2
  31. package/script/src/reports/index.d.ts +2 -0
  32. package/script/src/reports/index.d.ts.map +1 -0
  33. package/script/src/reports/index.js +17 -0
  34. package/script/src/reports/report_manager.d.ts +144 -0
  35. package/script/src/reports/report_manager.d.ts.map +1 -0
  36. package/script/src/reports/report_manager.js +328 -0
@@ -0,0 +1,318 @@
1
+ import FileSaver from "file-saver";
2
+ import { ConfigService } from "../config/index.js";
3
+ /**
4
+ * Available file formats for reports
5
+ */
6
+ export var FileFormat;
7
+ (function (FileFormat) {
8
+ /** PDF file format */
9
+ FileFormat["PDF"] = "pdf";
10
+ /** Excel file format */
11
+ FileFormat["EXCEL"] = "excel";
12
+ })(FileFormat || (FileFormat = {}));
13
+ /**
14
+ * Available project types
15
+ */
16
+ export var ProjectType;
17
+ (function (ProjectType) {
18
+ /** Tembo Dashboard project */
19
+ ProjectType["DASHBOARD"] = "dashboard";
20
+ /** Afloat project */
21
+ ProjectType["AFLOAT"] = "afloat";
22
+ /** VertoX project */
23
+ ProjectType["VERTO_X"] = "verto_x";
24
+ })(ProjectType || (ProjectType = {}));
25
+ /**
26
+ * Available report types with improved naming
27
+ */
28
+ export var ReportType;
29
+ (function (ReportType) {
30
+ /** Merchant payout statement (Dashboard) */
31
+ ReportType["MERCHANT_DISBURSEMENT_REPORT"] = "merchant_disbursement_report";
32
+ /** Transaction revenue summary (Dashboard) */
33
+ ReportType["TRANSACTION_REVENUE_SUMMARY"] = "transaction_revenue_summary";
34
+ /** Customer wallet activity (Afloat) */
35
+ ReportType["CUSTOMER_WALLET_ACTIVITY"] = "customer_wallet_activity";
36
+ /** Customer profile information (Afloat) */
37
+ ReportType["CUSTOMER_PROFILE_SNAPSHOT"] = "customer_profile_snapshot";
38
+ /** Gateway transaction log (VertoX) */
39
+ ReportType["GATEWAY_TRANSACTION_LOG"] = "gateway_transaction_log";
40
+ })(ReportType || (ReportType = {}));
41
+ /**
42
+ * Registry of all available reports
43
+ */
44
+ export const REPORTS = {
45
+ // Dashboard Reports
46
+ [ReportType.MERCHANT_DISBURSEMENT_REPORT]: {
47
+ id: "merchant_disbursement_report",
48
+ displayName: "Merchant Disbursement Report",
49
+ endpoint: "/dashboard/merchant_disbursements",
50
+ availableFormats: [FileFormat.PDF, FileFormat.EXCEL],
51
+ projectType: ProjectType.DASHBOARD,
52
+ reportType: ReportType.MERCHANT_DISBURSEMENT_REPORT,
53
+ description: "Detailed breakdown of payments made to merchants",
54
+ },
55
+ [ReportType.TRANSACTION_REVENUE_SUMMARY]: {
56
+ id: "transaction_revenue_summary",
57
+ displayName: "Transaction Revenue Summary",
58
+ endpoint: "/dashboard/revenue_summary",
59
+ availableFormats: [FileFormat.PDF, FileFormat.EXCEL],
60
+ projectType: ProjectType.DASHBOARD,
61
+ reportType: ReportType.TRANSACTION_REVENUE_SUMMARY,
62
+ description: "Summary of all revenue transactions by period",
63
+ },
64
+ // Afloat Reports
65
+ [ReportType.CUSTOMER_WALLET_ACTIVITY]: {
66
+ id: "customer_wallet_activity",
67
+ displayName: "Customer Wallet Activity",
68
+ endpoint: "/afloat/wallet_activity",
69
+ availableFormats: [FileFormat.PDF, FileFormat.EXCEL],
70
+ projectType: ProjectType.AFLOAT,
71
+ reportType: ReportType.CUSTOMER_WALLET_ACTIVITY,
72
+ description: "Detailed record of all customer wallet transactions",
73
+ },
74
+ [ReportType.CUSTOMER_PROFILE_SNAPSHOT]: {
75
+ id: "customer_profile_snapshot",
76
+ displayName: "Customer Profile Snapshot",
77
+ endpoint: "/afloat/profile_snapshot",
78
+ availableFormats: [FileFormat.PDF],
79
+ projectType: ProjectType.AFLOAT,
80
+ reportType: ReportType.CUSTOMER_PROFILE_SNAPSHOT,
81
+ description: "Current account information and status",
82
+ },
83
+ // VertoX Reports
84
+ [ReportType.GATEWAY_TRANSACTION_LOG]: {
85
+ id: "gateway_transaction_log",
86
+ displayName: "Gateway Transaction Log",
87
+ endpoint: "/vertox/gateway_transactions",
88
+ availableFormats: [FileFormat.EXCEL],
89
+ projectType: ProjectType.VERTO_X,
90
+ reportType: ReportType.GATEWAY_TRANSACTION_LOG,
91
+ description: "Log of all payment gateway API transactions",
92
+ },
93
+ };
94
+ /**
95
+ * Get all reports for a specific project
96
+ * @param projectType The project type to filter by
97
+ * @returns Array of report definitions for the project
98
+ */
99
+ export function getReportsByProject(projectType) {
100
+ return Object.values(REPORTS).filter((report) => report.projectType === projectType);
101
+ }
102
+ /**
103
+ * Get a report by its type
104
+ * @param reportType The report type to retrieve
105
+ * @returns The report definition or undefined if not found
106
+ */
107
+ export function getReportByType(reportType) {
108
+ return REPORTS[reportType];
109
+ }
110
+ /**
111
+ * Validates if a report type is available for a project
112
+ * @param projectType The project type
113
+ * @param reportType The report type
114
+ * @returns True if the report is available for the project, false otherwise
115
+ */
116
+ export function isReportAvailableForProject(projectType, reportType) {
117
+ const report = REPORTS[reportType];
118
+ return report !== undefined && report.projectType === projectType;
119
+ }
120
+ /**
121
+ * Report Manager class for handling report downloads
122
+ */
123
+ export class ReportManager {
124
+ constructor() {
125
+ /**
126
+ * Get the base URL for the report API
127
+ * @returns The base URL
128
+ */
129
+ Object.defineProperty(this, "getBaseURL", {
130
+ enumerable: true,
131
+ configurable: true,
132
+ writable: true,
133
+ value: () => {
134
+ let url = ConfigService.instance.pdfMakerBaseUrl;
135
+ if (url.trim().length === 0) {
136
+ url = "https://api.afloat.money/pdf-maker";
137
+ }
138
+ if (url.endsWith("/"))
139
+ return url.slice(0, -1);
140
+ return url;
141
+ }
142
+ });
143
+ /**
144
+ * Converts a base64 string to a Blob
145
+ * @param base64 The base64 string
146
+ * @returns A Blob
147
+ */
148
+ Object.defineProperty(this, "b64toBlob", {
149
+ enumerable: true,
150
+ configurable: true,
151
+ writable: true,
152
+ value: (base64) => fetch(base64).then((res) => res.blob())
153
+ });
154
+ }
155
+ /**
156
+ * Get the singleton instance of ReportManager
157
+ */
158
+ static get instance() {
159
+ return this._instance || (this._instance = new this());
160
+ }
161
+ /**
162
+ * Downloads a report based on project type and report type
163
+ * @param args Arguments for the report download
164
+ * @returns Promise that resolves when download is complete
165
+ */
166
+ async downloadReport(args) {
167
+ try {
168
+ // Get the report from the registry
169
+ const report = REPORTS[args.reportType];
170
+ if (!report) {
171
+ throw new Error(`Report type ${args.reportType} not configured`);
172
+ }
173
+ // Validate that the report belongs to the specified project
174
+ if (report.projectType !== args.projectType) {
175
+ throw new Error(`Report type ${args.reportType} does not belong to project ${args.projectType}`);
176
+ }
177
+ // Check if requested format is supported
178
+ if (!report.availableFormats.includes(args.fileFormat)) {
179
+ throw new Error(`File format ${args.fileFormat} not supported for ${report.displayName}`);
180
+ }
181
+ // Build URL using the report's endpoint
182
+ let url = `${this.getBaseURL()}${report.endpoint}`;
183
+ // Create a properly typed query parameters object
184
+ // deno-lint-ignore no-explicit-any
185
+ const queryParams = {
186
+ ...(args.query || {}),
187
+ fileFormat: args.fileFormat,
188
+ };
189
+ // Build the query string
190
+ const searchParams = new URLSearchParams();
191
+ for (const key in queryParams) {
192
+ if (Object.prototype.hasOwnProperty.call(queryParams, key)) {
193
+ const value = queryParams[key];
194
+ if (value !== undefined && value !== null) {
195
+ if (Array.isArray(value)) {
196
+ value.forEach((item) => {
197
+ searchParams.append(key + "[]", String(item));
198
+ });
199
+ }
200
+ else {
201
+ searchParams.append(key, String(value));
202
+ }
203
+ }
204
+ }
205
+ }
206
+ const queryString = searchParams.toString();
207
+ if (queryString) {
208
+ url += `?${queryString}`;
209
+ }
210
+ // Make the request
211
+ const response = await fetch(url, {
212
+ method: "GET",
213
+ headers: {
214
+ "Accept": "*/*",
215
+ "Content-Type": "application/json",
216
+ "Authorization": `Bearer ${args.token}`,
217
+ },
218
+ });
219
+ if (response.status !== 200) {
220
+ await this.handleErrorResponse(response);
221
+ }
222
+ // Process the download
223
+ await this.processDownload(response, report, args.fileFormat);
224
+ }
225
+ catch (error) {
226
+ console.error("Report download failed:", error);
227
+ throw error;
228
+ }
229
+ }
230
+ /**
231
+ * Process the download
232
+ * @param response The response from the API
233
+ * @param report The report definition
234
+ * @param fileFormat The requested file format
235
+ */
236
+ async processDownload(response, report, fileFormat) {
237
+ const contentDisposition = response.headers.get("Content-Disposition");
238
+ // Get default filename based on report and file format
239
+ const defaultFilename = this.getDefaultFilename(report, fileFormat);
240
+ // Try to get filename from Content-Disposition, fall back to default
241
+ const fileName = this.extractFilenameFromContentDisposition(contentDisposition) ||
242
+ defaultFilename;
243
+ // Handle the response based on content type
244
+ // deno-lint-ignore no-explicit-any
245
+ const blob = await this.b64toBlob(await response.text());
246
+ FileSaver.saveAs(blob, fileName);
247
+ }
248
+ /**
249
+ * Handle error responses from the API
250
+ * @param response The response from the API
251
+ * @throws Error with appropriate message
252
+ */
253
+ async handleErrorResponse(response) {
254
+ let errorMessage = "Encountered an error while generating report";
255
+ try {
256
+ // Try to parse as JSON first
257
+ const contentType = response.headers.get("Content-Type");
258
+ if (contentType && contentType.includes("application/json")) {
259
+ const errorData = await response.json();
260
+ errorMessage = errorData.message || errorData.error ||
261
+ errorMessage;
262
+ }
263
+ else {
264
+ // Try to get error as text
265
+ const textError = await response.text();
266
+ if (textError) {
267
+ errorMessage = textError;
268
+ }
269
+ }
270
+ }
271
+ catch (parseError) {
272
+ console.error("Error parsing error response:", parseError);
273
+ }
274
+ throw new Error(errorMessage);
275
+ }
276
+ /**
277
+ * Generates a default filename based on report and file format
278
+ * @param report The report definition
279
+ * @param fileFormat The requested file format
280
+ * @returns A suitable default filename with proper extension
281
+ */
282
+ getDefaultFilename(report, fileFormat) {
283
+ const date = new Date().toISOString().slice(0, 10); // YYYY-MM-DD format
284
+ // Build the filename with project, report type, and date
285
+ const baseFilename = `${report.id}_${date}`;
286
+ // Add the extension based on the file format
287
+ return fileFormat === FileFormat.PDF
288
+ ? `${baseFilename}.pdf`
289
+ : `${baseFilename}.xlsx`;
290
+ }
291
+ /**
292
+ * Extracts the filename from the Content-Disposition header
293
+ * @param contentDisposition The Content-Disposition header value
294
+ * @returns The extracted filename or null if not found
295
+ */
296
+ extractFilenameFromContentDisposition(contentDisposition) {
297
+ // Check if the header exists
298
+ if (!contentDisposition) {
299
+ return null;
300
+ }
301
+ // Try to match the filename pattern
302
+ const filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
303
+ const matches = filenameRegex.exec(contentDisposition);
304
+ if (matches && matches[1]) {
305
+ // Clean up the filename by removing quotes if present
306
+ let filename = matches[1].trim();
307
+ // Remove surrounding quotes if they exist
308
+ if (filename.startsWith('"') && filename.endsWith('"')) {
309
+ filename = filename.substring(1, filename.length - 1);
310
+ }
311
+ else if (filename.startsWith("'") && filename.endsWith("'")) {
312
+ filename = filename.substring(1, filename.length - 1);
313
+ }
314
+ return filename;
315
+ }
316
+ return null;
317
+ }
318
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@temboplus/frontend-core",
3
- "version": "0.2.2",
3
+ "version": "0.2.4",
4
4
  "description": "A JavaScript/TypeScript package providing common utilities and logic shared across front-end TemboPlus projects.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -24,6 +24,7 @@
24
24
  "private": false,
25
25
  "dependencies": {
26
26
  "antd": "^5.24.2",
27
+ "file-saver": "^2.0.5",
27
28
  "uuid": "^11.1.0"
28
29
  },
29
30
  "devDependencies": {
package/script/mod.d.ts CHANGED
@@ -1,3 +1,5 @@
1
1
  export * from "./src/models/index.js";
2
2
  export * from "./src/utils/index.js";
3
+ export * from "./src/reports/index.js";
4
+ export * from "./src/config/index.js";
3
5
  //# sourceMappingURL=mod.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AAAA,cAAc,uBAAuB,CAAC;AACtC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC"}
package/script/mod.js CHANGED
@@ -16,3 +16,5 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./src/models/index.js"), exports);
18
18
  __exportStar(require("./src/utils/index.js"), exports);
19
+ __exportStar(require("./src/reports/index.js"), exports);
20
+ __exportStar(require("./src/config/index.js"), exports);
@@ -0,0 +1,11 @@
1
+ export declare class ConfigService {
2
+ private static _instance;
3
+ private _pdfMakerBaseUrl;
4
+ private constructor();
5
+ static get instance(): ConfigService;
6
+ initialize(config: {
7
+ pdfMakerBaseUrl: string;
8
+ }): void;
9
+ get pdfMakerBaseUrl(): string;
10
+ }
11
+ //# sourceMappingURL=config_service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config_service.d.ts","sourceRoot":"","sources":["../../../src/src/config/config_service.ts"],"names":[],"mappings":"AAAA,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAC,SAAS,CAAgB;IACxC,OAAO,CAAC,gBAAgB,CAAc;IAEtC,OAAO;IAEP,WAAkB,QAAQ,kBAEzB;IAEM,UAAU,CAAC,MAAM,EAAE;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE;IAIrD,IAAW,eAAe,IAAI,MAAM,CAEnC;CACF"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConfigService = void 0;
4
+ class ConfigService {
5
+ constructor() {
6
+ Object.defineProperty(this, "_pdfMakerBaseUrl", {
7
+ enumerable: true,
8
+ configurable: true,
9
+ writable: true,
10
+ value: ""
11
+ });
12
+ }
13
+ static get instance() {
14
+ return this._instance || (this._instance = new this());
15
+ }
16
+ initialize(config) {
17
+ this._pdfMakerBaseUrl = config.pdfMakerBaseUrl;
18
+ }
19
+ get pdfMakerBaseUrl() {
20
+ return this._pdfMakerBaseUrl;
21
+ }
22
+ }
23
+ exports.ConfigService = ConfigService;
@@ -0,0 +1,2 @@
1
+ export * from "./config_service.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/config/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./config_service.js"), exports);
@@ -1 +1 @@
1
- {"version":3,"file":"network_operator.d.ts","sourceRoot":"","sources":["../../../../../src/src/models/phone_number/tz/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
+ {"version":3,"file":"network_operator.d.ts","sourceRoot":"","sources":["../../../../../src/src/models/phone_number/tz/network_operator.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,oBAAY,eAAe;IACzB,OAAO,YAAY;IACnB,MAAM,WAAW;IAIjB,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"}
@@ -9,6 +9,9 @@ var NetworkOperator;
9
9
  (function (NetworkOperator) {
10
10
  NetworkOperator["VODACOM"] = "Vodacom";
11
11
  NetworkOperator["AIRTEL"] = "Airtel";
12
+ // Preserve the value "Tigo" bse our backend still recognizes it for payout channel codes
13
+ // It should not be seen anywhere for we have NetworkOperatorInfo.displayName & NetworkOperatorInfo.mobileMoneyService
14
+ // as labels we can use on the frontend
12
15
  NetworkOperator["TIGO"] = "Tigo";
13
16
  NetworkOperator["HALOTEL"] = "Halotel";
14
17
  })(NetworkOperator || (exports.NetworkOperator = NetworkOperator = {}));
@@ -34,8 +37,8 @@ exports.NETWORK_OPERATOR_CONFIG = {
34
37
  id: NetworkOperator.TIGO,
35
38
  mobileNumberPrefixes: ["71", "65", "67", "77"],
36
39
  displayName: "Yas",
37
- mobileMoneyService: "Mixx",
38
- brandColor: "blue",
40
+ mobileMoneyService: "Mixx by Yas",
41
+ brandColor: "yellow",
39
42
  },
40
43
  [NetworkOperator.HALOTEL]: {
41
44
  id: NetworkOperator.HALOTEL,
@@ -0,0 +1,2 @@
1
+ export * from "./report_manager.js";
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/src/reports/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAA"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./report_manager.js"), exports);
@@ -0,0 +1,144 @@
1
+ /**
2
+ * Available file formats for reports
3
+ */
4
+ export declare enum FileFormat {
5
+ /** PDF file format */
6
+ PDF = "pdf",
7
+ /** Excel file format */
8
+ EXCEL = "excel"
9
+ }
10
+ /**
11
+ * Available project types
12
+ */
13
+ export declare enum ProjectType {
14
+ /** Tembo Dashboard project */
15
+ DASHBOARD = "dashboard",
16
+ /** Afloat project */
17
+ AFLOAT = "afloat",
18
+ /** VertoX project */
19
+ VERTO_X = "verto_x"
20
+ }
21
+ /**
22
+ * Available report types with improved naming
23
+ */
24
+ export declare enum ReportType {
25
+ /** Merchant payout statement (Dashboard) */
26
+ MERCHANT_DISBURSEMENT_REPORT = "merchant_disbursement_report",
27
+ /** Transaction revenue summary (Dashboard) */
28
+ TRANSACTION_REVENUE_SUMMARY = "transaction_revenue_summary",
29
+ /** Customer wallet activity (Afloat) */
30
+ CUSTOMER_WALLET_ACTIVITY = "customer_wallet_activity",
31
+ /** Customer profile information (Afloat) */
32
+ CUSTOMER_PROFILE_SNAPSHOT = "customer_profile_snapshot",
33
+ /** Gateway transaction log (VertoX) */
34
+ GATEWAY_TRANSACTION_LOG = "gateway_transaction_log"
35
+ }
36
+ /**
37
+ * Report definition interface
38
+ */
39
+ export interface ReportDefinition {
40
+ /** Unique identifier for the report */
41
+ id: string;
42
+ /** Human-readable report name for UI display */
43
+ displayName: string;
44
+ /** API endpoint path for the report */
45
+ endpoint: string;
46
+ /** Available file formats for the report */
47
+ availableFormats: FileFormat[];
48
+ /** Optional description of the report */
49
+ description?: string;
50
+ /** Project the report belongs to */
51
+ projectType: ProjectType;
52
+ /** Type of the report */
53
+ reportType: ReportType;
54
+ }
55
+ /**
56
+ * Registry of all available reports
57
+ */
58
+ export declare const REPORTS: {
59
+ merchant_disbursement_report: ReportDefinition;
60
+ transaction_revenue_summary: ReportDefinition;
61
+ customer_wallet_activity: ReportDefinition;
62
+ customer_profile_snapshot: ReportDefinition;
63
+ gateway_transaction_log: ReportDefinition;
64
+ };
65
+ /**
66
+ * Get all reports for a specific project
67
+ * @param projectType The project type to filter by
68
+ * @returns Array of report definitions for the project
69
+ */
70
+ export declare function getReportsByProject(projectType: ProjectType): ReportDefinition[];
71
+ /**
72
+ * Get a report by its type
73
+ * @param reportType The report type to retrieve
74
+ * @returns The report definition or undefined if not found
75
+ */
76
+ export declare function getReportByType(reportType: ReportType): ReportDefinition;
77
+ /**
78
+ * Validates if a report type is available for a project
79
+ * @param projectType The project type
80
+ * @param reportType The report type
81
+ * @returns True if the report is available for the project, false otherwise
82
+ */
83
+ export declare function isReportAvailableForProject(projectType: ProjectType, reportType: ReportType): boolean;
84
+ /**
85
+ * Report Manager class for handling report downloads
86
+ */
87
+ export declare class ReportManager {
88
+ private static _instance;
89
+ private constructor();
90
+ /**
91
+ * Get the singleton instance of ReportManager
92
+ */
93
+ static get instance(): ReportManager;
94
+ /**
95
+ * Get the base URL for the report API
96
+ * @returns The base URL
97
+ */
98
+ private getBaseURL;
99
+ /**
100
+ * Downloads a report based on project type and report type
101
+ * @param args Arguments for the report download
102
+ * @returns Promise that resolves when download is complete
103
+ */
104
+ downloadReport(args: {
105
+ token: string;
106
+ projectType: ProjectType;
107
+ reportType: ReportType;
108
+ fileFormat: FileFormat;
109
+ query?: Record<string, any>;
110
+ }): Promise<void>;
111
+ /**
112
+ * Process the download
113
+ * @param response The response from the API
114
+ * @param report The report definition
115
+ * @param fileFormat The requested file format
116
+ */
117
+ private processDownload;
118
+ /**
119
+ * Handle error responses from the API
120
+ * @param response The response from the API
121
+ * @throws Error with appropriate message
122
+ */
123
+ private handleErrorResponse;
124
+ /**
125
+ * Generates a default filename based on report and file format
126
+ * @param report The report definition
127
+ * @param fileFormat The requested file format
128
+ * @returns A suitable default filename with proper extension
129
+ */
130
+ private getDefaultFilename;
131
+ /**
132
+ * Extracts the filename from the Content-Disposition header
133
+ * @param contentDisposition The Content-Disposition header value
134
+ * @returns The extracted filename or null if not found
135
+ */
136
+ private extractFilenameFromContentDisposition;
137
+ /**
138
+ * Converts a base64 string to a Blob
139
+ * @param base64 The base64 string
140
+ * @returns A Blob
141
+ */
142
+ private b64toBlob;
143
+ }
144
+ //# sourceMappingURL=report_manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"report_manager.d.ts","sourceRoot":"","sources":["../../../src/src/reports/report_manager.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,oBAAY,UAAU;IACpB,sBAAsB;IACtB,GAAG,QAAQ;IACX,wBAAwB;IACxB,KAAK,UAAU;CAChB;AAED;;GAEG;AACH,oBAAY,WAAW;IACrB,8BAA8B;IAC9B,SAAS,cAAc;IACvB,qBAAqB;IACrB,MAAM,WAAW;IACjB,qBAAqB;IACrB,OAAO,YAAY;CACpB;AAED;;GAEG;AACH,oBAAY,UAAU;IACpB,4CAA4C;IAC5C,4BAA4B,iCAAiC;IAC7D,8CAA8C;IAC9C,2BAA2B,gCAAgC;IAC3D,wCAAwC;IACxC,wBAAwB,6BAA6B;IACrD,4CAA4C;IAC5C,yBAAyB,8BAA8B;IACvD,uCAAuC;IACvC,uBAAuB,4BAA4B;CACpD;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,uCAAuC;IACvC,EAAE,EAAE,MAAM,CAAC;IACX,gDAAgD;IAChD,WAAW,EAAE,MAAM,CAAC;IACpB,uCAAuC;IACvC,QAAQ,EAAE,MAAM,CAAC;IACjB,4CAA4C;IAC5C,gBAAgB,EAAE,UAAU,EAAE,CAAC;IAC/B,yCAAyC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,oCAAoC;IACpC,WAAW,EAAE,WAAW,CAAC;IACzB,yBAAyB;IACzB,UAAU,EAAE,UAAU,CAAC;CACxB;AAED;;GAEG;AACH,eAAO,MAAM,OAAO;kCAUb,gBAAgB;iCAUhB,gBAAgB;8BAWhB,gBAAgB;+BAUhB,gBAAgB;6BAWhB,gBAAgB;CACtB,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,mBAAmB,CACjC,WAAW,EAAE,WAAW,GACvB,gBAAgB,EAAE,CAIpB;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,UAAU,EAAE,UAAU,GAAG,gBAAgB,CAExE;AAED;;;;;GAKG;AACH,wBAAgB,2BAA2B,CACzC,WAAW,EAAE,WAAW,EACxB,UAAU,EAAE,UAAU,GACrB,OAAO,CAGT;AAED;;GAEG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,MAAM,CAAC,SAAS,CAAgB;IAExC,OAAO;IAEP;;OAEG;IACH,WAAkB,QAAQ,kBAEzB;IAED;;;OAGG;IACH,OAAO,CAAC,UAAU,CAOhB;IAEF;;;;OAIG;IACU,cAAc,CAAC,IAAI,EAAE;QAChC,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,EAAE,WAAW,CAAC;QACzB,UAAU,EAAE,UAAU,CAAC;QACvB,UAAU,EAAE,UAAU,CAAC;QAEvB,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAC7B,GAAG,OAAO,CAAC,IAAI,CAAC;IAmFjB;;;;;OAKG;YACW,eAAe;IAqB7B;;;;OAIG;YACW,mBAAmB;IAwBjC;;;;;OAKG;IACH,OAAO,CAAC,kBAAkB;IAe1B;;;;OAIG;IACH,OAAO,CAAC,qCAAqC;IA6B7C;;;;OAIG;IACH,OAAO,CAAC,SAAS,CACyB;CAC3C"}