@updraft-solutions/mcrit-sdk 0.18.7 → 0.19.1

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.
@@ -1,306 +1,173 @@
1
- // Report Status Types
2
- export type ReportStatus = "pending" | "processing" | "completed" | "failed";
1
+ import type { Media } from "../types/models";
3
2
 
4
- // Report Type Enum
5
- export type ReportType =
6
- | "financial"
7
- | "operational"
8
- | "instructor_efficiency"
9
- | "company_development";
3
+ // ─────────────────────────────────────────────────────────────────────────────
4
+ // Company reports (Berichte) — section-document contract.
5
+ // A report is compiled server-side into an ordered list of typed sections;
6
+ // the same JSON drives the PDF and the in-app viewer. Values are raw numbers
7
+ // with a `format`; `label`-format values and every `*Key`/`label`/`title`
8
+ // string are translation keys resolved through `ReportDetail.labels`.
9
+ // ─────────────────────────────────────────────────────────────────────────────
10
10
 
11
- // Granularity Options
12
- export type ReportGranularity =
13
- | "total"
14
- | "yearly"
15
- | "quarterly"
16
- | "monthly"
17
- | "weekly"
18
- | "daily";
11
+ export type ReportStatus = "queued" | "processing" | "completed" | "failed";
19
12
 
20
- // Media Type (matching backend MediaResource)
21
- export interface Media {
22
- type: "media";
23
- id: number;
24
- description?: string;
25
- url: string | null;
26
- mime_type: string;
27
- file_name: string;
28
- size: number;
29
- collection_name: string;
30
- created_at: string;
31
- updated_at: string;
32
- }
33
-
34
- // Media Collection (for reports - only PDF)
35
- export interface ReportMedia {
36
- pdf?: Media | null;
37
- }
13
+ export type ReportType = "financial" | "operations" | "training" | "development";
38
14
 
39
- // Base Report Interface
40
- export interface Report {
41
- id: number;
42
- reportable_type: string;
43
- reportable_id: number;
44
- report_type: ReportType;
45
- parameters: ReportParameters;
46
- data: ReportData;
47
- metadata: ReportMetadata;
48
- status: ReportStatus;
49
- generated_at: string | null;
50
- expires_at: string | null;
51
- created_at: string;
52
- updated_at: string;
53
- media?: ReportMedia;
54
- }
15
+ export type ReportGranularity = "total" | "weekly" | "monthly" | "quarterly" | "yearly";
55
16
 
56
- // Report Parameters
57
- export interface ReportParameters {
58
- start_date?: string | null;
59
- end_date?: string | null;
60
- granularity: ReportGranularity;
61
- }
17
+ export type ReportValueFormat =
18
+ | "number"
19
+ | "currency"
20
+ | "percent"
21
+ | "hours"
22
+ | "date"
23
+ | "text"
24
+ | "label";
62
25
 
63
- // Report Generation Parameters (for API requests)
64
- export interface ReportGenerationParams {
65
- type: ReportType;
66
- start_date?: string | null;
67
- end_date?: string | null;
68
- granularity?: ReportGranularity;
69
- }
26
+ export type ReportChartKind = "line" | "bar" | "horizontal_bar" | "stacked_bar" | "donut";
70
27
 
71
- // Report Metadata
72
- export interface ReportMetadata {
73
- requested_by?: number;
74
- requested_at?: string;
75
- started_at?: string;
76
- completed_at?: string;
77
- duration_seconds?: number;
78
- attempt?: number;
79
- error?: string;
80
- batch?: boolean;
81
- }
28
+ export type ReportCellValue = string | number | null;
82
29
 
83
- // Base structure for period-based data
84
- export interface PeriodData<T> {
85
- summary: T;
86
- by_period?: Record<string, T>;
30
+ export interface ReportComparison {
31
+ current: number | null;
32
+ previous: number | null;
33
+ previous_year: number | null;
34
+ /** Percent delta vs the previous period; null without a usable baseline. */
35
+ delta_previous: number | null;
36
+ delta_previous_year: number | null;
87
37
  }
88
38
 
89
- // Generic Report Data
90
- export type ReportData =
91
- | FinancialReportData
92
- | OperationalReportData
93
- | InstructorEfficiencyReportData
94
- | CompanyDevelopmentReportData;
95
-
96
- // =====================
97
- // Financial Report Types
98
- // =====================
99
-
100
- export interface FinancialReportData {
101
- revenue: PeriodData<RevenueData>;
102
- expenses: PeriodData<ExpenseData>;
103
- invoices: PeriodData<InvoiceData>;
104
- prepaid_packages: PeriodData<PrepaidPackageData>;
105
- summary: PeriodData<FinancialSummaryData>;
39
+ export interface ReportKpi {
40
+ /** Translation key (see `ReportDetail.labels`). */
41
+ label: string;
42
+ value: number | null;
43
+ format: ReportValueFormat;
44
+ comparison: ReportComparison | null;
106
45
  }
107
46
 
108
- export interface RevenueData {
109
- total_gross: number;
110
- total_net: number;
111
- by_type: Record<string, number>;
112
- count?: number;
47
+ export interface ReportKpiGridSection {
48
+ kind: "kpi_grid";
49
+ title: string;
50
+ items: ReportKpi[];
113
51
  }
114
52
 
115
- export interface ExpenseData {
116
- total_gross: number;
117
- total_net: number;
118
- by_category: Record<string, number>;
119
- count?: number;
53
+ export interface ReportColumn {
54
+ key: string;
55
+ label: string;
56
+ format: ReportValueFormat;
57
+ align: "left" | "right";
120
58
  }
121
59
 
122
- export interface InvoiceData {
123
- total_count: number;
124
- total_gross: number;
125
- by_status: Record<string, number>;
126
- by_paid_status: Record<string, number>;
60
+ export interface ReportDataTableSection {
61
+ kind: "data_table";
62
+ title: string;
63
+ columns: ReportColumn[];
64
+ rows: Record<string, ReportCellValue>[];
65
+ totals: Record<string, ReportCellValue> | null;
66
+ /** Translation key shown when `rows` is empty. */
67
+ empty: string | null;
127
68
  }
128
69
 
129
- export interface PrepaidPackageData {
130
- total_packages: number;
131
- total_initial_value: number;
132
- total_remaining_value: number;
133
- total_used_value: number;
134
- usage_percentage: number;
70
+ export interface ReportSeries {
71
+ label: string;
72
+ data: (number | null)[];
135
73
  }
136
74
 
137
- export interface FinancialSummaryData {
138
- total_revenue: number;
139
- total_expenses: number;
140
- profit: number;
141
- profit_margin: number;
75
+ export interface ReportChartSection {
76
+ kind: "chart";
77
+ title: string;
78
+ chart: ReportChartKind;
79
+ /** Axis labels, or slice labels for a donut; may be translation keys. */
80
+ categories: string[];
81
+ series: ReportSeries[];
82
+ format: ReportValueFormat;
142
83
  }
143
84
 
144
- // =====================
145
- // Operational Report Types
146
- // =====================
147
-
148
- export interface OperationalReportData {
149
- flight_hours: FlightHoursData;
150
- bookings: BookingsData;
151
- landings: LandingsData;
152
- aircraft_utilization: AircraftUtilization[];
153
- member_activity: MemberActivityData;
85
+ export interface ReportCalloutSection {
86
+ kind: "callout";
87
+ text: string;
88
+ params: Record<string, string | number | boolean>;
89
+ tone: "info" | "warning";
154
90
  }
155
91
 
156
- export interface FlightHoursData {
157
- total_hours: number;
158
- total_flights: number;
159
- average_flight_hours: number;
160
- by_month?: Record<string, number>;
161
- by_period?: Record<
162
- string,
163
- {
164
- hours: number;
165
- flights: number;
166
- average: number;
167
- }
168
- >;
169
- }
92
+ export type ReportSection =
93
+ | ReportKpiGridSection
94
+ | ReportDataTableSection
95
+ | ReportChartSection
96
+ | ReportCalloutSection;
170
97
 
171
- export interface BookingsData {
172
- total_bookings: number;
173
- completion_rate: number;
174
- average_efficiency: number;
175
- by_status: Record<string, number>;
176
- by_period?: Record<
177
- string,
178
- {
179
- total: number;
180
- completed: number;
181
- cancelled: number;
182
- }
183
- >;
98
+ export interface ReportParameters {
99
+ /** Local calendar date (Y-m-d) in `timezone`. */
100
+ start_date: string;
101
+ end_date: string;
102
+ granularity: ReportGranularity;
103
+ timezone: string;
184
104
  }
185
105
 
186
- export interface LandingsData {
187
- total_landings: number;
188
- full_stop_landings: number;
189
- touch_and_gos: number;
190
- top_airports: Array<{
191
- airport_code: string;
192
- airport_name: string;
193
- count: number;
194
- }>;
106
+ export interface ReportDocument {
107
+ version: number;
108
+ type: ReportType;
109
+ company_id: number;
110
+ period: ReportParameters;
111
+ locale: string;
112
+ sections: ReportSection[];
195
113
  }
196
114
 
197
- export interface AircraftUtilization {
198
- aircraft_id: number;
199
- aircraft_registration: string;
200
- aircraft_name: string;
201
- total_hours: number;
202
- total_bookings: number;
203
- utilization_rate: number;
115
+ export interface ReportRequester {
116
+ id: number;
117
+ name: string;
204
118
  }
205
119
 
206
- export interface MemberActivityData {
207
- top_pilots: Array<{
208
- member_id: number;
209
- member_name: string;
210
- flight_hours: number;
211
- booking_count: number;
212
- }>;
213
- total_active_members: number;
120
+ /** Identity tier — what the list shows; never carries the section document. */
121
+ export interface Report {
122
+ type: "report";
123
+ id: number;
124
+ report_type: ReportType;
125
+ status: ReportStatus;
126
+ parameters: ReportParameters;
127
+ locale: string;
128
+ error: string | null;
129
+ generated_at: string | null;
130
+ created_at: string | null;
131
+ requested_by?: ReportRequester | null;
132
+ background_task_uuid?: string | null;
133
+ media?: { pdf: Media | null };
134
+ can?: Record<string, boolean | null>;
214
135
  }
215
136
 
216
- // =====================
217
- // Instructor Efficiency Report Types
218
- // =====================
219
-
220
- export interface InstructorEfficiencyReportData {
221
- instructors: InstructorData[];
222
- summary: InstructorSummaryData;
223
- period: {
224
- start_date: string;
225
- end_date: string;
226
- };
137
+ export interface ReportDetail extends Report {
138
+ data: ReportDocument | null;
139
+ /** Translation key → text in the report's locale, for every key the document uses. */
140
+ labels: Record<string, string>;
227
141
  }
228
142
 
229
- export interface InstructorData {
230
- instructor_id: number;
231
- instructor_name: string;
232
- instructor_email: string;
233
- total_bookings: number;
234
- average_efficiency: number;
235
- average_delay_minutes: number;
236
- total_flight_hours: number;
237
- bookings_with_efficiency: number;
238
- by_period?: Record<
239
- string,
240
- {
241
- bookings: number;
242
- efficiency: number;
243
- delay: number;
244
- hours: number;
245
- }
246
- >;
143
+ export interface ReportTypeMeta {
144
+ type: ReportType;
145
+ title: string;
146
+ description: string;
247
147
  }
248
148
 
249
- export interface InstructorSummaryData {
250
- total_instructors: number;
251
- average_efficiency_overall: number;
252
- average_delay_overall: number;
253
- total_bookings_overall: number;
254
- total_flight_hours_overall: number;
255
- best_performer: {
256
- name: string;
257
- efficiency: number;
258
- };
149
+ export interface ReportGranularityMeta {
150
+ value: ReportGranularity;
151
+ label: string;
259
152
  }
260
153
 
261
- // =====================
262
- // Company Development Report Types
263
- // =====================
264
-
265
- export interface CompanyDevelopmentReportData {
266
- summary?: Record<string, any>;
267
- metrics?: Record<string, any>;
268
- by_period?: Record<string, any>;
154
+ /** `GET companies/{company}/meta/reports` */
155
+ export interface ReportMeta {
156
+ types: ReportTypeMeta[];
157
+ granularities: ReportGranularityMeta[];
158
+ max_buckets: number;
269
159
  }
270
160
 
271
- // =====================
272
- // Helper Types
273
- // =====================
274
-
275
- // Report list item for display in tables/lists
276
- export interface ReportListItem {
277
- id: number;
161
+ /** `POST companies/{company}/reports` */
162
+ export interface StoreReportInput {
278
163
  type: ReportType;
279
- status: ReportStatus;
280
- created_at: string;
281
- generated_at: string | null;
282
- parameters: ReportParameters;
164
+ start_date: string;
165
+ end_date: string;
166
+ granularity?: ReportGranularity;
283
167
  }
284
168
 
285
- // Report generation response
286
- export interface ReportGenerationResponse {
169
+ /** 409 body when an identical report is already queued or processing. */
170
+ export interface ReportConflictResponse {
287
171
  message: string;
288
- data?: Report | Report[];
289
- skipped?: Array<{
290
- type: ReportType;
291
- message: string;
292
- report: Report;
293
- }>;
294
- }
295
-
296
- // Report status response
297
- export interface ReportStatusResponse {
298
- data: {
299
- id: number;
300
- status: ReportStatus;
301
- report_type: ReportType;
302
- created_at: string;
303
- generated_at: string | null;
304
- metadata: ReportMetadata;
305
- };
172
+ data: Report;
306
173
  }