@mydoormot/app-types 1.9.0 → 1.9.2

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.8.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 14.07 KB
12
- CJS ⚡️ Build success in 57ms
13
- ESM dist/index.js 11.62 KB
14
- ESM ⚡️ Build success in 57ms
15
- DTS Build start
16
- DTS ⚡️ Build success in 752ms
17
- DTS dist/index.d.ts 36.60 KB
18
- DTS dist/index.d.cts 36.60 KB
1
+
2
+ > @mydoormot/app-types@1.9.1 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
+ ESM dist/index.js 13.48 KB
12
+ ESM ⚡️ Build success in 55ms
13
+ CJS dist/index.cjs 16.12 KB
14
+ CJS ⚡️ Build success in 55ms
15
+ DTS Build start
16
+ DTS ⚡️ Build success in 635ms
17
+ DTS dist/index.d.ts 41.80 KB
18
+ DTS dist/index.d.cts 41.80 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @mydoormot/app-types
2
2
 
3
+ ## 1.9.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Modified transactions
8
+
9
+ ## 1.9.1
10
+
11
+ ### Patch Changes
12
+
13
+ - Added customer billing
14
+
3
15
  ## 1.9.0
4
16
 
5
17
  ### Minor Changes
package/dist/index.cjs CHANGED
@@ -31,12 +31,15 @@ __export(src_exports, {
31
31
  DeliveryStatus: () => DeliveryStatus,
32
32
  DraftErrandStatus: () => DraftErrandStatus,
33
33
  EnterpriseType: () => EnterpriseType,
34
+ ErrandInvoiceState: () => ErrandInvoiceState,
34
35
  ErrandStatus: () => ErrandStatus,
35
36
  FeePaymentStatus: () => FeePaymentStatus,
36
37
  FeeSettlement: () => FeeSettlement,
37
38
  GlobalRoles: () => GlobalRoles,
39
+ InvoiceEventType: () => InvoiceEventType,
38
40
  InvoiceGenerationType: () => InvoiceGenerationType,
39
41
  InvoiceItemType: () => InvoiceItemType,
42
+ InvoicePaymentMethod: () => InvoicePaymentMethod,
40
43
  InvoiceStatus: () => InvoiceStatus,
41
44
  LinkDestination: () => LinkDestination,
42
45
  MembershipStatus: () => MembershipStatus,
@@ -46,6 +49,7 @@ __export(src_exports, {
46
49
  PortalStatus: () => PortalStatus,
47
50
  RemittanceStatus: () => RemittanceStatus,
48
51
  RoleType: () => RoleType,
52
+ SweepExclusionReason: () => SweepExclusionReason,
49
53
  VehicleLogType: () => VehicleLogType,
50
54
  VehicleType: () => VehicleType,
51
55
  WhatsappButtonType: () => WhatsappButtonType,
@@ -138,6 +142,12 @@ var FeeSettlement = /* @__PURE__ */ ((FeeSettlement2) => {
138
142
  FeeSettlement2["Owed"] = "owed";
139
143
  return FeeSettlement2;
140
144
  })(FeeSettlement || {});
145
+ var ErrandInvoiceState = /* @__PURE__ */ ((ErrandInvoiceState2) => {
146
+ ErrandInvoiceState2["Unbilled"] = "unbilled";
147
+ ErrandInvoiceState2["Invoiced"] = "invoiced";
148
+ ErrandInvoiceState2["Excluded"] = "excluded";
149
+ return ErrandInvoiceState2;
150
+ })(ErrandInvoiceState || {});
141
151
  var AddressTypes = /* @__PURE__ */ ((AddressTypes2) => {
142
152
  AddressTypes2["DeliveryAddress"] = "deliveryAddress";
143
153
  AddressTypes2["PickupAddress"] = "pickupAddress";
@@ -189,6 +199,37 @@ var PaymentOptions = /* @__PURE__ */ ((PaymentOptions2) => {
189
199
  PaymentOptions2["BusinessInvoice"] = "business_invoice";
190
200
  return PaymentOptions2;
191
201
  })(PaymentOptions || {});
202
+ var InvoicePaymentMethod = /* @__PURE__ */ ((InvoicePaymentMethod2) => {
203
+ InvoicePaymentMethod2["Transfer"] = "transfer";
204
+ InvoicePaymentMethod2["Cash"] = "cash";
205
+ InvoicePaymentMethod2["Card"] = "card";
206
+ InvoicePaymentMethod2["Pos"] = "pos";
207
+ InvoicePaymentMethod2["Other"] = "other";
208
+ return InvoicePaymentMethod2;
209
+ })(InvoicePaymentMethod || {});
210
+ var InvoiceEventType = /* @__PURE__ */ ((InvoiceEventType2) => {
211
+ InvoiceEventType2["Frozen"] = "frozen";
212
+ InvoiceEventType2["ErrandsAdded"] = "errands_added";
213
+ InvoiceEventType2["ErrandRemoved"] = "errand_removed";
214
+ InvoiceEventType2["Recalculated"] = "recalculated";
215
+ InvoiceEventType2["LineAmountChanged"] = "line_amount_changed";
216
+ InvoiceEventType2["PaymentRecorded"] = "payment_recorded";
217
+ InvoiceEventType2["PaymentReversed"] = "payment_reversed";
218
+ InvoiceEventType2["StatusChanged"] = "status_changed";
219
+ InvoiceEventType2["LinkCreated"] = "link_created";
220
+ InvoiceEventType2["LinkRevoked"] = "link_revoked";
221
+ InvoiceEventType2["Viewed"] = "viewed";
222
+ return InvoiceEventType2;
223
+ })(InvoiceEventType || {});
224
+ var SweepExclusionReason = /* @__PURE__ */ ((SweepExclusionReason2) => {
225
+ SweepExclusionReason2["Cancelled"] = "cancelled";
226
+ SweepExclusionReason2["AlreadyInvoiced"] = "already_invoiced";
227
+ SweepExclusionReason2["SettledCash"] = "settled_cash";
228
+ SweepExclusionReason2["Prepaid"] = "prepaid";
229
+ SweepExclusionReason2["Owed"] = "owed";
230
+ SweepExclusionReason2["NotInvoiceable"] = "not_invoiceable";
231
+ return SweepExclusionReason2;
232
+ })(SweepExclusionReason || {});
192
233
 
193
234
  // src/notification.ts
194
235
  var NotificationType = /* @__PURE__ */ ((NotificationType2) => {
@@ -364,12 +405,15 @@ var LinkDestination = /* @__PURE__ */ ((LinkDestination2) => {
364
405
  DeliveryStatus,
365
406
  DraftErrandStatus,
366
407
  EnterpriseType,
408
+ ErrandInvoiceState,
367
409
  ErrandStatus,
368
410
  FeePaymentStatus,
369
411
  FeeSettlement,
370
412
  GlobalRoles,
413
+ InvoiceEventType,
371
414
  InvoiceGenerationType,
372
415
  InvoiceItemType,
416
+ InvoicePaymentMethod,
373
417
  InvoiceStatus,
374
418
  LinkDestination,
375
419
  MembershipStatus,
@@ -379,6 +423,7 @@ var LinkDestination = /* @__PURE__ */ ((LinkDestination2) => {
379
423
  PortalStatus,
380
424
  RemittanceStatus,
381
425
  RoleType,
426
+ SweepExclusionReason,
382
427
  VehicleLogType,
383
428
  VehicleType,
384
429
  WhatsappButtonType,
package/dist/index.d.cts CHANGED
@@ -132,6 +132,35 @@ interface Customer {
132
132
  customerBusinessId?: string;
133
133
  transactionStats?: CustomerTransactionStats;
134
134
  }
135
+ /**
136
+ * What a customer owes, computed server-side. `unbilled` is a SET, not a
137
+ * period — it has no start or end date, and `oldestUnbilledAt` is simply its
138
+ * earliest member.
139
+ */
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
+ */
146
+ unbilledAmount: number;
147
+ /** How many errands are not on a statement yet, paid ones included. */
148
+ unbilledCount: number;
149
+ oldestUnbilledAt: string | null;
150
+ outstandingAmount: number;
151
+ openInvoiceCount: number;
152
+ /** End of the newest period already invoiced. */
153
+ lastInvoicedThrough: string | null;
154
+ /**
155
+ * The next invoice window, derived rather than typed: from the day after the
156
+ * last invoice closed, to today. Consecutive periods therefore tile with no
157
+ * gap and no overlap.
158
+ */
159
+ nextPeriod: {
160
+ from: string | null;
161
+ to: string;
162
+ };
163
+ }
135
164
 
136
165
  declare enum InvoiceStatus {
137
166
  Pending = "pending",
@@ -152,6 +181,82 @@ declare enum PaymentOptions {
152
181
  Card = "card",
153
182
  BusinessInvoice = "business_invoice"
154
183
  }
184
+ declare enum InvoicePaymentMethod {
185
+ Transfer = "transfer",
186
+ Cash = "cash",
187
+ Card = "card",
188
+ Pos = "pos",
189
+ Other = "other"
190
+ }
191
+ declare enum InvoiceEventType {
192
+ Frozen = "frozen",
193
+ ErrandsAdded = "errands_added",
194
+ ErrandRemoved = "errand_removed",
195
+ Recalculated = "recalculated",
196
+ LineAmountChanged = "line_amount_changed",
197
+ PaymentRecorded = "payment_recorded",
198
+ PaymentReversed = "payment_reversed",
199
+ StatusChanged = "status_changed",
200
+ LinkCreated = "link_created",
201
+ LinkRevoked = "link_revoked",
202
+ Viewed = "viewed"
203
+ }
204
+ /** Why an errand in the period was not charged on the statement. */
205
+ declare enum SweepExclusionReason {
206
+ Cancelled = "cancelled",
207
+ AlreadyInvoiced = "already_invoiced",
208
+ SettledCash = "settled_cash",
209
+ Prepaid = "prepaid",
210
+ Owed = "owed",
211
+ NotInvoiceable = "not_invoiceable"
212
+ }
213
+ interface InvoicePayment {
214
+ id: string;
215
+ invoiceId: string;
216
+ businessId: string;
217
+ amount: number;
218
+ paidAt: string;
219
+ method?: InvoicePaymentMethod | `${InvoicePaymentMethod}`;
220
+ reference?: string;
221
+ note?: string;
222
+ recordedBy: string;
223
+ reversedAt?: string;
224
+ reversedBy?: string;
225
+ reversalReason?: string;
226
+ createdAt: string;
227
+ updatedAt: string;
228
+ }
229
+ interface InvoiceEvent {
230
+ id: string;
231
+ invoiceId: string;
232
+ businessId: string;
233
+ type: InvoiceEventType | `${InvoiceEventType}`;
234
+ actorUserId?: string;
235
+ amountBefore?: number;
236
+ amountAfter?: number;
237
+ summary?: string;
238
+ /** Repeated back to the customer on their own statement. */
239
+ customerVisible: boolean;
240
+ meta?: Record<string, unknown>;
241
+ createdAt: string;
242
+ }
243
+ interface InvoiceStatementLink {
244
+ id: string;
245
+ invoiceId: string;
246
+ businessId: string;
247
+ token: string;
248
+ expiresAt: string;
249
+ revokedAt?: string;
250
+ viewCount: number;
251
+ firstViewedAt?: string;
252
+ lastViewedAt?: string;
253
+ createdAt: string;
254
+ }
255
+ /** Whether a frozen invoice has fallen out of date, and by how much. */
256
+ interface InvoiceDrift {
257
+ errandCount: number;
258
+ amount: number;
259
+ }
155
260
  interface Invoice {
156
261
  id: string;
157
262
  businessId: string;
@@ -159,9 +264,26 @@ interface Invoice {
159
264
  invoiceNumber: string;
160
265
  startDate: string;
161
266
  endDate: string;
267
+ /** What the customer is asked for. Excludes zero-rated lines. */
162
268
  totalAmount: number;
269
+ /**
270
+ * What the settled-at-the-door lines were worth. Never owed, never part of
271
+ * `totalAmount` — carried so the statement can show the period's full
272
+ * activity without charging for it twice.
273
+ */
274
+ zeroRatedTotal: number;
163
275
  paidAmount: number;
164
276
  unpaidAmount: number;
277
+ lastRecalculatedAt?: string;
278
+ /**
279
+ * Document lifecycle, kept separate from `status`: an invoice can be
280
+ * part-paid and viewed, or paid and never opened.
281
+ */
282
+ sentAt?: string;
283
+ firstViewedAt?: string;
284
+ lastViewedAt?: string;
285
+ viewCount?: number;
286
+ drift?: InvoiceDrift;
165
287
  status: InvoiceStatus | `${InvoiceStatus}`;
166
288
  customerId: string;
167
289
  items: InvoiceItem[];
@@ -176,7 +298,13 @@ interface InvoiceItem {
176
298
  invoiceId: string;
177
299
  itemType: InvoiceItemType | `${InvoiceItemType}`;
178
300
  itemId: string;
301
+ /** Contribution to the invoice total. Zero for a settled line. */
179
302
  amount: number;
303
+ /** Shown but not charged — work the customer already paid for in cash. */
304
+ zeroRated?: boolean;
305
+ settledBy?: 'cash';
306
+ /** What the work was worth, on a zero-rated line only. */
307
+ originalAmount?: number;
180
308
  description: string;
181
309
  date: string;
182
310
  createdAt: string;
@@ -210,6 +338,12 @@ interface Business {
210
338
  registrationCompleted: boolean | NullOrUndefined;
211
339
  stateId: string | NullOrUndefined;
212
340
  cityId: string | NullOrUndefined;
341
+ /**
342
+ * IANA zone the business's own calendar runs on — the clock its reports are cut
343
+ * against, so a 23:30 errand lands on the day the operator worked it rather than
344
+ * on whatever day it was in UTC. Unset means the platform default, Africa/Lagos.
345
+ */
346
+ timezone: string | NullOrUndefined;
213
347
  originalLogoUrl: string | NullOrUndefined;
214
348
  logoUrl: string | NullOrUndefined;
215
349
  logoBlurHash: string | NullOrUndefined;
@@ -397,11 +531,17 @@ type VehicleLog = {
397
531
  createdAt: string;
398
532
  updatedAt: string;
399
533
  previousLogId?: string;
400
- errandIdsSinceLastRefuel?: string[];
401
- lastRecalculatedAt?: string;
402
534
  vehicleDetails?: Vehicle;
403
535
  };
404
536
  type VehicleLogWithErrands = VehicleLog & {
537
+ /**
538
+ * The errands the vehicle ran during this refuel's fuel period —
539
+ * `(previousLog.createdAt, createdAt]`. Derived on read, so it always
540
+ * reflects current assignments and cancellations.
541
+ */
542
+ errands?: Errand[];
543
+ /** Start of the fuel period; null for a vehicle's first log. */
544
+ periodStart?: string | null;
405
545
  errandsCount?: number;
406
546
  totalErrandsRevenue?: number;
407
547
  /**
@@ -598,6 +738,11 @@ declare enum FeeSettlement {
598
738
  Invoice = "invoice",
599
739
  Owed = "owed"
600
740
  }
741
+ declare enum ErrandInvoiceState {
742
+ Unbilled = "unbilled",
743
+ Invoiced = "invoiced",
744
+ Excluded = "excluded"
745
+ }
601
746
  type ExpensePaidBy = 'rider' | 'company' | 'customer';
602
747
  interface Errand {
603
748
  id: string;
@@ -1053,6 +1198,12 @@ interface TransactionItem {
1053
1198
  variantId?: string;
1054
1199
  isAddon?: boolean;
1055
1200
  }
1201
+ /**
1202
+ * Rider user attached to a transaction — the same `riderUserDetails` field the
1203
+ * errand types carry, narrowed to what the UI needs to label an expense with
1204
+ * its rider. Derived from User so it can't drift from the canonical shape.
1205
+ */
1206
+ type TransactionRiderUser = Pick<User, 'id' | 'firstName' | 'lastName' | 'mobileNumber' | 'avatarUrl'>;
1056
1207
  interface Transaction {
1057
1208
  id: string;
1058
1209
  type: TransactionType;
@@ -1066,6 +1217,7 @@ interface Transaction {
1066
1217
  categoryId?: string;
1067
1218
  customerId?: string;
1068
1219
  riderId?: string;
1220
+ riderUserDetails?: TransactionRiderUser | null;
1069
1221
  items?: TransactionItem[];
1070
1222
  customerDetails?: Customer;
1071
1223
  }
@@ -1312,14 +1464,14 @@ interface PublicPortalBusiness {
1312
1464
  openingHours?: Record<string, unknown>;
1313
1465
  socialLinks?: Record<string, unknown>;
1314
1466
  }
1315
- /** `GET /api/v2/public/b/:handle` */
1467
+ /** `GET /api/v2/portals/:handle` — unauthenticated. */
1316
1468
  interface PublicPortal {
1317
1469
  handle: string;
1318
1470
  /** Set when the requested handle was retired — redirect to `handle`. */
1319
1471
  redirectedFrom?: string;
1320
1472
  business: PublicPortalBusiness;
1321
1473
  }
1322
- /** `GET /api/v2/public/portal-handle-availability` */
1474
+ /** `GET /api/v2/portals/handles/:handle` — unauthenticated. */
1323
1475
  interface PortalHandleAvailability {
1324
1476
  /** Normalised — what you would actually be assigned. */
1325
1477
  handle: string;
@@ -1349,4 +1501,4 @@ declare enum LinkDestination {
1349
1501
  }
1350
1502
  type NullOrUndefined = null | undefined;
1351
1503
 
1352
- 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 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, InvoiceGenerationType, type InvoiceItem, InvoiceItemType, 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, 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 };
1504
+ 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, ErrandInvoiceState, 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 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
@@ -132,6 +132,35 @@ interface Customer {
132
132
  customerBusinessId?: string;
133
133
  transactionStats?: CustomerTransactionStats;
134
134
  }
135
+ /**
136
+ * What a customer owes, computed server-side. `unbilled` is a SET, not a
137
+ * period — it has no start or end date, and `oldestUnbilledAt` is simply its
138
+ * earliest member.
139
+ */
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
+ */
146
+ unbilledAmount: number;
147
+ /** How many errands are not on a statement yet, paid ones included. */
148
+ unbilledCount: number;
149
+ oldestUnbilledAt: string | null;
150
+ outstandingAmount: number;
151
+ openInvoiceCount: number;
152
+ /** End of the newest period already invoiced. */
153
+ lastInvoicedThrough: string | null;
154
+ /**
155
+ * The next invoice window, derived rather than typed: from the day after the
156
+ * last invoice closed, to today. Consecutive periods therefore tile with no
157
+ * gap and no overlap.
158
+ */
159
+ nextPeriod: {
160
+ from: string | null;
161
+ to: string;
162
+ };
163
+ }
135
164
 
136
165
  declare enum InvoiceStatus {
137
166
  Pending = "pending",
@@ -152,6 +181,82 @@ declare enum PaymentOptions {
152
181
  Card = "card",
153
182
  BusinessInvoice = "business_invoice"
154
183
  }
184
+ declare enum InvoicePaymentMethod {
185
+ Transfer = "transfer",
186
+ Cash = "cash",
187
+ Card = "card",
188
+ Pos = "pos",
189
+ Other = "other"
190
+ }
191
+ declare enum InvoiceEventType {
192
+ Frozen = "frozen",
193
+ ErrandsAdded = "errands_added",
194
+ ErrandRemoved = "errand_removed",
195
+ Recalculated = "recalculated",
196
+ LineAmountChanged = "line_amount_changed",
197
+ PaymentRecorded = "payment_recorded",
198
+ PaymentReversed = "payment_reversed",
199
+ StatusChanged = "status_changed",
200
+ LinkCreated = "link_created",
201
+ LinkRevoked = "link_revoked",
202
+ Viewed = "viewed"
203
+ }
204
+ /** Why an errand in the period was not charged on the statement. */
205
+ declare enum SweepExclusionReason {
206
+ Cancelled = "cancelled",
207
+ AlreadyInvoiced = "already_invoiced",
208
+ SettledCash = "settled_cash",
209
+ Prepaid = "prepaid",
210
+ Owed = "owed",
211
+ NotInvoiceable = "not_invoiceable"
212
+ }
213
+ interface InvoicePayment {
214
+ id: string;
215
+ invoiceId: string;
216
+ businessId: string;
217
+ amount: number;
218
+ paidAt: string;
219
+ method?: InvoicePaymentMethod | `${InvoicePaymentMethod}`;
220
+ reference?: string;
221
+ note?: string;
222
+ recordedBy: string;
223
+ reversedAt?: string;
224
+ reversedBy?: string;
225
+ reversalReason?: string;
226
+ createdAt: string;
227
+ updatedAt: string;
228
+ }
229
+ interface InvoiceEvent {
230
+ id: string;
231
+ invoiceId: string;
232
+ businessId: string;
233
+ type: InvoiceEventType | `${InvoiceEventType}`;
234
+ actorUserId?: string;
235
+ amountBefore?: number;
236
+ amountAfter?: number;
237
+ summary?: string;
238
+ /** Repeated back to the customer on their own statement. */
239
+ customerVisible: boolean;
240
+ meta?: Record<string, unknown>;
241
+ createdAt: string;
242
+ }
243
+ interface InvoiceStatementLink {
244
+ id: string;
245
+ invoiceId: string;
246
+ businessId: string;
247
+ token: string;
248
+ expiresAt: string;
249
+ revokedAt?: string;
250
+ viewCount: number;
251
+ firstViewedAt?: string;
252
+ lastViewedAt?: string;
253
+ createdAt: string;
254
+ }
255
+ /** Whether a frozen invoice has fallen out of date, and by how much. */
256
+ interface InvoiceDrift {
257
+ errandCount: number;
258
+ amount: number;
259
+ }
155
260
  interface Invoice {
156
261
  id: string;
157
262
  businessId: string;
@@ -159,9 +264,26 @@ interface Invoice {
159
264
  invoiceNumber: string;
160
265
  startDate: string;
161
266
  endDate: string;
267
+ /** What the customer is asked for. Excludes zero-rated lines. */
162
268
  totalAmount: number;
269
+ /**
270
+ * What the settled-at-the-door lines were worth. Never owed, never part of
271
+ * `totalAmount` — carried so the statement can show the period's full
272
+ * activity without charging for it twice.
273
+ */
274
+ zeroRatedTotal: number;
163
275
  paidAmount: number;
164
276
  unpaidAmount: number;
277
+ lastRecalculatedAt?: string;
278
+ /**
279
+ * Document lifecycle, kept separate from `status`: an invoice can be
280
+ * part-paid and viewed, or paid and never opened.
281
+ */
282
+ sentAt?: string;
283
+ firstViewedAt?: string;
284
+ lastViewedAt?: string;
285
+ viewCount?: number;
286
+ drift?: InvoiceDrift;
165
287
  status: InvoiceStatus | `${InvoiceStatus}`;
166
288
  customerId: string;
167
289
  items: InvoiceItem[];
@@ -176,7 +298,13 @@ interface InvoiceItem {
176
298
  invoiceId: string;
177
299
  itemType: InvoiceItemType | `${InvoiceItemType}`;
178
300
  itemId: string;
301
+ /** Contribution to the invoice total. Zero for a settled line. */
179
302
  amount: number;
303
+ /** Shown but not charged — work the customer already paid for in cash. */
304
+ zeroRated?: boolean;
305
+ settledBy?: 'cash';
306
+ /** What the work was worth, on a zero-rated line only. */
307
+ originalAmount?: number;
180
308
  description: string;
181
309
  date: string;
182
310
  createdAt: string;
@@ -210,6 +338,12 @@ interface Business {
210
338
  registrationCompleted: boolean | NullOrUndefined;
211
339
  stateId: string | NullOrUndefined;
212
340
  cityId: string | NullOrUndefined;
341
+ /**
342
+ * IANA zone the business's own calendar runs on — the clock its reports are cut
343
+ * against, so a 23:30 errand lands on the day the operator worked it rather than
344
+ * on whatever day it was in UTC. Unset means the platform default, Africa/Lagos.
345
+ */
346
+ timezone: string | NullOrUndefined;
213
347
  originalLogoUrl: string | NullOrUndefined;
214
348
  logoUrl: string | NullOrUndefined;
215
349
  logoBlurHash: string | NullOrUndefined;
@@ -397,11 +531,17 @@ type VehicleLog = {
397
531
  createdAt: string;
398
532
  updatedAt: string;
399
533
  previousLogId?: string;
400
- errandIdsSinceLastRefuel?: string[];
401
- lastRecalculatedAt?: string;
402
534
  vehicleDetails?: Vehicle;
403
535
  };
404
536
  type VehicleLogWithErrands = VehicleLog & {
537
+ /**
538
+ * The errands the vehicle ran during this refuel's fuel period —
539
+ * `(previousLog.createdAt, createdAt]`. Derived on read, so it always
540
+ * reflects current assignments and cancellations.
541
+ */
542
+ errands?: Errand[];
543
+ /** Start of the fuel period; null for a vehicle's first log. */
544
+ periodStart?: string | null;
405
545
  errandsCount?: number;
406
546
  totalErrandsRevenue?: number;
407
547
  /**
@@ -598,6 +738,11 @@ declare enum FeeSettlement {
598
738
  Invoice = "invoice",
599
739
  Owed = "owed"
600
740
  }
741
+ declare enum ErrandInvoiceState {
742
+ Unbilled = "unbilled",
743
+ Invoiced = "invoiced",
744
+ Excluded = "excluded"
745
+ }
601
746
  type ExpensePaidBy = 'rider' | 'company' | 'customer';
602
747
  interface Errand {
603
748
  id: string;
@@ -1053,6 +1198,12 @@ interface TransactionItem {
1053
1198
  variantId?: string;
1054
1199
  isAddon?: boolean;
1055
1200
  }
1201
+ /**
1202
+ * Rider user attached to a transaction — the same `riderUserDetails` field the
1203
+ * errand types carry, narrowed to what the UI needs to label an expense with
1204
+ * its rider. Derived from User so it can't drift from the canonical shape.
1205
+ */
1206
+ type TransactionRiderUser = Pick<User, 'id' | 'firstName' | 'lastName' | 'mobileNumber' | 'avatarUrl'>;
1056
1207
  interface Transaction {
1057
1208
  id: string;
1058
1209
  type: TransactionType;
@@ -1066,6 +1217,7 @@ interface Transaction {
1066
1217
  categoryId?: string;
1067
1218
  customerId?: string;
1068
1219
  riderId?: string;
1220
+ riderUserDetails?: TransactionRiderUser | null;
1069
1221
  items?: TransactionItem[];
1070
1222
  customerDetails?: Customer;
1071
1223
  }
@@ -1312,14 +1464,14 @@ interface PublicPortalBusiness {
1312
1464
  openingHours?: Record<string, unknown>;
1313
1465
  socialLinks?: Record<string, unknown>;
1314
1466
  }
1315
- /** `GET /api/v2/public/b/:handle` */
1467
+ /** `GET /api/v2/portals/:handle` — unauthenticated. */
1316
1468
  interface PublicPortal {
1317
1469
  handle: string;
1318
1470
  /** Set when the requested handle was retired — redirect to `handle`. */
1319
1471
  redirectedFrom?: string;
1320
1472
  business: PublicPortalBusiness;
1321
1473
  }
1322
- /** `GET /api/v2/public/portal-handle-availability` */
1474
+ /** `GET /api/v2/portals/handles/:handle` — unauthenticated. */
1323
1475
  interface PortalHandleAvailability {
1324
1476
  /** Normalised — what you would actually be assigned. */
1325
1477
  handle: string;
@@ -1349,4 +1501,4 @@ declare enum LinkDestination {
1349
1501
  }
1350
1502
  type NullOrUndefined = null | undefined;
1351
1503
 
1352
- 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 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, InvoiceGenerationType, type InvoiceItem, InvoiceItemType, 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, 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 };
1504
+ 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, ErrandInvoiceState, 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 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";
@@ -129,6 +135,37 @@ var PaymentOptions = /* @__PURE__ */ ((PaymentOptions2) => {
129
135
  PaymentOptions2["BusinessInvoice"] = "business_invoice";
130
136
  return PaymentOptions2;
131
137
  })(PaymentOptions || {});
138
+ var InvoicePaymentMethod = /* @__PURE__ */ ((InvoicePaymentMethod2) => {
139
+ InvoicePaymentMethod2["Transfer"] = "transfer";
140
+ InvoicePaymentMethod2["Cash"] = "cash";
141
+ InvoicePaymentMethod2["Card"] = "card";
142
+ InvoicePaymentMethod2["Pos"] = "pos";
143
+ InvoicePaymentMethod2["Other"] = "other";
144
+ return InvoicePaymentMethod2;
145
+ })(InvoicePaymentMethod || {});
146
+ var InvoiceEventType = /* @__PURE__ */ ((InvoiceEventType2) => {
147
+ InvoiceEventType2["Frozen"] = "frozen";
148
+ InvoiceEventType2["ErrandsAdded"] = "errands_added";
149
+ InvoiceEventType2["ErrandRemoved"] = "errand_removed";
150
+ InvoiceEventType2["Recalculated"] = "recalculated";
151
+ InvoiceEventType2["LineAmountChanged"] = "line_amount_changed";
152
+ InvoiceEventType2["PaymentRecorded"] = "payment_recorded";
153
+ InvoiceEventType2["PaymentReversed"] = "payment_reversed";
154
+ InvoiceEventType2["StatusChanged"] = "status_changed";
155
+ InvoiceEventType2["LinkCreated"] = "link_created";
156
+ InvoiceEventType2["LinkRevoked"] = "link_revoked";
157
+ InvoiceEventType2["Viewed"] = "viewed";
158
+ return InvoiceEventType2;
159
+ })(InvoiceEventType || {});
160
+ var SweepExclusionReason = /* @__PURE__ */ ((SweepExclusionReason2) => {
161
+ SweepExclusionReason2["Cancelled"] = "cancelled";
162
+ SweepExclusionReason2["AlreadyInvoiced"] = "already_invoiced";
163
+ SweepExclusionReason2["SettledCash"] = "settled_cash";
164
+ SweepExclusionReason2["Prepaid"] = "prepaid";
165
+ SweepExclusionReason2["Owed"] = "owed";
166
+ SweepExclusionReason2["NotInvoiceable"] = "not_invoiceable";
167
+ return SweepExclusionReason2;
168
+ })(SweepExclusionReason || {});
132
169
 
133
170
  // src/notification.ts
134
171
  var NotificationType = /* @__PURE__ */ ((NotificationType2) => {
@@ -303,12 +340,15 @@ export {
303
340
  DeliveryStatus,
304
341
  DraftErrandStatus,
305
342
  EnterpriseType,
343
+ ErrandInvoiceState,
306
344
  ErrandStatus,
307
345
  FeePaymentStatus,
308
346
  FeeSettlement,
309
347
  GlobalRoles,
348
+ InvoiceEventType,
310
349
  InvoiceGenerationType,
311
350
  InvoiceItemType,
351
+ InvoicePaymentMethod,
312
352
  InvoiceStatus,
313
353
  LinkDestination,
314
354
  MembershipStatus,
@@ -318,6 +358,7 @@ export {
318
358
  PortalStatus,
319
359
  RemittanceStatus,
320
360
  RoleType,
361
+ SweepExclusionReason,
321
362
  VehicleLogType,
322
363
  VehicleType,
323
364
  WhatsappButtonType,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mydoormot/app-types",
3
- "version": "1.9.0",
3
+ "version": "1.9.2",
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;
package/src/customer.ts CHANGED
@@ -48,3 +48,30 @@ export interface Customer {
48
48
  // city?: City;
49
49
  // state?: State;
50
50
  }
51
+
52
+ /**
53
+ * What a customer owes, computed server-side. `unbilled` is a SET, not a
54
+ * period — it has no start or end date, and `oldestUnbilledAt` is simply its
55
+ * earliest member.
56
+ */
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
+ */
63
+ unbilledAmount: number;
64
+ /** How many errands are not on a statement yet, paid ones included. */
65
+ unbilledCount: number;
66
+ oldestUnbilledAt: string | null;
67
+ outstandingAmount: number;
68
+ openInvoiceCount: number;
69
+ /** End of the newest period already invoiced. */
70
+ lastInvoicedThrough: string | null;
71
+ /**
72
+ * The next invoice window, derived rather than typed: from the day after the
73
+ * last invoice closed, to today. Consecutive periods therefore tile with no
74
+ * gap and no overlap.
75
+ */
76
+ nextPeriod: { from: string | null; to: string };
77
+ }
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
@@ -25,6 +25,89 @@ export enum PaymentOptions {
25
25
  BusinessInvoice = 'business_invoice',
26
26
  }
27
27
 
28
+ export enum InvoicePaymentMethod {
29
+ Transfer = 'transfer',
30
+ Cash = 'cash',
31
+ Card = 'card',
32
+ Pos = 'pos',
33
+ Other = 'other',
34
+ }
35
+
36
+ export enum InvoiceEventType {
37
+ Frozen = 'frozen',
38
+ ErrandsAdded = 'errands_added',
39
+ ErrandRemoved = 'errand_removed',
40
+ Recalculated = 'recalculated',
41
+ LineAmountChanged = 'line_amount_changed',
42
+ PaymentRecorded = 'payment_recorded',
43
+ PaymentReversed = 'payment_reversed',
44
+ StatusChanged = 'status_changed',
45
+ LinkCreated = 'link_created',
46
+ LinkRevoked = 'link_revoked',
47
+ Viewed = 'viewed',
48
+ }
49
+
50
+ /** Why an errand in the period was not charged on the statement. */
51
+ export enum SweepExclusionReason {
52
+ Cancelled = 'cancelled',
53
+ AlreadyInvoiced = 'already_invoiced',
54
+ SettledCash = 'settled_cash',
55
+ Prepaid = 'prepaid',
56
+ Owed = 'owed',
57
+ NotInvoiceable = 'not_invoiceable',
58
+ }
59
+
60
+ export interface InvoicePayment {
61
+ id: string;
62
+ invoiceId: string;
63
+ businessId: string;
64
+ amount: number;
65
+ paidAt: string;
66
+ method?: InvoicePaymentMethod | `${InvoicePaymentMethod}`;
67
+ reference?: string;
68
+ note?: string;
69
+ recordedBy: string;
70
+ reversedAt?: string;
71
+ reversedBy?: string;
72
+ reversalReason?: string;
73
+ createdAt: string;
74
+ updatedAt: string;
75
+ }
76
+
77
+ export interface InvoiceEvent {
78
+ id: string;
79
+ invoiceId: string;
80
+ businessId: string;
81
+ type: InvoiceEventType | `${InvoiceEventType}`;
82
+ actorUserId?: string;
83
+ amountBefore?: number;
84
+ amountAfter?: number;
85
+ summary?: string;
86
+ /** Repeated back to the customer on their own statement. */
87
+ customerVisible: boolean;
88
+ meta?: Record<string, unknown>;
89
+ createdAt: string;
90
+ }
91
+
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;
103
+ }
104
+
105
+ /** Whether a frozen invoice has fallen out of date, and by how much. */
106
+ export interface InvoiceDrift {
107
+ errandCount: number;
108
+ amount: number;
109
+ }
110
+
28
111
  export interface Invoice {
29
112
  id: string;
30
113
  businessId: string;
@@ -32,9 +115,26 @@ export interface Invoice {
32
115
  invoiceNumber: string;
33
116
  startDate: string;
34
117
  endDate: string;
118
+ /** What the customer is asked for. Excludes zero-rated lines. */
35
119
  totalAmount: number;
120
+ /**
121
+ * What the settled-at-the-door lines were worth. Never owed, never part of
122
+ * `totalAmount` — carried so the statement can show the period's full
123
+ * activity without charging for it twice.
124
+ */
125
+ zeroRatedTotal: number;
36
126
  paidAmount: number;
37
127
  unpaidAmount: number;
128
+ lastRecalculatedAt?: string;
129
+ /**
130
+ * Document lifecycle, kept separate from `status`: an invoice can be
131
+ * part-paid and viewed, or paid and never opened.
132
+ */
133
+ sentAt?: string;
134
+ firstViewedAt?: string;
135
+ lastViewedAt?: string;
136
+ viewCount?: number;
137
+ drift?: InvoiceDrift;
38
138
  status: InvoiceStatus | `${InvoiceStatus}`;
39
139
  customerId: string;
40
140
  items: InvoiceItem[];
@@ -52,7 +152,13 @@ export interface InvoiceItem {
52
152
  itemType: InvoiceItemType | `${InvoiceItemType}`;
53
153
  itemId: string;
54
154
  // item: Errand;
155
+ /** Contribution to the invoice total. Zero for a settled line. */
55
156
  amount: number;
157
+ /** Shown but not charged — work the customer already paid for in cash. */
158
+ zeroRated?: boolean;
159
+ settledBy?: 'cash';
160
+ /** What the work was worth, on a zero-rated line only. */
161
+ originalAmount?: number;
56
162
  description: string;
57
163
  date: string;
58
164
  createdAt: string;
package/src/portal.ts CHANGED
@@ -29,7 +29,7 @@ export interface PublicPortalBusiness {
29
29
  socialLinks?: Record<string, unknown>;
30
30
  }
31
31
 
32
- /** `GET /api/v2/public/b/:handle` */
32
+ /** `GET /api/v2/portals/:handle` — unauthenticated. */
33
33
  export interface PublicPortal {
34
34
  handle: string;
35
35
  /** Set when the requested handle was retired — redirect to `handle`. */
@@ -37,7 +37,7 @@ export interface PublicPortal {
37
37
  business: PublicPortalBusiness;
38
38
  }
39
39
 
40
- /** `GET /api/v2/public/portal-handle-availability` */
40
+ /** `GET /api/v2/portals/handles/:handle` — unauthenticated. */
41
41
  export interface PortalHandleAvailability {
42
42
  /** Normalised — what you would actually be assigned. */
43
43
  handle: 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
@@ -1,3 +1,4 @@
1
+ import { Errand } from './errand';
1
2
  import { RiderWithUserDetails } from './rider';
2
3
 
3
4
  export enum VehicleType {
@@ -73,12 +74,18 @@ export type VehicleLog = {
73
74
  createdAt: string;
74
75
  updatedAt: string;
75
76
  previousLogId?: string;
76
- errandIdsSinceLastRefuel?: string[];
77
- lastRecalculatedAt?: string;
78
77
  vehicleDetails?: Vehicle;
79
78
  };
80
79
 
81
80
  export type VehicleLogWithErrands = VehicleLog & {
81
+ /**
82
+ * The errands the vehicle ran during this refuel's fuel period —
83
+ * `(previousLog.createdAt, createdAt]`. Derived on read, so it always
84
+ * reflects current assignments and cancellations.
85
+ */
86
+ errands?: Errand[];
87
+ /** Start of the fuel period; null for a vehicle's first log. */
88
+ periodStart?: string | null;
82
89
  errandsCount?: number;
83
90
  totalErrandsRevenue?: number;
84
91
  /**