@mydoormot/app-types 1.9.1 → 1.9.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.
@@ -1,18 +1,18 @@
1
-
2
- > @mydoormot/app-types@1.9.0 build /Users/chuksben/Desktop/projects/microservices/mydoormot/packages/app-types
3
- > tsup src/index.ts --format esm,cjs --dts
4
-
5
- CLI Building entry: src/index.ts
6
- CLI Using tsconfig: tsconfig.json
7
- CLI tsup v7.3.0
8
- CLI Target: es2021
9
- ESM Build start
10
- CJS Build start
11
- DTS Build start
12
- CJS dist/index.cjs 15.79 KB
13
- CJS ⚡️ Build success in 301ms
14
- ESM dist/index.js 13.19 KB
15
- ESM ⚡️ Build success in 301ms
16
- DTS ⚡️ Build success in 931ms
17
- DTS dist/index.d.ts 40.67 KB
18
- DTS dist/index.d.cts 40.67 KB
1
+
2
+ > @mydoormot/app-types@1.9.2 build /Users/chuksben/Desktop/projects/microservices/mydoormot/packages/app-types
3
+ > tsup src/index.ts --format esm,cjs --dts
4
+
5
+ CLI Building entry: src/index.ts
6
+ CLI Using tsconfig: tsconfig.json
7
+ CLI tsup v7.3.0
8
+ CLI Target: es2021
9
+ ESM Build start
10
+ CJS Build start
11
+ CJS dist/index.cjs 16.39 KB
12
+ CJS ⚡️ Build success in 42ms
13
+ ESM dist/index.js 13.63 KB
14
+ ESM ⚡️ Build success in 43ms
15
+ DTS Build start
16
+ DTS ⚡️ Build success in 668ms
17
+ DTS dist/index.d.ts 46.03 KB
18
+ DTS dist/index.d.cts 46.03 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @mydoormot/app-types
2
2
 
3
+ ## 1.9.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Modified invoice types
8
+
9
+ ## 1.9.2
10
+
11
+ ### Patch Changes
12
+
13
+ - Modified transactions
14
+
3
15
  ## 1.9.1
4
16
 
5
17
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -26,14 +26,17 @@ __export(src_exports, {
26
26
  BusinessCourierLinkStatus: () => BusinessCourierLinkStatus,
27
27
  BusinessRole: () => BusinessRole,
28
28
  BusinessStatus: () => BusinessStatus,
29
+ DEFAULT_BUSINESS_FUEL_SETTINGS: () => DEFAULT_BUSINESS_FUEL_SETTINGS,
29
30
  DEFAULT_BUSINESS_MODULES: () => DEFAULT_BUSINESS_MODULES,
30
31
  DEFAULT_BUSINESS_SETTINGS: () => DEFAULT_BUSINESS_SETTINGS,
31
32
  DeliveryStatus: () => DeliveryStatus,
32
33
  DraftErrandStatus: () => DraftErrandStatus,
33
34
  EnterpriseType: () => EnterpriseType,
35
+ ErrandInvoiceState: () => ErrandInvoiceState,
34
36
  ErrandStatus: () => ErrandStatus,
35
37
  FeePaymentStatus: () => FeePaymentStatus,
36
38
  FeeSettlement: () => FeeSettlement,
39
+ FuelDueStatus: () => FuelDueStatus,
37
40
  GlobalRoles: () => GlobalRoles,
38
41
  InvoiceEventType: () => InvoiceEventType,
39
42
  InvoiceGenerationType: () => InvoiceGenerationType,
@@ -141,6 +144,12 @@ var FeeSettlement = /* @__PURE__ */ ((FeeSettlement2) => {
141
144
  FeeSettlement2["Owed"] = "owed";
142
145
  return FeeSettlement2;
143
146
  })(FeeSettlement || {});
147
+ var ErrandInvoiceState = /* @__PURE__ */ ((ErrandInvoiceState2) => {
148
+ ErrandInvoiceState2["Unbilled"] = "unbilled";
149
+ ErrandInvoiceState2["Invoiced"] = "invoiced";
150
+ ErrandInvoiceState2["Excluded"] = "excluded";
151
+ return ErrandInvoiceState2;
152
+ })(ErrandInvoiceState || {});
144
153
  var AddressTypes = /* @__PURE__ */ ((AddressTypes2) => {
145
154
  AddressTypes2["DeliveryAddress"] = "deliveryAddress";
146
155
  AddressTypes2["PickupAddress"] = "pickupAddress";
@@ -209,16 +218,13 @@ var InvoiceEventType = /* @__PURE__ */ ((InvoiceEventType2) => {
209
218
  InvoiceEventType2["PaymentRecorded"] = "payment_recorded";
210
219
  InvoiceEventType2["PaymentReversed"] = "payment_reversed";
211
220
  InvoiceEventType2["StatusChanged"] = "status_changed";
212
- InvoiceEventType2["LinkCreated"] = "link_created";
213
- InvoiceEventType2["LinkRevoked"] = "link_revoked";
221
+ InvoiceEventType2["Shared"] = "shared";
214
222
  InvoiceEventType2["Viewed"] = "viewed";
215
223
  return InvoiceEventType2;
216
224
  })(InvoiceEventType || {});
217
225
  var SweepExclusionReason = /* @__PURE__ */ ((SweepExclusionReason2) => {
218
226
  SweepExclusionReason2["Cancelled"] = "cancelled";
219
227
  SweepExclusionReason2["AlreadyInvoiced"] = "already_invoiced";
220
- SweepExclusionReason2["SettledCash"] = "settled_cash";
221
- SweepExclusionReason2["Prepaid"] = "prepaid";
222
228
  SweepExclusionReason2["Owed"] = "owed";
223
229
  SweepExclusionReason2["NotInvoiceable"] = "not_invoiceable";
224
230
  return SweepExclusionReason2;
@@ -243,6 +249,11 @@ var VehicleLogType = /* @__PURE__ */ ((VehicleLogType2) => {
243
249
  VehicleLogType2["REFUEL"] = "REFUEL";
244
250
  return VehicleLogType2;
245
251
  })(VehicleLogType || {});
252
+ var FuelDueStatus = /* @__PURE__ */ ((FuelDueStatus2) => {
253
+ FuelDueStatus2["Due"] = "DUE";
254
+ FuelDueStatus2["Ok"] = "OK";
255
+ return FuelDueStatus2;
256
+ })(FuelDueStatus || {});
246
257
 
247
258
  // src/rider.ts
248
259
  var RemittanceStatus = /* @__PURE__ */ ((RemittanceStatus2) => {
@@ -284,6 +295,9 @@ var MembershipStatus = /* @__PURE__ */ ((MembershipStatus2) => {
284
295
  MembershipStatus2["SUSPENDED"] = "SUSPENDED";
285
296
  return MembershipStatus2;
286
297
  })(MembershipStatus || {});
298
+ var DEFAULT_BUSINESS_FUEL_SETTINGS = {
299
+ revenuePercent: null
300
+ };
287
301
  var DEFAULT_BUSINESS_MODULES = {
288
302
  draftErrands: true,
289
303
  team: true,
@@ -315,7 +329,8 @@ var DEFAULT_BUSINESS_SETTINGS = {
315
329
  tiktok: null,
316
330
  website: null
317
331
  },
318
- modules: DEFAULT_BUSINESS_MODULES
332
+ modules: DEFAULT_BUSINESS_MODULES,
333
+ fuel: DEFAULT_BUSINESS_FUEL_SETTINGS
319
334
  };
320
335
  var BusinessCourierLinkStatus = /* @__PURE__ */ ((BusinessCourierLinkStatus2) => {
321
336
  BusinessCourierLinkStatus2["ACTIVE"] = "active";
@@ -393,14 +408,17 @@ var LinkDestination = /* @__PURE__ */ ((LinkDestination2) => {
393
408
  BusinessCourierLinkStatus,
394
409
  BusinessRole,
395
410
  BusinessStatus,
411
+ DEFAULT_BUSINESS_FUEL_SETTINGS,
396
412
  DEFAULT_BUSINESS_MODULES,
397
413
  DEFAULT_BUSINESS_SETTINGS,
398
414
  DeliveryStatus,
399
415
  DraftErrandStatus,
400
416
  EnterpriseType,
417
+ ErrandInvoiceState,
401
418
  ErrandStatus,
402
419
  FeePaymentStatus,
403
420
  FeeSettlement,
421
+ FuelDueStatus,
404
422
  GlobalRoles,
405
423
  InvoiceEventType,
406
424
  InvoiceGenerationType,
package/dist/index.d.cts CHANGED
@@ -138,7 +138,13 @@ interface Customer {
138
138
  * earliest member.
139
139
  */
140
140
  interface CustomerBilling {
141
+ /**
142
+ * What is still owed on work that has not reached a statement — net of
143
+ * anything already paid on those errands, which is why it can be smaller than
144
+ * the sum of their prices.
145
+ */
141
146
  unbilledAmount: number;
147
+ /** How many errands are not on a statement yet, paid ones included. */
142
148
  unbilledCount: number;
143
149
  oldestUnbilledAt: string | null;
144
150
  outstandingAmount: number;
@@ -191,16 +197,13 @@ declare enum InvoiceEventType {
191
197
  PaymentRecorded = "payment_recorded",
192
198
  PaymentReversed = "payment_reversed",
193
199
  StatusChanged = "status_changed",
194
- LinkCreated = "link_created",
195
- LinkRevoked = "link_revoked",
200
+ Shared = "shared",
196
201
  Viewed = "viewed"
197
202
  }
198
203
  /** Why an errand in the period was not charged on the statement. */
199
204
  declare enum SweepExclusionReason {
200
205
  Cancelled = "cancelled",
201
206
  AlreadyInvoiced = "already_invoiced",
202
- SettledCash = "settled_cash",
203
- Prepaid = "prepaid",
204
207
  Owed = "owed",
205
208
  NotInvoiceable = "not_invoiceable"
206
209
  }
@@ -234,17 +237,11 @@ interface InvoiceEvent {
234
237
  meta?: Record<string, unknown>;
235
238
  createdAt: string;
236
239
  }
237
- interface InvoiceStatementLink {
238
- id: string;
239
- invoiceId: string;
240
- businessId: string;
241
- token: string;
242
- expiresAt: string;
243
- revokedAt?: string;
244
- viewCount: number;
245
- firstViewedAt?: string;
246
- lastViewedAt?: string;
247
- createdAt: string;
240
+ /** What `POST /invoices/:invoiceId/statement-link` returns. */
241
+ interface SharedStatement {
242
+ /** The slug in the public statement URL. Stable for the invoice's lifetime. */
243
+ statementSlug: string;
244
+ sentAt?: string;
248
245
  }
249
246
  /** Whether a frozen invoice has fallen out of date, and by how much. */
250
247
  interface InvoiceDrift {
@@ -256,6 +253,12 @@ interface Invoice {
256
253
  businessId: string;
257
254
  userId: string;
258
255
  invoiceNumber: string;
256
+ /**
257
+ * Slug for the public statement URL, and the only credential guarding it.
258
+ * Written at freeze time, so every invoice is shareable immediately. Absent on
259
+ * invoices frozen before the field existed.
260
+ */
261
+ statementSlug?: string;
259
262
  startDate: string;
260
263
  endDate: string;
261
264
  /** What the customer is asked for. Excludes zero-rated lines. */
@@ -294,9 +297,17 @@ interface InvoiceItem {
294
297
  itemId: string;
295
298
  /** Contribution to the invoice total. Zero for a settled line. */
296
299
  amount: number;
297
- /** Shown but not charged — work the customer already paid for in cash. */
300
+ /**
301
+ * Shown but not charged — work whose fee the customer already settled, either
302
+ * in cash at the door or prepaid before dispatch.
303
+ */
298
304
  zeroRated?: boolean;
299
- settledBy?: 'cash';
305
+ /**
306
+ * Which already-settled route a zero-rated line took. Unset on a charged line.
307
+ * The invoice's `zeroRatedTotal` is one number for the period; sum lines by
308
+ * this field for the "paid at the door" / "paid in advance" split.
309
+ */
310
+ settledBy?: 'cash' | 'prepaid';
300
311
  /** What the work was worth, on a zero-rated line only. */
301
312
  originalAmount?: number;
302
313
  description: string;
@@ -332,6 +343,12 @@ interface Business {
332
343
  registrationCompleted: boolean | NullOrUndefined;
333
344
  stateId: string | NullOrUndefined;
334
345
  cityId: string | NullOrUndefined;
346
+ /**
347
+ * IANA zone the business's own calendar runs on — the clock its reports are cut
348
+ * against, so a 23:30 errand lands on the day the operator worked it rather than
349
+ * on whatever day it was in UTC. Unset means the platform default, Africa/Lagos.
350
+ */
351
+ timezone: string | NullOrUndefined;
335
352
  originalLogoUrl: string | NullOrUndefined;
336
353
  logoUrl: string | NullOrUndefined;
337
354
  logoBlurHash: string | NullOrUndefined;
@@ -391,6 +408,15 @@ interface BusinessModules {
391
408
  invoices: boolean;
392
409
  remittances: boolean;
393
410
  }
411
+ /**
412
+ * How a business funds fuel. `revenuePercent` is the share of errand revenue a
413
+ * vehicle sets aside for its own fuel — the single knob behind the fuel-owed
414
+ * balance. `null` (the default) means the business hasn't configured it and the
415
+ * balance is not computed at all.
416
+ */
417
+ interface BusinessFuelSettings {
418
+ revenuePercent: number | null;
419
+ }
394
420
  interface BusinessSettings {
395
421
  whatsapp_notification_enabled: boolean;
396
422
  whatsapp: BusinessWhatsappConfig;
@@ -417,7 +443,9 @@ interface BusinessSettings {
417
443
  maxErrands: number | null;
418
444
  };
419
445
  modules: BusinessModules;
446
+ fuel?: BusinessFuelSettings;
420
447
  }
448
+ declare const DEFAULT_BUSINESS_FUEL_SETTINGS: BusinessFuelSettings;
421
449
  declare const DEFAULT_BUSINESS_MODULES: BusinessModules;
422
450
  declare const DEFAULT_BUSINESS_SETTINGS: BusinessSettings;
423
451
  interface BusinessMember {
@@ -578,6 +606,95 @@ interface VehiclePerformanceData {
578
606
  totals: VehiclePerformanceTotals;
579
607
  filters: VehiclePerformanceFilters;
580
608
  }
609
+ declare enum FuelDueStatus {
610
+ /** Worked through the fuel it was last given. Fuel this one. */
611
+ Due = "DUE",
612
+ /** Still running on fuel already paid for. Leave it. */
613
+ Ok = "OK"
614
+ }
615
+ /** What the vehicle has done since the fuel it was last given. */
616
+ interface FuelSinceLastRefuel {
617
+ revenue: number;
618
+ errandCount: number;
619
+ fuelEarned: number;
620
+ }
621
+ interface FuelDueItem {
622
+ vehicleId: string;
623
+ vehicleNumber: string;
624
+ shortName: string | null;
625
+ vehicleType: VehicleType | `${VehicleType}`;
626
+ /**
627
+ * The fuel gauge, and the field to lead a UI with: how much of the fuel this
628
+ * vehicle was last given it has worked through. 0 is freshly filled, 100 is
629
+ * due, past 100 is overdue. Null when it has never been fuelled.
630
+ */
631
+ fuelUsedPercent: number | null;
632
+ /** `fuelEarned - fuelSpent`, in naira — how much to give, not whether to. */
633
+ fuelDue: number;
634
+ fuelEarned: number;
635
+ fuelSpent: number;
636
+ revenue: number;
637
+ errandCount: number;
638
+ refuelCount: number;
639
+ /** What this vehicle is typically fuelled with; null if never fuelled. */
640
+ averageRefuelCost: number | null;
641
+ /**
642
+ * The figure has drifted far past what this vehicle is ever fuelled with —
643
+ * the signature of a wrong `revenuePercent` compounding rather than a real
644
+ * fuel need. Prompt to check the percentage instead of showing the figure.
645
+ */
646
+ needsCalibration: boolean;
647
+ lastRefuel: {
648
+ at: string;
649
+ cost: number;
650
+ } | null;
651
+ sinceLastRefuel: FuelSinceLastRefuel | null;
652
+ dueStatus: FuelDueStatus | `${FuelDueStatus}`;
653
+ /** Counting starts here when the prediction has been reset; null otherwise. */
654
+ countingFrom: string | null;
655
+ }
656
+ interface FuelDueTotals {
657
+ totalDue: number;
658
+ totalEarned: number;
659
+ totalSpent: number;
660
+ vehiclesDue: number;
661
+ vehiclesNeedingCalibration: number;
662
+ }
663
+ interface FuelDueData {
664
+ /** False when the business has not set `settings.fuel.revenuePercent`. */
665
+ configured: boolean;
666
+ revenuePercent: number | null;
667
+ /** Only when `configured` is false: what history says the percent should be. */
668
+ suggestedPercent?: number | null;
669
+ vehicles: FuelDueItem[];
670
+ totals: FuelDueTotals;
671
+ }
672
+ type FuelSuggestionConfidence = 'low' | 'medium' | 'high';
673
+ interface FuelPercentSuggestion {
674
+ /**
675
+ * Fuel spend as a share of the revenue that earned it, to one decimal —
676
+ * the percentage this business has actually been running at. Null when
677
+ * there is too little history; `reason` says which.
678
+ */
679
+ suggestedPercent: number | null;
680
+ /**
681
+ * Read off the number of refuels behind the suggestion, not the length of
682
+ * the window. Fuel bought near a window's edge is burnt outside it, so a
683
+ * thin refuel count gives a volatile ratio however many days were read.
684
+ */
685
+ confidence: FuelSuggestionConfidence;
686
+ reason: string | null;
687
+ days: number;
688
+ basedOn: {
689
+ totalFuelCost: number;
690
+ totalRevenue: number;
691
+ refuelCount: number;
692
+ errandCount: number;
693
+ refuelledVehicles: number;
694
+ /** Refuels per vehicle — what says whether the ratio has settled. */
695
+ refuelsPerVehicle: number | null;
696
+ };
697
+ }
581
698
 
582
699
  type Rider = {
583
700
  id: string;
@@ -726,6 +843,11 @@ declare enum FeeSettlement {
726
843
  Invoice = "invoice",
727
844
  Owed = "owed"
728
845
  }
846
+ declare enum ErrandInvoiceState {
847
+ Unbilled = "unbilled",
848
+ Invoiced = "invoiced",
849
+ Excluded = "excluded"
850
+ }
729
851
  type ExpensePaidBy = 'rider' | 'company' | 'customer';
730
852
  interface Errand {
731
853
  id: string;
@@ -1181,6 +1303,12 @@ interface TransactionItem {
1181
1303
  variantId?: string;
1182
1304
  isAddon?: boolean;
1183
1305
  }
1306
+ /**
1307
+ * Rider user attached to a transaction — the same `riderUserDetails` field the
1308
+ * errand types carry, narrowed to what the UI needs to label an expense with
1309
+ * its rider. Derived from User so it can't drift from the canonical shape.
1310
+ */
1311
+ type TransactionRiderUser = Pick<User, 'id' | 'firstName' | 'lastName' | 'mobileNumber' | 'avatarUrl'>;
1184
1312
  interface Transaction {
1185
1313
  id: string;
1186
1314
  type: TransactionType;
@@ -1194,6 +1322,7 @@ interface Transaction {
1194
1322
  categoryId?: string;
1195
1323
  customerId?: string;
1196
1324
  riderId?: string;
1325
+ riderUserDetails?: TransactionRiderUser | null;
1197
1326
  items?: TransactionItem[];
1198
1327
  customerDetails?: Customer;
1199
1328
  }
@@ -1477,4 +1606,4 @@ declare enum LinkDestination {
1477
1606
  }
1478
1607
  type NullOrUndefined = null | undefined;
1479
1608
 
1480
- export { type AddonGroup, type AddonGroupItem, type AddressDetails, AddressTypes, type AggregatedErrand, AuthType, type Business, BusinessCapability, type BusinessCategory, type BusinessCourierLink, BusinessCourierLinkStatus, type BusinessMember, type BusinessModules, type BusinessPg, type BusinessPortal, BusinessRole, type BusinessSettings, BusinessStatus, type BusinessWhatsappConfig, type City, type Collection, type Customer, type CustomerAddress, type CustomerBilling, type CustomerTransactionStats, DEFAULT_BUSINESS_MODULES, DEFAULT_BUSINESS_SETTINGS, DeliveryStatus, type DraftErrand, DraftErrandStatus, type Enterprise, type EnterpriseCategoryDoc, type EnterpriseSubCategoryDoc, EnterpriseType, type Errand, type ErrandDeliveryTiming, type ErrandPackagingQuality, type ErrandRating, type ErrandReview, type ErrandReviewLink, type ErrandRiderBehavior, ErrandStatus, type ErrandTimeline, type ExpensePaidBy, FeePaymentStatus, FeeSettlement, type GeoPoint, GlobalRoles, type Invoice, type InvoiceDrift, type InvoiceEvent, InvoiceEventType, InvoiceGenerationType, type InvoiceItem, InvoiceItemType, type InvoicePayment, InvoicePaymentMethod, type InvoiceStatementLink, InvoiceStatus, type LatLng, LinkDestination, type MaintenanceItem, type MaintenancePartUsage, type MaintenanceRecord, type MaintenanceStats, type MaintenanceStatsSummary, type MaintenanceTopItem, MembershipStatus, type Notification, type NotificationData, NotificationType, type NullOrUndefined, type OpeningHours, type PaginateResult, ParcelSize, PaymentOptions, type PendingErrand, type PortalHandleAvailability, PortalStatus, type Product, type ProductCategory, type ProductImage, type ProductOption, type ProductOptionValue, type ProductStatus, type ProductTag, type ProductVariant, type ProductVariantPrice, type PublicPortal, type PublicPortalBusiness, RemittanceStatus, type Rider, type RiderPerformanceItem, type RiderPerformanceStats, type RiderPerformanceSummary, type RiderPerformanceTimeSeries, type RiderSettlement, type RiderWithUserDetails, RoleType, type State, SweepExclusionReason, type TrackerPosition, type Transaction, type TransactionCategory, type TransactionItem, type TransactionType, type TransactionWithCategory, type TransactionWithJoin, type User, type UserAddress, type Vehicle, type VehicleErrandStats, type VehicleFuelStats, type VehicleLog, type VehicleLogStatsSummary, VehicleLogType, type VehicleLogWithErrands, type VehicleMaintenanceStats, type VehiclePerformanceData, type VehiclePerformanceFilters, type VehiclePerformanceItem, type VehiclePerformanceTotals, VehicleType, type VehicleWithRider, type Vendor, WhatsappButtonType, WhatsappComponentType, WhatsappEvent, WhatsappRecipient, type WhatsappSendLog, type WhatsappTemplate, type WhatsappTemplateButton, type WhatsappTemplateComponent, WhatsappTemplateMetaStatus, WhatsappTemplateParamSource, type WhatsappTemplateSource, errandTimeline };
1609
+ export { type AddonGroup, type AddonGroupItem, type AddressDetails, AddressTypes, type AggregatedErrand, AuthType, type Business, BusinessCapability, type BusinessCategory, type BusinessCourierLink, BusinessCourierLinkStatus, type BusinessFuelSettings, type BusinessMember, type BusinessModules, type BusinessPg, type BusinessPortal, BusinessRole, type BusinessSettings, BusinessStatus, type BusinessWhatsappConfig, type City, type Collection, type Customer, type CustomerAddress, type CustomerBilling, type CustomerTransactionStats, DEFAULT_BUSINESS_FUEL_SETTINGS, DEFAULT_BUSINESS_MODULES, DEFAULT_BUSINESS_SETTINGS, DeliveryStatus, type DraftErrand, DraftErrandStatus, type Enterprise, type EnterpriseCategoryDoc, type EnterpriseSubCategoryDoc, EnterpriseType, type Errand, type ErrandDeliveryTiming, ErrandInvoiceState, type ErrandPackagingQuality, type ErrandRating, type ErrandReview, type ErrandReviewLink, type ErrandRiderBehavior, ErrandStatus, type ErrandTimeline, type ExpensePaidBy, FeePaymentStatus, FeeSettlement, type FuelDueData, type FuelDueItem, FuelDueStatus, type FuelDueTotals, type FuelPercentSuggestion, type FuelSinceLastRefuel, type FuelSuggestionConfidence, type GeoPoint, GlobalRoles, type Invoice, type InvoiceDrift, type InvoiceEvent, InvoiceEventType, InvoiceGenerationType, type InvoiceItem, InvoiceItemType, type InvoicePayment, InvoicePaymentMethod, InvoiceStatus, type LatLng, LinkDestination, type MaintenanceItem, type MaintenancePartUsage, type MaintenanceRecord, type MaintenanceStats, type MaintenanceStatsSummary, type MaintenanceTopItem, MembershipStatus, type Notification, type NotificationData, NotificationType, type NullOrUndefined, type OpeningHours, type PaginateResult, ParcelSize, PaymentOptions, type PendingErrand, type PortalHandleAvailability, PortalStatus, type Product, type ProductCategory, type ProductImage, type ProductOption, type ProductOptionValue, type ProductStatus, type ProductTag, type ProductVariant, type ProductVariantPrice, type PublicPortal, type PublicPortalBusiness, RemittanceStatus, type Rider, type RiderPerformanceItem, type RiderPerformanceStats, type RiderPerformanceSummary, type RiderPerformanceTimeSeries, type RiderSettlement, type RiderWithUserDetails, RoleType, type SharedStatement, type State, SweepExclusionReason, type TrackerPosition, type Transaction, type TransactionCategory, type TransactionItem, type TransactionRiderUser, type TransactionType, type TransactionWithCategory, type TransactionWithJoin, type User, type UserAddress, type Vehicle, type VehicleErrandStats, type VehicleFuelStats, type VehicleLog, type VehicleLogStatsSummary, VehicleLogType, type VehicleLogWithErrands, type VehicleMaintenanceStats, type VehiclePerformanceData, type VehiclePerformanceFilters, type VehiclePerformanceItem, type VehiclePerformanceTotals, VehicleType, type VehicleWithRider, type Vendor, WhatsappButtonType, WhatsappComponentType, WhatsappEvent, WhatsappRecipient, type WhatsappSendLog, type WhatsappTemplate, type WhatsappTemplateButton, type WhatsappTemplateComponent, WhatsappTemplateMetaStatus, WhatsappTemplateParamSource, type WhatsappTemplateSource, errandTimeline };
package/dist/index.d.ts CHANGED
@@ -138,7 +138,13 @@ interface Customer {
138
138
  * earliest member.
139
139
  */
140
140
  interface CustomerBilling {
141
+ /**
142
+ * What is still owed on work that has not reached a statement — net of
143
+ * anything already paid on those errands, which is why it can be smaller than
144
+ * the sum of their prices.
145
+ */
141
146
  unbilledAmount: number;
147
+ /** How many errands are not on a statement yet, paid ones included. */
142
148
  unbilledCount: number;
143
149
  oldestUnbilledAt: string | null;
144
150
  outstandingAmount: number;
@@ -191,16 +197,13 @@ declare enum InvoiceEventType {
191
197
  PaymentRecorded = "payment_recorded",
192
198
  PaymentReversed = "payment_reversed",
193
199
  StatusChanged = "status_changed",
194
- LinkCreated = "link_created",
195
- LinkRevoked = "link_revoked",
200
+ Shared = "shared",
196
201
  Viewed = "viewed"
197
202
  }
198
203
  /** Why an errand in the period was not charged on the statement. */
199
204
  declare enum SweepExclusionReason {
200
205
  Cancelled = "cancelled",
201
206
  AlreadyInvoiced = "already_invoiced",
202
- SettledCash = "settled_cash",
203
- Prepaid = "prepaid",
204
207
  Owed = "owed",
205
208
  NotInvoiceable = "not_invoiceable"
206
209
  }
@@ -234,17 +237,11 @@ interface InvoiceEvent {
234
237
  meta?: Record<string, unknown>;
235
238
  createdAt: string;
236
239
  }
237
- interface InvoiceStatementLink {
238
- id: string;
239
- invoiceId: string;
240
- businessId: string;
241
- token: string;
242
- expiresAt: string;
243
- revokedAt?: string;
244
- viewCount: number;
245
- firstViewedAt?: string;
246
- lastViewedAt?: string;
247
- createdAt: string;
240
+ /** What `POST /invoices/:invoiceId/statement-link` returns. */
241
+ interface SharedStatement {
242
+ /** The slug in the public statement URL. Stable for the invoice's lifetime. */
243
+ statementSlug: string;
244
+ sentAt?: string;
248
245
  }
249
246
  /** Whether a frozen invoice has fallen out of date, and by how much. */
250
247
  interface InvoiceDrift {
@@ -256,6 +253,12 @@ interface Invoice {
256
253
  businessId: string;
257
254
  userId: string;
258
255
  invoiceNumber: string;
256
+ /**
257
+ * Slug for the public statement URL, and the only credential guarding it.
258
+ * Written at freeze time, so every invoice is shareable immediately. Absent on
259
+ * invoices frozen before the field existed.
260
+ */
261
+ statementSlug?: string;
259
262
  startDate: string;
260
263
  endDate: string;
261
264
  /** What the customer is asked for. Excludes zero-rated lines. */
@@ -294,9 +297,17 @@ interface InvoiceItem {
294
297
  itemId: string;
295
298
  /** Contribution to the invoice total. Zero for a settled line. */
296
299
  amount: number;
297
- /** Shown but not charged — work the customer already paid for in cash. */
300
+ /**
301
+ * Shown but not charged — work whose fee the customer already settled, either
302
+ * in cash at the door or prepaid before dispatch.
303
+ */
298
304
  zeroRated?: boolean;
299
- settledBy?: 'cash';
305
+ /**
306
+ * Which already-settled route a zero-rated line took. Unset on a charged line.
307
+ * The invoice's `zeroRatedTotal` is one number for the period; sum lines by
308
+ * this field for the "paid at the door" / "paid in advance" split.
309
+ */
310
+ settledBy?: 'cash' | 'prepaid';
300
311
  /** What the work was worth, on a zero-rated line only. */
301
312
  originalAmount?: number;
302
313
  description: string;
@@ -332,6 +343,12 @@ interface Business {
332
343
  registrationCompleted: boolean | NullOrUndefined;
333
344
  stateId: string | NullOrUndefined;
334
345
  cityId: string | NullOrUndefined;
346
+ /**
347
+ * IANA zone the business's own calendar runs on — the clock its reports are cut
348
+ * against, so a 23:30 errand lands on the day the operator worked it rather than
349
+ * on whatever day it was in UTC. Unset means the platform default, Africa/Lagos.
350
+ */
351
+ timezone: string | NullOrUndefined;
335
352
  originalLogoUrl: string | NullOrUndefined;
336
353
  logoUrl: string | NullOrUndefined;
337
354
  logoBlurHash: string | NullOrUndefined;
@@ -391,6 +408,15 @@ interface BusinessModules {
391
408
  invoices: boolean;
392
409
  remittances: boolean;
393
410
  }
411
+ /**
412
+ * How a business funds fuel. `revenuePercent` is the share of errand revenue a
413
+ * vehicle sets aside for its own fuel — the single knob behind the fuel-owed
414
+ * balance. `null` (the default) means the business hasn't configured it and the
415
+ * balance is not computed at all.
416
+ */
417
+ interface BusinessFuelSettings {
418
+ revenuePercent: number | null;
419
+ }
394
420
  interface BusinessSettings {
395
421
  whatsapp_notification_enabled: boolean;
396
422
  whatsapp: BusinessWhatsappConfig;
@@ -417,7 +443,9 @@ interface BusinessSettings {
417
443
  maxErrands: number | null;
418
444
  };
419
445
  modules: BusinessModules;
446
+ fuel?: BusinessFuelSettings;
420
447
  }
448
+ declare const DEFAULT_BUSINESS_FUEL_SETTINGS: BusinessFuelSettings;
421
449
  declare const DEFAULT_BUSINESS_MODULES: BusinessModules;
422
450
  declare const DEFAULT_BUSINESS_SETTINGS: BusinessSettings;
423
451
  interface BusinessMember {
@@ -578,6 +606,95 @@ interface VehiclePerformanceData {
578
606
  totals: VehiclePerformanceTotals;
579
607
  filters: VehiclePerformanceFilters;
580
608
  }
609
+ declare enum FuelDueStatus {
610
+ /** Worked through the fuel it was last given. Fuel this one. */
611
+ Due = "DUE",
612
+ /** Still running on fuel already paid for. Leave it. */
613
+ Ok = "OK"
614
+ }
615
+ /** What the vehicle has done since the fuel it was last given. */
616
+ interface FuelSinceLastRefuel {
617
+ revenue: number;
618
+ errandCount: number;
619
+ fuelEarned: number;
620
+ }
621
+ interface FuelDueItem {
622
+ vehicleId: string;
623
+ vehicleNumber: string;
624
+ shortName: string | null;
625
+ vehicleType: VehicleType | `${VehicleType}`;
626
+ /**
627
+ * The fuel gauge, and the field to lead a UI with: how much of the fuel this
628
+ * vehicle was last given it has worked through. 0 is freshly filled, 100 is
629
+ * due, past 100 is overdue. Null when it has never been fuelled.
630
+ */
631
+ fuelUsedPercent: number | null;
632
+ /** `fuelEarned - fuelSpent`, in naira — how much to give, not whether to. */
633
+ fuelDue: number;
634
+ fuelEarned: number;
635
+ fuelSpent: number;
636
+ revenue: number;
637
+ errandCount: number;
638
+ refuelCount: number;
639
+ /** What this vehicle is typically fuelled with; null if never fuelled. */
640
+ averageRefuelCost: number | null;
641
+ /**
642
+ * The figure has drifted far past what this vehicle is ever fuelled with —
643
+ * the signature of a wrong `revenuePercent` compounding rather than a real
644
+ * fuel need. Prompt to check the percentage instead of showing the figure.
645
+ */
646
+ needsCalibration: boolean;
647
+ lastRefuel: {
648
+ at: string;
649
+ cost: number;
650
+ } | null;
651
+ sinceLastRefuel: FuelSinceLastRefuel | null;
652
+ dueStatus: FuelDueStatus | `${FuelDueStatus}`;
653
+ /** Counting starts here when the prediction has been reset; null otherwise. */
654
+ countingFrom: string | null;
655
+ }
656
+ interface FuelDueTotals {
657
+ totalDue: number;
658
+ totalEarned: number;
659
+ totalSpent: number;
660
+ vehiclesDue: number;
661
+ vehiclesNeedingCalibration: number;
662
+ }
663
+ interface FuelDueData {
664
+ /** False when the business has not set `settings.fuel.revenuePercent`. */
665
+ configured: boolean;
666
+ revenuePercent: number | null;
667
+ /** Only when `configured` is false: what history says the percent should be. */
668
+ suggestedPercent?: number | null;
669
+ vehicles: FuelDueItem[];
670
+ totals: FuelDueTotals;
671
+ }
672
+ type FuelSuggestionConfidence = 'low' | 'medium' | 'high';
673
+ interface FuelPercentSuggestion {
674
+ /**
675
+ * Fuel spend as a share of the revenue that earned it, to one decimal —
676
+ * the percentage this business has actually been running at. Null when
677
+ * there is too little history; `reason` says which.
678
+ */
679
+ suggestedPercent: number | null;
680
+ /**
681
+ * Read off the number of refuels behind the suggestion, not the length of
682
+ * the window. Fuel bought near a window's edge is burnt outside it, so a
683
+ * thin refuel count gives a volatile ratio however many days were read.
684
+ */
685
+ confidence: FuelSuggestionConfidence;
686
+ reason: string | null;
687
+ days: number;
688
+ basedOn: {
689
+ totalFuelCost: number;
690
+ totalRevenue: number;
691
+ refuelCount: number;
692
+ errandCount: number;
693
+ refuelledVehicles: number;
694
+ /** Refuels per vehicle — what says whether the ratio has settled. */
695
+ refuelsPerVehicle: number | null;
696
+ };
697
+ }
581
698
 
582
699
  type Rider = {
583
700
  id: string;
@@ -726,6 +843,11 @@ declare enum FeeSettlement {
726
843
  Invoice = "invoice",
727
844
  Owed = "owed"
728
845
  }
846
+ declare enum ErrandInvoiceState {
847
+ Unbilled = "unbilled",
848
+ Invoiced = "invoiced",
849
+ Excluded = "excluded"
850
+ }
729
851
  type ExpensePaidBy = 'rider' | 'company' | 'customer';
730
852
  interface Errand {
731
853
  id: string;
@@ -1181,6 +1303,12 @@ interface TransactionItem {
1181
1303
  variantId?: string;
1182
1304
  isAddon?: boolean;
1183
1305
  }
1306
+ /**
1307
+ * Rider user attached to a transaction — the same `riderUserDetails` field the
1308
+ * errand types carry, narrowed to what the UI needs to label an expense with
1309
+ * its rider. Derived from User so it can't drift from the canonical shape.
1310
+ */
1311
+ type TransactionRiderUser = Pick<User, 'id' | 'firstName' | 'lastName' | 'mobileNumber' | 'avatarUrl'>;
1184
1312
  interface Transaction {
1185
1313
  id: string;
1186
1314
  type: TransactionType;
@@ -1194,6 +1322,7 @@ interface Transaction {
1194
1322
  categoryId?: string;
1195
1323
  customerId?: string;
1196
1324
  riderId?: string;
1325
+ riderUserDetails?: TransactionRiderUser | null;
1197
1326
  items?: TransactionItem[];
1198
1327
  customerDetails?: Customer;
1199
1328
  }
@@ -1477,4 +1606,4 @@ declare enum LinkDestination {
1477
1606
  }
1478
1607
  type NullOrUndefined = null | undefined;
1479
1608
 
1480
- export { type AddonGroup, type AddonGroupItem, type AddressDetails, AddressTypes, type AggregatedErrand, AuthType, type Business, BusinessCapability, type BusinessCategory, type BusinessCourierLink, BusinessCourierLinkStatus, type BusinessMember, type BusinessModules, type BusinessPg, type BusinessPortal, BusinessRole, type BusinessSettings, BusinessStatus, type BusinessWhatsappConfig, type City, type Collection, type Customer, type CustomerAddress, type CustomerBilling, type CustomerTransactionStats, DEFAULT_BUSINESS_MODULES, DEFAULT_BUSINESS_SETTINGS, DeliveryStatus, type DraftErrand, DraftErrandStatus, type Enterprise, type EnterpriseCategoryDoc, type EnterpriseSubCategoryDoc, EnterpriseType, type Errand, type ErrandDeliveryTiming, type ErrandPackagingQuality, type ErrandRating, type ErrandReview, type ErrandReviewLink, type ErrandRiderBehavior, ErrandStatus, type ErrandTimeline, type ExpensePaidBy, FeePaymentStatus, FeeSettlement, type GeoPoint, GlobalRoles, type Invoice, type InvoiceDrift, type InvoiceEvent, InvoiceEventType, InvoiceGenerationType, type InvoiceItem, InvoiceItemType, type InvoicePayment, InvoicePaymentMethod, type InvoiceStatementLink, InvoiceStatus, type LatLng, LinkDestination, type MaintenanceItem, type MaintenancePartUsage, type MaintenanceRecord, type MaintenanceStats, type MaintenanceStatsSummary, type MaintenanceTopItem, MembershipStatus, type Notification, type NotificationData, NotificationType, type NullOrUndefined, type OpeningHours, type PaginateResult, ParcelSize, PaymentOptions, type PendingErrand, type PortalHandleAvailability, PortalStatus, type Product, type ProductCategory, type ProductImage, type ProductOption, type ProductOptionValue, type ProductStatus, type ProductTag, type ProductVariant, type ProductVariantPrice, type PublicPortal, type PublicPortalBusiness, RemittanceStatus, type Rider, type RiderPerformanceItem, type RiderPerformanceStats, type RiderPerformanceSummary, type RiderPerformanceTimeSeries, type RiderSettlement, type RiderWithUserDetails, RoleType, type State, SweepExclusionReason, type TrackerPosition, type Transaction, type TransactionCategory, type TransactionItem, type TransactionType, type TransactionWithCategory, type TransactionWithJoin, type User, type UserAddress, type Vehicle, type VehicleErrandStats, type VehicleFuelStats, type VehicleLog, type VehicleLogStatsSummary, VehicleLogType, type VehicleLogWithErrands, type VehicleMaintenanceStats, type VehiclePerformanceData, type VehiclePerformanceFilters, type VehiclePerformanceItem, type VehiclePerformanceTotals, VehicleType, type VehicleWithRider, type Vendor, WhatsappButtonType, WhatsappComponentType, WhatsappEvent, WhatsappRecipient, type WhatsappSendLog, type WhatsappTemplate, type WhatsappTemplateButton, type WhatsappTemplateComponent, WhatsappTemplateMetaStatus, WhatsappTemplateParamSource, type WhatsappTemplateSource, errandTimeline };
1609
+ export { type AddonGroup, type AddonGroupItem, type AddressDetails, AddressTypes, type AggregatedErrand, AuthType, type Business, BusinessCapability, type BusinessCategory, type BusinessCourierLink, BusinessCourierLinkStatus, type BusinessFuelSettings, type BusinessMember, type BusinessModules, type BusinessPg, type BusinessPortal, BusinessRole, type BusinessSettings, BusinessStatus, type BusinessWhatsappConfig, type City, type Collection, type Customer, type CustomerAddress, type CustomerBilling, type CustomerTransactionStats, DEFAULT_BUSINESS_FUEL_SETTINGS, DEFAULT_BUSINESS_MODULES, DEFAULT_BUSINESS_SETTINGS, DeliveryStatus, type DraftErrand, DraftErrandStatus, type Enterprise, type EnterpriseCategoryDoc, type EnterpriseSubCategoryDoc, EnterpriseType, type Errand, type ErrandDeliveryTiming, ErrandInvoiceState, type ErrandPackagingQuality, type ErrandRating, type ErrandReview, type ErrandReviewLink, type ErrandRiderBehavior, ErrandStatus, type ErrandTimeline, type ExpensePaidBy, FeePaymentStatus, FeeSettlement, type FuelDueData, type FuelDueItem, FuelDueStatus, type FuelDueTotals, type FuelPercentSuggestion, type FuelSinceLastRefuel, type FuelSuggestionConfidence, type GeoPoint, GlobalRoles, type Invoice, type InvoiceDrift, type InvoiceEvent, InvoiceEventType, InvoiceGenerationType, type InvoiceItem, InvoiceItemType, type InvoicePayment, InvoicePaymentMethod, InvoiceStatus, type LatLng, LinkDestination, type MaintenanceItem, type MaintenancePartUsage, type MaintenanceRecord, type MaintenanceStats, type MaintenanceStatsSummary, type MaintenanceTopItem, MembershipStatus, type Notification, type NotificationData, NotificationType, type NullOrUndefined, type OpeningHours, type PaginateResult, ParcelSize, PaymentOptions, type PendingErrand, type PortalHandleAvailability, PortalStatus, type Product, type ProductCategory, type ProductImage, type ProductOption, type ProductOptionValue, type ProductStatus, type ProductTag, type ProductVariant, type ProductVariantPrice, type PublicPortal, type PublicPortalBusiness, RemittanceStatus, type Rider, type RiderPerformanceItem, type RiderPerformanceStats, type RiderPerformanceSummary, type RiderPerformanceTimeSeries, type RiderSettlement, type RiderWithUserDetails, RoleType, type SharedStatement, type State, SweepExclusionReason, type TrackerPosition, type Transaction, type TransactionCategory, type TransactionItem, type TransactionRiderUser, type TransactionType, type TransactionWithCategory, type TransactionWithJoin, type User, type UserAddress, type Vehicle, type VehicleErrandStats, type VehicleFuelStats, type VehicleLog, type VehicleLogStatsSummary, VehicleLogType, type VehicleLogWithErrands, type VehicleMaintenanceStats, type VehiclePerformanceData, type VehiclePerformanceFilters, type VehiclePerformanceItem, type VehiclePerformanceTotals, VehicleType, type VehicleWithRider, type Vendor, WhatsappButtonType, WhatsappComponentType, WhatsappEvent, WhatsappRecipient, type WhatsappSendLog, type WhatsappTemplate, type WhatsappTemplateButton, type WhatsappTemplateComponent, WhatsappTemplateMetaStatus, WhatsappTemplateParamSource, type WhatsappTemplateSource, errandTimeline };
package/dist/index.js CHANGED
@@ -78,6 +78,12 @@ var FeeSettlement = /* @__PURE__ */ ((FeeSettlement2) => {
78
78
  FeeSettlement2["Owed"] = "owed";
79
79
  return FeeSettlement2;
80
80
  })(FeeSettlement || {});
81
+ var ErrandInvoiceState = /* @__PURE__ */ ((ErrandInvoiceState2) => {
82
+ ErrandInvoiceState2["Unbilled"] = "unbilled";
83
+ ErrandInvoiceState2["Invoiced"] = "invoiced";
84
+ ErrandInvoiceState2["Excluded"] = "excluded";
85
+ return ErrandInvoiceState2;
86
+ })(ErrandInvoiceState || {});
81
87
  var AddressTypes = /* @__PURE__ */ ((AddressTypes2) => {
82
88
  AddressTypes2["DeliveryAddress"] = "deliveryAddress";
83
89
  AddressTypes2["PickupAddress"] = "pickupAddress";
@@ -146,16 +152,13 @@ var InvoiceEventType = /* @__PURE__ */ ((InvoiceEventType2) => {
146
152
  InvoiceEventType2["PaymentRecorded"] = "payment_recorded";
147
153
  InvoiceEventType2["PaymentReversed"] = "payment_reversed";
148
154
  InvoiceEventType2["StatusChanged"] = "status_changed";
149
- InvoiceEventType2["LinkCreated"] = "link_created";
150
- InvoiceEventType2["LinkRevoked"] = "link_revoked";
155
+ InvoiceEventType2["Shared"] = "shared";
151
156
  InvoiceEventType2["Viewed"] = "viewed";
152
157
  return InvoiceEventType2;
153
158
  })(InvoiceEventType || {});
154
159
  var SweepExclusionReason = /* @__PURE__ */ ((SweepExclusionReason2) => {
155
160
  SweepExclusionReason2["Cancelled"] = "cancelled";
156
161
  SweepExclusionReason2["AlreadyInvoiced"] = "already_invoiced";
157
- SweepExclusionReason2["SettledCash"] = "settled_cash";
158
- SweepExclusionReason2["Prepaid"] = "prepaid";
159
162
  SweepExclusionReason2["Owed"] = "owed";
160
163
  SweepExclusionReason2["NotInvoiceable"] = "not_invoiceable";
161
164
  return SweepExclusionReason2;
@@ -180,6 +183,11 @@ var VehicleLogType = /* @__PURE__ */ ((VehicleLogType2) => {
180
183
  VehicleLogType2["REFUEL"] = "REFUEL";
181
184
  return VehicleLogType2;
182
185
  })(VehicleLogType || {});
186
+ var FuelDueStatus = /* @__PURE__ */ ((FuelDueStatus2) => {
187
+ FuelDueStatus2["Due"] = "DUE";
188
+ FuelDueStatus2["Ok"] = "OK";
189
+ return FuelDueStatus2;
190
+ })(FuelDueStatus || {});
183
191
 
184
192
  // src/rider.ts
185
193
  var RemittanceStatus = /* @__PURE__ */ ((RemittanceStatus2) => {
@@ -221,6 +229,9 @@ var MembershipStatus = /* @__PURE__ */ ((MembershipStatus2) => {
221
229
  MembershipStatus2["SUSPENDED"] = "SUSPENDED";
222
230
  return MembershipStatus2;
223
231
  })(MembershipStatus || {});
232
+ var DEFAULT_BUSINESS_FUEL_SETTINGS = {
233
+ revenuePercent: null
234
+ };
224
235
  var DEFAULT_BUSINESS_MODULES = {
225
236
  draftErrands: true,
226
237
  team: true,
@@ -252,7 +263,8 @@ var DEFAULT_BUSINESS_SETTINGS = {
252
263
  tiktok: null,
253
264
  website: null
254
265
  },
255
- modules: DEFAULT_BUSINESS_MODULES
266
+ modules: DEFAULT_BUSINESS_MODULES,
267
+ fuel: DEFAULT_BUSINESS_FUEL_SETTINGS
256
268
  };
257
269
  var BusinessCourierLinkStatus = /* @__PURE__ */ ((BusinessCourierLinkStatus2) => {
258
270
  BusinessCourierLinkStatus2["ACTIVE"] = "active";
@@ -329,14 +341,17 @@ export {
329
341
  BusinessCourierLinkStatus,
330
342
  BusinessRole,
331
343
  BusinessStatus,
344
+ DEFAULT_BUSINESS_FUEL_SETTINGS,
332
345
  DEFAULT_BUSINESS_MODULES,
333
346
  DEFAULT_BUSINESS_SETTINGS,
334
347
  DeliveryStatus,
335
348
  DraftErrandStatus,
336
349
  EnterpriseType,
350
+ ErrandInvoiceState,
337
351
  ErrandStatus,
338
352
  FeePaymentStatus,
339
353
  FeeSettlement,
354
+ FuelDueStatus,
340
355
  GlobalRoles,
341
356
  InvoiceEventType,
342
357
  InvoiceGenerationType,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mydoormot/app-types",
3
- "version": "1.9.1",
3
+ "version": "1.9.3",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
package/src/business.ts CHANGED
@@ -33,6 +33,13 @@ export interface Business {
33
33
  stateId: string | NullOrUndefined;
34
34
  cityId: string | NullOrUndefined;
35
35
 
36
+ /**
37
+ * IANA zone the business's own calendar runs on — the clock its reports are cut
38
+ * against, so a 23:30 errand lands on the day the operator worked it rather than
39
+ * on whatever day it was in UTC. Unset means the platform default, Africa/Lagos.
40
+ */
41
+ timezone: string | NullOrUndefined;
42
+
36
43
  originalLogoUrl: string | NullOrUndefined;
37
44
  logoUrl: string | NullOrUndefined;
38
45
  logoBlurHash: string | NullOrUndefined;
@@ -106,6 +113,16 @@ export interface BusinessModules {
106
113
  remittances: boolean;
107
114
  }
108
115
 
116
+ /**
117
+ * How a business funds fuel. `revenuePercent` is the share of errand revenue a
118
+ * vehicle sets aside for its own fuel — the single knob behind the fuel-owed
119
+ * balance. `null` (the default) means the business hasn't configured it and the
120
+ * balance is not computed at all.
121
+ */
122
+ export interface BusinessFuelSettings {
123
+ revenuePercent: number | null;
124
+ }
125
+
109
126
  export interface BusinessSettings {
110
127
  whatsapp_notification_enabled: boolean;
111
128
  whatsapp: BusinessWhatsappConfig;
@@ -132,8 +149,13 @@ export interface BusinessSettings {
132
149
  maxErrands: number | null;
133
150
  };
134
151
  modules: BusinessModules;
152
+ fuel?: BusinessFuelSettings;
135
153
  }
136
154
 
155
+ export const DEFAULT_BUSINESS_FUEL_SETTINGS: BusinessFuelSettings = {
156
+ revenuePercent: null,
157
+ };
158
+
137
159
  export const DEFAULT_BUSINESS_MODULES: BusinessModules = {
138
160
  draftErrands: true,
139
161
  team: true,
@@ -167,6 +189,7 @@ export const DEFAULT_BUSINESS_SETTINGS: BusinessSettings = {
167
189
  website: null,
168
190
  },
169
191
  modules: DEFAULT_BUSINESS_MODULES,
192
+ fuel: DEFAULT_BUSINESS_FUEL_SETTINGS,
170
193
  };
171
194
 
172
195
  export interface BusinessMember {
package/src/customer.ts CHANGED
@@ -55,7 +55,13 @@ export interface Customer {
55
55
  * earliest member.
56
56
  */
57
57
  export interface CustomerBilling {
58
+ /**
59
+ * What is still owed on work that has not reached a statement — net of
60
+ * anything already paid on those errands, which is why it can be smaller than
61
+ * the sum of their prices.
62
+ */
58
63
  unbilledAmount: number;
64
+ /** How many errands are not on a statement yet, paid ones included. */
59
65
  unbilledCount: number;
60
66
  oldestUnbilledAt: string | null;
61
67
  outstandingAmount: number;
package/src/errand.ts CHANGED
@@ -135,6 +135,21 @@ export enum FeeSettlement {
135
135
  Owed = 'owed',
136
136
  }
137
137
 
138
+ // Where an errand sits in the billing lifecycle — the axis orthogonal to
139
+ // `feePaymentStatus`. One asks "does the customer owe us?", this asks "has it
140
+ // been put on a bill yet?", and every useful listing is a product of the two
141
+ // (e.g. `invoiced` + `unpaid` is the chase list).
142
+ export enum ErrandInvoiceState {
143
+ // Billable and not yet on any invoice — the statement sweep would pick it up.
144
+ Unbilled = 'unbilled',
145
+ // Already attached to an invoice (or a business invoice batch).
146
+ Invoiced = 'invoiced',
147
+ // Settles some way that never reaches a statement: prepaid, cash on
148
+ // delivery, or `owed`. Notably where `owed` lands, which is what keeps it out
149
+ // of a collections list it would otherwise sit in forever.
150
+ Excluded = 'excluded',
151
+ }
152
+
138
153
  // Who fronted an errand expense. `customer` covers "paid on call" and
139
154
  // "handed to the rider directly" — only `company`-fronted expenses are billed.
140
155
  export type ExpensePaidBy = 'rider' | 'company' | 'customer';
package/src/invoice.ts CHANGED
@@ -42,8 +42,7 @@ export enum InvoiceEventType {
42
42
  PaymentRecorded = 'payment_recorded',
43
43
  PaymentReversed = 'payment_reversed',
44
44
  StatusChanged = 'status_changed',
45
- LinkCreated = 'link_created',
46
- LinkRevoked = 'link_revoked',
45
+ Shared = 'shared',
47
46
  Viewed = 'viewed',
48
47
  }
49
48
 
@@ -51,8 +50,6 @@ export enum InvoiceEventType {
51
50
  export enum SweepExclusionReason {
52
51
  Cancelled = 'cancelled',
53
52
  AlreadyInvoiced = 'already_invoiced',
54
- SettledCash = 'settled_cash',
55
- Prepaid = 'prepaid',
56
53
  Owed = 'owed',
57
54
  NotInvoiceable = 'not_invoiceable',
58
55
  }
@@ -89,17 +86,11 @@ export interface InvoiceEvent {
89
86
  createdAt: string;
90
87
  }
91
88
 
92
- export interface InvoiceStatementLink {
93
- id: string;
94
- invoiceId: string;
95
- businessId: string;
96
- token: string;
97
- expiresAt: string;
98
- revokedAt?: string;
99
- viewCount: number;
100
- firstViewedAt?: string;
101
- lastViewedAt?: string;
102
- createdAt: string;
89
+ /** What `POST /invoices/:invoiceId/statement-link` returns. */
90
+ export interface SharedStatement {
91
+ /** The slug in the public statement URL. Stable for the invoice's lifetime. */
92
+ statementSlug: string;
93
+ sentAt?: string;
103
94
  }
104
95
 
105
96
  /** Whether a frozen invoice has fallen out of date, and by how much. */
@@ -113,6 +104,12 @@ export interface Invoice {
113
104
  businessId: string;
114
105
  userId: string;
115
106
  invoiceNumber: string;
107
+ /**
108
+ * Slug for the public statement URL, and the only credential guarding it.
109
+ * Written at freeze time, so every invoice is shareable immediately. Absent on
110
+ * invoices frozen before the field existed.
111
+ */
112
+ statementSlug?: string;
116
113
  startDate: string;
117
114
  endDate: string;
118
115
  /** What the customer is asked for. Excludes zero-rated lines. */
@@ -154,9 +151,17 @@ export interface InvoiceItem {
154
151
  // item: Errand;
155
152
  /** Contribution to the invoice total. Zero for a settled line. */
156
153
  amount: number;
157
- /** Shown but not charged — work the customer already paid for in cash. */
154
+ /**
155
+ * Shown but not charged — work whose fee the customer already settled, either
156
+ * in cash at the door or prepaid before dispatch.
157
+ */
158
158
  zeroRated?: boolean;
159
- settledBy?: 'cash';
159
+ /**
160
+ * Which already-settled route a zero-rated line took. Unset on a charged line.
161
+ * The invoice's `zeroRatedTotal` is one number for the period; sum lines by
162
+ * this field for the "paid at the door" / "paid in advance" split.
163
+ */
164
+ settledBy?: 'cash' | 'prepaid';
160
165
  /** What the work was worth, on a zero-rated line only. */
161
166
  originalAmount?: number;
162
167
  description: string;
@@ -1,4 +1,5 @@
1
1
  import { Customer } from './customer';
2
+ import { User } from './user';
2
3
 
3
4
  export type TransactionType = 'sale' | 'expense';
4
5
 
@@ -12,6 +13,16 @@ export interface TransactionItem {
12
13
  isAddon?: boolean;
13
14
  }
14
15
 
16
+ /**
17
+ * Rider user attached to a transaction — the same `riderUserDetails` field the
18
+ * errand types carry, narrowed to what the UI needs to label an expense with
19
+ * its rider. Derived from User so it can't drift from the canonical shape.
20
+ */
21
+ export type TransactionRiderUser = Pick<
22
+ User,
23
+ 'id' | 'firstName' | 'lastName' | 'mobileNumber' | 'avatarUrl'
24
+ >;
25
+
15
26
  export interface Transaction {
16
27
  id: string;
17
28
  type: TransactionType;
@@ -25,6 +36,7 @@ export interface Transaction {
25
36
  categoryId?: string;
26
37
  customerId?: string;
27
38
  riderId?: string;
39
+ riderUserDetails?: TransactionRiderUser | null;
28
40
  items?: TransactionItem[];
29
41
  customerDetails?: Customer;
30
42
  }
package/src/vehicle.ts CHANGED
@@ -142,3 +142,104 @@ export interface VehiclePerformanceData {
142
142
  totals: VehiclePerformanceTotals;
143
143
  filters: VehiclePerformanceFilters;
144
144
  }
145
+
146
+ // Fuel Due Types
147
+ //
148
+ // These answer "which vehicles are due for fuel" without anyone counting
149
+ // errands by hand. Errands generate fuel money at the business's
150
+ // `settings.fuel.revenuePercent`; logged refuels spend it. The difference is
151
+ // `fuelDue`, and `fuelUsedPercent` reads it back as a fuel gauge — 0 freshly
152
+ // filled, 100 due, beyond that overdue.
153
+
154
+ export enum FuelDueStatus {
155
+ /** Worked through the fuel it was last given. Fuel this one. */
156
+ Due = 'DUE',
157
+ /** Still running on fuel already paid for. Leave it. */
158
+ Ok = 'OK',
159
+ }
160
+
161
+ /** What the vehicle has done since the fuel it was last given. */
162
+ export interface FuelSinceLastRefuel {
163
+ revenue: number;
164
+ errandCount: number;
165
+ fuelEarned: number;
166
+ }
167
+
168
+ export interface FuelDueItem {
169
+ vehicleId: string;
170
+ vehicleNumber: string;
171
+ shortName: string | null;
172
+ vehicleType: VehicleType | `${VehicleType}`;
173
+ /**
174
+ * The fuel gauge, and the field to lead a UI with: how much of the fuel this
175
+ * vehicle was last given it has worked through. 0 is freshly filled, 100 is
176
+ * due, past 100 is overdue. Null when it has never been fuelled.
177
+ */
178
+ fuelUsedPercent: number | null;
179
+ /** `fuelEarned - fuelSpent`, in naira — how much to give, not whether to. */
180
+ fuelDue: number;
181
+ fuelEarned: number;
182
+ fuelSpent: number;
183
+ revenue: number;
184
+ errandCount: number;
185
+ refuelCount: number;
186
+ /** What this vehicle is typically fuelled with; null if never fuelled. */
187
+ averageRefuelCost: number | null;
188
+ /**
189
+ * The figure has drifted far past what this vehicle is ever fuelled with —
190
+ * the signature of a wrong `revenuePercent` compounding rather than a real
191
+ * fuel need. Prompt to check the percentage instead of showing the figure.
192
+ */
193
+ needsCalibration: boolean;
194
+ lastRefuel: { at: string; cost: number } | null;
195
+ sinceLastRefuel: FuelSinceLastRefuel | null;
196
+ dueStatus: FuelDueStatus | `${FuelDueStatus}`;
197
+ /** Counting starts here when the prediction has been reset; null otherwise. */
198
+ countingFrom: string | null;
199
+ }
200
+
201
+ export interface FuelDueTotals {
202
+ totalDue: number;
203
+ totalEarned: number;
204
+ totalSpent: number;
205
+ vehiclesDue: number;
206
+ vehiclesNeedingCalibration: number;
207
+ }
208
+
209
+ export interface FuelDueData {
210
+ /** False when the business has not set `settings.fuel.revenuePercent`. */
211
+ configured: boolean;
212
+ revenuePercent: number | null;
213
+ /** Only when `configured` is false: what history says the percent should be. */
214
+ suggestedPercent?: number | null;
215
+ vehicles: FuelDueItem[];
216
+ totals: FuelDueTotals;
217
+ }
218
+
219
+ export type FuelSuggestionConfidence = 'low' | 'medium' | 'high';
220
+
221
+ export interface FuelPercentSuggestion {
222
+ /**
223
+ * Fuel spend as a share of the revenue that earned it, to one decimal —
224
+ * the percentage this business has actually been running at. Null when
225
+ * there is too little history; `reason` says which.
226
+ */
227
+ suggestedPercent: number | null;
228
+ /**
229
+ * Read off the number of refuels behind the suggestion, not the length of
230
+ * the window. Fuel bought near a window's edge is burnt outside it, so a
231
+ * thin refuel count gives a volatile ratio however many days were read.
232
+ */
233
+ confidence: FuelSuggestionConfidence;
234
+ reason: string | null;
235
+ days: number;
236
+ basedOn: {
237
+ totalFuelCost: number;
238
+ totalRevenue: number;
239
+ refuelCount: number;
240
+ errandCount: number;
241
+ refuelledVehicles: number;
242
+ /** Refuels per vehicle — what says whether the ratio has settled. */
243
+ refuelsPerVehicle: number | null;
244
+ };
245
+ }