@mydoormot/app-types 2.0.6 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
 
2
- > @mydoormot/app-types@2.0.5 build /Users/chuksben/Desktop/projects/microservices/mydoormot/packages/app-types
2
+ > @mydoormot/app-types@2.1.0 build /Users/chuksben/Desktop/projects/microservices/mydoormot/packages/app-types
3
3
  > tsup src/index.ts --format esm,cjs --dts
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -8,11 +8,11 @@ CLI tsup v7.3.0
8
8
  CLI Target: es2021
9
9
  ESM Build start
10
10
  CJS Build start
11
- ESM dist/index.js 14.38 KB
12
- ESM ⚡️ Build success in 180ms
13
- CJS dist/index.cjs 17.31 KB
14
- CJS ⚡️ Build success in 180ms
11
+ ESM dist/index.js 14.90 KB
12
+ ESM ⚡️ Build success in 59ms
13
+ CJS dist/index.cjs 17.95 KB
14
+ CJS ⚡️ Build success in 59ms
15
15
  DTS Build start
16
- DTS ⚡️ Build success in 682ms
17
- DTS dist/index.d.ts 50.65 KB
18
- DTS dist/index.d.cts 50.65 KB
16
+ DTS ⚡️ Build success in 738ms
17
+ DTS dist/index.d.ts 55.42 KB
18
+ DTS dist/index.d.cts 55.42 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @mydoormot/app-types
2
2
 
3
+ ## 2.1.1
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated business schema
8
+
3
9
  ## 2.0.6
4
10
 
5
11
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -24,8 +24,10 @@ __export(src_exports, {
24
24
  AuthType: () => AuthType,
25
25
  BusinessCapability: () => BusinessCapability,
26
26
  BusinessCourierLinkStatus: () => BusinessCourierLinkStatus,
27
+ BusinessPlan: () => BusinessPlan,
27
28
  BusinessRole: () => BusinessRole,
28
29
  BusinessStatus: () => BusinessStatus,
30
+ BusinessType: () => BusinessType,
29
31
  DEFAULT_BUSINESS_FUEL_SETTINGS: () => DEFAULT_BUSINESS_FUEL_SETTINGS,
30
32
  DEFAULT_BUSINESS_MODULES: () => DEFAULT_BUSINESS_MODULES,
31
33
  DEFAULT_BUSINESS_RIDER_PAY_SETTINGS: () => DEFAULT_BUSINESS_RIDER_PAY_SETTINGS,
@@ -33,6 +35,7 @@ __export(src_exports, {
33
35
  DeliveryStatus: () => DeliveryStatus,
34
36
  DraftErrandStatus: () => DraftErrandStatus,
35
37
  EnterpriseType: () => EnterpriseType,
38
+ ErrandFulfilment: () => ErrandFulfilment,
36
39
  ErrandInvoiceState: () => ErrandInvoiceState,
37
40
  ErrandStatus: () => ErrandStatus,
38
41
  FeePaymentStatus: () => FeePaymentStatus,
@@ -291,6 +294,22 @@ var BusinessCapability = /* @__PURE__ */ ((BusinessCapability2) => {
291
294
  BusinessCapability2["SELF_FULFILLMENT"] = "self_fulfillment";
292
295
  return BusinessCapability2;
293
296
  })(BusinessCapability || {});
297
+ var ErrandFulfilment = /* @__PURE__ */ ((ErrandFulfilment2) => {
298
+ ErrandFulfilment2["OWN"] = "own";
299
+ ErrandFulfilment2["NETWORK"] = "network";
300
+ return ErrandFulfilment2;
301
+ })(ErrandFulfilment || {});
302
+ var BusinessType = /* @__PURE__ */ ((BusinessType2) => {
303
+ BusinessType2["MERCHANT"] = "merchant";
304
+ BusinessType2["COURIER"] = "courier";
305
+ return BusinessType2;
306
+ })(BusinessType || {});
307
+ var BusinessPlan = /* @__PURE__ */ ((BusinessPlan2) => {
308
+ BusinessPlan2["MVP"] = "mvp";
309
+ BusinessPlan2["FULL"] = "full";
310
+ BusinessPlan2["INTERNAL"] = "internal";
311
+ return BusinessPlan2;
312
+ })(BusinessPlan || {});
294
313
  var BusinessStatus = /* @__PURE__ */ ((BusinessStatus2) => {
295
314
  BusinessStatus2["ACTIVE"] = "active";
296
315
  BusinessStatus2["DISABLED"] = "disabled";
@@ -316,22 +335,15 @@ var DEFAULT_BUSINESS_RIDER_PAY_SETTINGS = {
316
335
  defaultPercentage: null,
317
336
  periodType: null
318
337
  };
319
- var DEFAULT_BUSINESS_MODULES = {
320
- draftErrands: true,
321
- team: true,
322
- maintenance: true,
323
- fuelLogs: true,
324
- invoices: true,
325
- remittances: true
326
- };
338
+ var DEFAULT_BUSINESS_MODULES = {};
327
339
  var DEFAULT_BUSINESS_SETTINGS = {
328
- whatsapp_notification_enabled: true,
340
+ whatsappNotificationEnabled: true,
329
341
  whatsapp: {
330
342
  enabled: false,
331
343
  templates: {}
332
344
  },
333
- is_online: true,
334
- opening_hours: {
345
+ isOnline: true,
346
+ openingHours: {
335
347
  monday: { open: "09:00", close: "17:00" },
336
348
  tuesday: { open: "09:00", close: "17:00" },
337
349
  wednesday: { open: "09:00", close: "17:00" },
@@ -340,7 +352,7 @@ var DEFAULT_BUSINESS_SETTINGS = {
340
352
  saturday: null,
341
353
  sunday: null
342
354
  },
343
- social_links: {
355
+ socialLinks: {
344
356
  instagram: null,
345
357
  facebook: null,
346
358
  twitter: null,
@@ -425,8 +437,10 @@ var LinkDestination = /* @__PURE__ */ ((LinkDestination2) => {
425
437
  AuthType,
426
438
  BusinessCapability,
427
439
  BusinessCourierLinkStatus,
440
+ BusinessPlan,
428
441
  BusinessRole,
429
442
  BusinessStatus,
443
+ BusinessType,
430
444
  DEFAULT_BUSINESS_FUEL_SETTINGS,
431
445
  DEFAULT_BUSINESS_MODULES,
432
446
  DEFAULT_BUSINESS_RIDER_PAY_SETTINGS,
@@ -434,6 +448,7 @@ var LinkDestination = /* @__PURE__ */ ((LinkDestination2) => {
434
448
  DeliveryStatus,
435
449
  DraftErrandStatus,
436
450
  EnterpriseType,
451
+ ErrandFulfilment,
437
452
  ErrandInvoiceState,
438
453
  ErrandStatus,
439
454
  FeePaymentStatus,
package/dist/index.d.cts CHANGED
@@ -309,9 +309,59 @@ interface InvoiceItem {
309
309
  itemDetails?: Errand;
310
310
  }
311
311
 
312
+ /**
313
+ * @deprecated Retired. `SELF_FULFILLMENT` asked "may this business use its own
314
+ * rider instead of ours?" — a question that only makes sense when
315
+ * self-fulfilment is the exception. Every merchant has riders, so the flag was
316
+ * true for everyone and said nothing.
317
+ *
318
+ * What replaced it: the `riders` module for whether the business manages its
319
+ * own riders at all, and {@link ErrandFulfilment} on each errand for who
320
+ * actually carried it. A restaurant with two riders still overflows to the
321
+ * network on a busy Friday, which a business-level boolean cannot express and
322
+ * an errand-level field can — and the errand-level one is what rider-cost
323
+ * reporting needs.
324
+ */
312
325
  declare enum BusinessCapability {
313
326
  SELF_FULFILLMENT = "self_fulfillment"
314
327
  }
328
+ /**
329
+ * Who carried an errand: the originating business's own rider, or the wider
330
+ * network. The field rider-cost reporting splits on — own-rider cost against
331
+ * network payout.
332
+ */
333
+ declare enum ErrandFulfilment {
334
+ OWN = "own",
335
+ NETWORK = "network"
336
+ }
337
+ /**
338
+ * Which product a business is using. The one stored fact about its shape —
339
+ * a courier runs deliveries for other businesses, a merchant sends its own out.
340
+ *
341
+ * Replaces the free-text business-category collection, whose only reader was a
342
+ * `name.includes('courier')` string match: a category rename silently reshaped
343
+ * the account, and five of the seven call sites omitted `toLowerCase()` so a
344
+ * capitalised name read as `false` everywhere.
345
+ */
346
+ declare enum BusinessType {
347
+ MERCHANT = "merchant",
348
+ COURIER = "courier"
349
+ }
350
+ /**
351
+ * How much of its product a business gets. Orthogonal to {@link BusinessType}:
352
+ * `type` decides which features are even relevant, `plan` decides which of
353
+ * those are unlocked. A merchant's `full` and a courier's `full` are different
354
+ * sets, which is the point — upgrading a restaurant must never hand it
355
+ * client-invoicing.
356
+ *
357
+ * `internal` is where new work lands: features default to it alone, so nothing
358
+ * reaches customers by someone forgetting to hide it.
359
+ */
360
+ declare enum BusinessPlan {
361
+ MVP = "mvp",
362
+ FULL = "full",
363
+ INTERNAL = "internal"
364
+ }
315
365
  declare enum BusinessStatus {
316
366
  ACTIVE = "active",
317
367
  DISABLED = "disabled"
@@ -322,6 +372,8 @@ interface Business {
322
372
  name: string;
323
373
  description: string;
324
374
  officeNumber: string;
375
+ type: BusinessType | `${BusinessType}`;
376
+ plan: BusinessPlan | `${BusinessPlan}`;
325
377
  categoryId: string;
326
378
  address: string | NullOrUndefined;
327
379
  addressCoordinates: number[] | NullOrUndefined | {
@@ -351,13 +403,26 @@ interface Business {
351
403
  updatedAt: string | NullOrUndefined | Date;
352
404
  verifiedAt: string | NullOrUndefined | Date;
353
405
  registrationCompletedAt: string | NullOrUndefined | Date;
406
+ /**
407
+ * Derived from `type`, not stored. Kept on the wire because installed mobile
408
+ * binaries still read it; new readers want `type`.
409
+ *
410
+ * @deprecated Read `type` instead.
411
+ */
354
412
  businessCategoryDetails: BusinessCategory | NullOrUndefined;
355
- capabilities: BusinessCapability[] | NullOrUndefined;
356
413
  status: BusinessStatus | `${BusinessStatus}`;
357
414
  disabledAt: string | NullOrUndefined | Date;
358
415
  disabledBy: string | NullOrUndefined;
359
416
  disabledReason: string | NullOrUndefined;
360
417
  settings: BusinessSettings | NullOrUndefined;
418
+ /**
419
+ * The resolved feature set — the plan's defaults with this business's own
420
+ * overrides applied. Server-computed; read this, never `settings.modules`,
421
+ * which holds only the deliberate exceptions.
422
+ */
423
+ modules: Required<{
424
+ [K in keyof BusinessModules]: boolean;
425
+ }>;
361
426
  }
362
427
  interface BusinessPg extends Business {
363
428
  pgId: any;
@@ -392,14 +457,58 @@ interface OpeningHours {
392
457
  open: string;
393
458
  close: string;
394
459
  }
460
+ /**
461
+ * Which features a business sees.
462
+ *
463
+ * Every value is optional, and `undefined` means *inherit from the plan* — not
464
+ * `false`. That distinction is the whole point: a stored `true` is a decision
465
+ * somebody made, so the plan can never quietly take it back, while an unset key
466
+ * follows whatever the plan says today. Storing a resolved default would
467
+ * collapse the two and freeze every business on the defaults it was created
468
+ * with.
469
+ *
470
+ * Resolve with `modulesForPlan(type, plan)[key] ?? ...` — never read a key off
471
+ * this object directly.
472
+ */
395
473
  interface BusinessModules {
396
- draftErrands: boolean;
397
- team: boolean;
398
- maintenance: boolean;
399
- fuelLogs: boolean;
400
- invoices: boolean;
401
- remittances: boolean;
474
+ draftErrands?: boolean;
475
+ maintenance?: boolean;
476
+ fuelLogs?: boolean;
477
+ invoices?: boolean;
478
+ remittances?: boolean;
479
+ /** Manage its own riders: the roster, their pay, what they cost. */
480
+ riders?: boolean;
481
+ /**
482
+ * Route new errands to its own riders rather than to the network.
483
+ *
484
+ * Deliberately separate from `riders`. A merchant can run a roster and still
485
+ * send most deliveries out — managing riders and defaulting to them are
486
+ * different questions, and the old `SELF_FULFILLMENT` capability answered
487
+ * only the second one. Folding them together made every merchant
488
+ * self-fulfil and silently bypass each city's default courier.
489
+ */
490
+ selfFulfilment?: boolean;
491
+ vehicles?: boolean;
492
+ expenses?: boolean;
493
+ /**
494
+ * Calculate what riders earned for a period and generate payout records.
495
+ * `riders/rider-payouts.controller.ts`, and the `rider-payouts` screens.
496
+ */
497
+ riderPayouts?: boolean;
498
+ /** External GPS tracker feed; needs an API key to be useful. */
499
+ trackerDevices?: boolean;
500
+ /**
501
+ * WhatsApp notifications to the business's users and customers on errand
502
+ * events.
503
+ *
504
+ * Declared here so it appears in the plan map and the admin UI, but nothing
505
+ * reads it yet: `updateWhatsappConfig` is still gated on `isOwnFulfiller`.
506
+ * Moving that gate onto this key is the follow-up.
507
+ */
508
+ whatsapp?: boolean;
402
509
  }
510
+ /** Every module key, so a plan map can be checked for completeness. */
511
+ type BusinessModuleKey = keyof BusinessModules;
403
512
  /**
404
513
  * How a business funds fuel. `revenuePercent` is the share of errand revenue a
405
514
  * vehicle sets aside for its own fuel — the single knob behind the fuel-owed
@@ -424,10 +533,10 @@ interface BusinessRiderPaySettings {
424
533
  periodType: PayoutPeriodType | `${PayoutPeriodType}` | null;
425
534
  }
426
535
  interface BusinessSettings {
427
- whatsapp_notification_enabled: boolean;
536
+ whatsappNotificationEnabled: boolean;
428
537
  whatsapp: BusinessWhatsappConfig;
429
- is_online: boolean;
430
- opening_hours: {
538
+ isOnline: boolean;
539
+ openingHours: {
431
540
  monday: OpeningHours | null;
432
541
  tuesday: OpeningHours | null;
433
542
  wednesday: OpeningHours | null;
@@ -436,24 +545,28 @@ interface BusinessSettings {
436
545
  saturday: OpeningHours | null;
437
546
  sunday: OpeningHours | null;
438
547
  };
439
- social_links: {
548
+ socialLinks: {
440
549
  instagram: string | null;
441
550
  facebook: string | null;
442
551
  twitter: string | null;
443
552
  tiktok: string | null;
444
553
  website: string | null;
445
554
  };
446
- limits?: {
447
- maxRiders: number | null;
448
- maxVehicles: number | null;
449
- maxErrands: number | null;
450
- };
451
555
  modules: BusinessModules;
452
556
  fuel?: BusinessFuelSettings;
453
557
  riderPay?: BusinessRiderPaySettings;
454
558
  }
455
559
  declare const DEFAULT_BUSINESS_FUEL_SETTINGS: BusinessFuelSettings;
456
560
  declare const DEFAULT_BUSINESS_RIDER_PAY_SETTINGS: BusinessRiderPaySettings;
561
+ /**
562
+ * @deprecated Defaults live in `modulesForPlan(type, plan)` on the server. This
563
+ * was an all-`true` deny-list: every new feature shipped to every business
564
+ * until someone remembered to switch it off, and writing it into each new
565
+ * business made the stored value indistinguishable from a deliberate grant.
566
+ *
567
+ * Kept only so nothing importing it breaks mid-migration. Empty on purpose —
568
+ * unset means inherit.
569
+ */
457
570
  declare const DEFAULT_BUSINESS_MODULES: BusinessModules;
458
571
  declare const DEFAULT_BUSINESS_SETTINGS: BusinessSettings;
459
572
  interface BusinessMember {
@@ -1723,4 +1836,4 @@ declare enum LinkDestination {
1723
1836
  }
1724
1837
  type NullOrUndefined = null | undefined;
1725
1838
 
1726
- 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, type BusinessRiderPaySettings, 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_RIDER_PAY_SETTINGS, 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, PaymentOptions, PayoutPeriodType, PayoutRateSource, 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 RiderPayout, type RiderPayoutAdjustment, type RiderPayoutPreview, type RiderPayoutPreviewItem, RiderPayoutStatus, 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 };
1839
+ export { type AddonGroup, type AddonGroupItem, type AddressDetails, AddressTypes, type AggregatedErrand, AuthType, type Business, BusinessCapability, type BusinessCategory, type BusinessCourierLink, BusinessCourierLinkStatus, type BusinessFuelSettings, type BusinessMember, type BusinessModuleKey, type BusinessModules, type BusinessPg, BusinessPlan, type BusinessPortal, type BusinessRiderPaySettings, BusinessRole, type BusinessSettings, BusinessStatus, BusinessType, type BusinessWhatsappConfig, type City, type Collection, type Customer, type CustomerAddress, type CustomerBilling, type CustomerTransactionStats, DEFAULT_BUSINESS_FUEL_SETTINGS, DEFAULT_BUSINESS_MODULES, DEFAULT_BUSINESS_RIDER_PAY_SETTINGS, DEFAULT_BUSINESS_SETTINGS, DeliveryStatus, type DraftErrand, DraftErrandStatus, type Enterprise, type EnterpriseCategoryDoc, type EnterpriseSubCategoryDoc, EnterpriseType, type Errand, type ErrandDeliveryTiming, ErrandFulfilment, 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, PaymentOptions, PayoutPeriodType, PayoutRateSource, 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 RiderPayout, type RiderPayoutAdjustment, type RiderPayoutPreview, type RiderPayoutPreviewItem, RiderPayoutStatus, 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
@@ -309,9 +309,59 @@ interface InvoiceItem {
309
309
  itemDetails?: Errand;
310
310
  }
311
311
 
312
+ /**
313
+ * @deprecated Retired. `SELF_FULFILLMENT` asked "may this business use its own
314
+ * rider instead of ours?" — a question that only makes sense when
315
+ * self-fulfilment is the exception. Every merchant has riders, so the flag was
316
+ * true for everyone and said nothing.
317
+ *
318
+ * What replaced it: the `riders` module for whether the business manages its
319
+ * own riders at all, and {@link ErrandFulfilment} on each errand for who
320
+ * actually carried it. A restaurant with two riders still overflows to the
321
+ * network on a busy Friday, which a business-level boolean cannot express and
322
+ * an errand-level field can — and the errand-level one is what rider-cost
323
+ * reporting needs.
324
+ */
312
325
  declare enum BusinessCapability {
313
326
  SELF_FULFILLMENT = "self_fulfillment"
314
327
  }
328
+ /**
329
+ * Who carried an errand: the originating business's own rider, or the wider
330
+ * network. The field rider-cost reporting splits on — own-rider cost against
331
+ * network payout.
332
+ */
333
+ declare enum ErrandFulfilment {
334
+ OWN = "own",
335
+ NETWORK = "network"
336
+ }
337
+ /**
338
+ * Which product a business is using. The one stored fact about its shape —
339
+ * a courier runs deliveries for other businesses, a merchant sends its own out.
340
+ *
341
+ * Replaces the free-text business-category collection, whose only reader was a
342
+ * `name.includes('courier')` string match: a category rename silently reshaped
343
+ * the account, and five of the seven call sites omitted `toLowerCase()` so a
344
+ * capitalised name read as `false` everywhere.
345
+ */
346
+ declare enum BusinessType {
347
+ MERCHANT = "merchant",
348
+ COURIER = "courier"
349
+ }
350
+ /**
351
+ * How much of its product a business gets. Orthogonal to {@link BusinessType}:
352
+ * `type` decides which features are even relevant, `plan` decides which of
353
+ * those are unlocked. A merchant's `full` and a courier's `full` are different
354
+ * sets, which is the point — upgrading a restaurant must never hand it
355
+ * client-invoicing.
356
+ *
357
+ * `internal` is where new work lands: features default to it alone, so nothing
358
+ * reaches customers by someone forgetting to hide it.
359
+ */
360
+ declare enum BusinessPlan {
361
+ MVP = "mvp",
362
+ FULL = "full",
363
+ INTERNAL = "internal"
364
+ }
315
365
  declare enum BusinessStatus {
316
366
  ACTIVE = "active",
317
367
  DISABLED = "disabled"
@@ -322,6 +372,8 @@ interface Business {
322
372
  name: string;
323
373
  description: string;
324
374
  officeNumber: string;
375
+ type: BusinessType | `${BusinessType}`;
376
+ plan: BusinessPlan | `${BusinessPlan}`;
325
377
  categoryId: string;
326
378
  address: string | NullOrUndefined;
327
379
  addressCoordinates: number[] | NullOrUndefined | {
@@ -351,13 +403,26 @@ interface Business {
351
403
  updatedAt: string | NullOrUndefined | Date;
352
404
  verifiedAt: string | NullOrUndefined | Date;
353
405
  registrationCompletedAt: string | NullOrUndefined | Date;
406
+ /**
407
+ * Derived from `type`, not stored. Kept on the wire because installed mobile
408
+ * binaries still read it; new readers want `type`.
409
+ *
410
+ * @deprecated Read `type` instead.
411
+ */
354
412
  businessCategoryDetails: BusinessCategory | NullOrUndefined;
355
- capabilities: BusinessCapability[] | NullOrUndefined;
356
413
  status: BusinessStatus | `${BusinessStatus}`;
357
414
  disabledAt: string | NullOrUndefined | Date;
358
415
  disabledBy: string | NullOrUndefined;
359
416
  disabledReason: string | NullOrUndefined;
360
417
  settings: BusinessSettings | NullOrUndefined;
418
+ /**
419
+ * The resolved feature set — the plan's defaults with this business's own
420
+ * overrides applied. Server-computed; read this, never `settings.modules`,
421
+ * which holds only the deliberate exceptions.
422
+ */
423
+ modules: Required<{
424
+ [K in keyof BusinessModules]: boolean;
425
+ }>;
361
426
  }
362
427
  interface BusinessPg extends Business {
363
428
  pgId: any;
@@ -392,14 +457,58 @@ interface OpeningHours {
392
457
  open: string;
393
458
  close: string;
394
459
  }
460
+ /**
461
+ * Which features a business sees.
462
+ *
463
+ * Every value is optional, and `undefined` means *inherit from the plan* — not
464
+ * `false`. That distinction is the whole point: a stored `true` is a decision
465
+ * somebody made, so the plan can never quietly take it back, while an unset key
466
+ * follows whatever the plan says today. Storing a resolved default would
467
+ * collapse the two and freeze every business on the defaults it was created
468
+ * with.
469
+ *
470
+ * Resolve with `modulesForPlan(type, plan)[key] ?? ...` — never read a key off
471
+ * this object directly.
472
+ */
395
473
  interface BusinessModules {
396
- draftErrands: boolean;
397
- team: boolean;
398
- maintenance: boolean;
399
- fuelLogs: boolean;
400
- invoices: boolean;
401
- remittances: boolean;
474
+ draftErrands?: boolean;
475
+ maintenance?: boolean;
476
+ fuelLogs?: boolean;
477
+ invoices?: boolean;
478
+ remittances?: boolean;
479
+ /** Manage its own riders: the roster, their pay, what they cost. */
480
+ riders?: boolean;
481
+ /**
482
+ * Route new errands to its own riders rather than to the network.
483
+ *
484
+ * Deliberately separate from `riders`. A merchant can run a roster and still
485
+ * send most deliveries out — managing riders and defaulting to them are
486
+ * different questions, and the old `SELF_FULFILLMENT` capability answered
487
+ * only the second one. Folding them together made every merchant
488
+ * self-fulfil and silently bypass each city's default courier.
489
+ */
490
+ selfFulfilment?: boolean;
491
+ vehicles?: boolean;
492
+ expenses?: boolean;
493
+ /**
494
+ * Calculate what riders earned for a period and generate payout records.
495
+ * `riders/rider-payouts.controller.ts`, and the `rider-payouts` screens.
496
+ */
497
+ riderPayouts?: boolean;
498
+ /** External GPS tracker feed; needs an API key to be useful. */
499
+ trackerDevices?: boolean;
500
+ /**
501
+ * WhatsApp notifications to the business's users and customers on errand
502
+ * events.
503
+ *
504
+ * Declared here so it appears in the plan map and the admin UI, but nothing
505
+ * reads it yet: `updateWhatsappConfig` is still gated on `isOwnFulfiller`.
506
+ * Moving that gate onto this key is the follow-up.
507
+ */
508
+ whatsapp?: boolean;
402
509
  }
510
+ /** Every module key, so a plan map can be checked for completeness. */
511
+ type BusinessModuleKey = keyof BusinessModules;
403
512
  /**
404
513
  * How a business funds fuel. `revenuePercent` is the share of errand revenue a
405
514
  * vehicle sets aside for its own fuel — the single knob behind the fuel-owed
@@ -424,10 +533,10 @@ interface BusinessRiderPaySettings {
424
533
  periodType: PayoutPeriodType | `${PayoutPeriodType}` | null;
425
534
  }
426
535
  interface BusinessSettings {
427
- whatsapp_notification_enabled: boolean;
536
+ whatsappNotificationEnabled: boolean;
428
537
  whatsapp: BusinessWhatsappConfig;
429
- is_online: boolean;
430
- opening_hours: {
538
+ isOnline: boolean;
539
+ openingHours: {
431
540
  monday: OpeningHours | null;
432
541
  tuesday: OpeningHours | null;
433
542
  wednesday: OpeningHours | null;
@@ -436,24 +545,28 @@ interface BusinessSettings {
436
545
  saturday: OpeningHours | null;
437
546
  sunday: OpeningHours | null;
438
547
  };
439
- social_links: {
548
+ socialLinks: {
440
549
  instagram: string | null;
441
550
  facebook: string | null;
442
551
  twitter: string | null;
443
552
  tiktok: string | null;
444
553
  website: string | null;
445
554
  };
446
- limits?: {
447
- maxRiders: number | null;
448
- maxVehicles: number | null;
449
- maxErrands: number | null;
450
- };
451
555
  modules: BusinessModules;
452
556
  fuel?: BusinessFuelSettings;
453
557
  riderPay?: BusinessRiderPaySettings;
454
558
  }
455
559
  declare const DEFAULT_BUSINESS_FUEL_SETTINGS: BusinessFuelSettings;
456
560
  declare const DEFAULT_BUSINESS_RIDER_PAY_SETTINGS: BusinessRiderPaySettings;
561
+ /**
562
+ * @deprecated Defaults live in `modulesForPlan(type, plan)` on the server. This
563
+ * was an all-`true` deny-list: every new feature shipped to every business
564
+ * until someone remembered to switch it off, and writing it into each new
565
+ * business made the stored value indistinguishable from a deliberate grant.
566
+ *
567
+ * Kept only so nothing importing it breaks mid-migration. Empty on purpose —
568
+ * unset means inherit.
569
+ */
457
570
  declare const DEFAULT_BUSINESS_MODULES: BusinessModules;
458
571
  declare const DEFAULT_BUSINESS_SETTINGS: BusinessSettings;
459
572
  interface BusinessMember {
@@ -1723,4 +1836,4 @@ declare enum LinkDestination {
1723
1836
  }
1724
1837
  type NullOrUndefined = null | undefined;
1725
1838
 
1726
- 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, type BusinessRiderPaySettings, 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_RIDER_PAY_SETTINGS, 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, PaymentOptions, PayoutPeriodType, PayoutRateSource, 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 RiderPayout, type RiderPayoutAdjustment, type RiderPayoutPreview, type RiderPayoutPreviewItem, RiderPayoutStatus, 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 };
1839
+ export { type AddonGroup, type AddonGroupItem, type AddressDetails, AddressTypes, type AggregatedErrand, AuthType, type Business, BusinessCapability, type BusinessCategory, type BusinessCourierLink, BusinessCourierLinkStatus, type BusinessFuelSettings, type BusinessMember, type BusinessModuleKey, type BusinessModules, type BusinessPg, BusinessPlan, type BusinessPortal, type BusinessRiderPaySettings, BusinessRole, type BusinessSettings, BusinessStatus, BusinessType, type BusinessWhatsappConfig, type City, type Collection, type Customer, type CustomerAddress, type CustomerBilling, type CustomerTransactionStats, DEFAULT_BUSINESS_FUEL_SETTINGS, DEFAULT_BUSINESS_MODULES, DEFAULT_BUSINESS_RIDER_PAY_SETTINGS, DEFAULT_BUSINESS_SETTINGS, DeliveryStatus, type DraftErrand, DraftErrandStatus, type Enterprise, type EnterpriseCategoryDoc, type EnterpriseSubCategoryDoc, EnterpriseType, type Errand, type ErrandDeliveryTiming, ErrandFulfilment, 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, PaymentOptions, PayoutPeriodType, PayoutRateSource, 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 RiderPayout, type RiderPayoutAdjustment, type RiderPayoutPreview, type RiderPayoutPreviewItem, RiderPayoutStatus, 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
@@ -222,6 +222,22 @@ var BusinessCapability = /* @__PURE__ */ ((BusinessCapability2) => {
222
222
  BusinessCapability2["SELF_FULFILLMENT"] = "self_fulfillment";
223
223
  return BusinessCapability2;
224
224
  })(BusinessCapability || {});
225
+ var ErrandFulfilment = /* @__PURE__ */ ((ErrandFulfilment2) => {
226
+ ErrandFulfilment2["OWN"] = "own";
227
+ ErrandFulfilment2["NETWORK"] = "network";
228
+ return ErrandFulfilment2;
229
+ })(ErrandFulfilment || {});
230
+ var BusinessType = /* @__PURE__ */ ((BusinessType2) => {
231
+ BusinessType2["MERCHANT"] = "merchant";
232
+ BusinessType2["COURIER"] = "courier";
233
+ return BusinessType2;
234
+ })(BusinessType || {});
235
+ var BusinessPlan = /* @__PURE__ */ ((BusinessPlan2) => {
236
+ BusinessPlan2["MVP"] = "mvp";
237
+ BusinessPlan2["FULL"] = "full";
238
+ BusinessPlan2["INTERNAL"] = "internal";
239
+ return BusinessPlan2;
240
+ })(BusinessPlan || {});
225
241
  var BusinessStatus = /* @__PURE__ */ ((BusinessStatus2) => {
226
242
  BusinessStatus2["ACTIVE"] = "active";
227
243
  BusinessStatus2["DISABLED"] = "disabled";
@@ -247,22 +263,15 @@ var DEFAULT_BUSINESS_RIDER_PAY_SETTINGS = {
247
263
  defaultPercentage: null,
248
264
  periodType: null
249
265
  };
250
- var DEFAULT_BUSINESS_MODULES = {
251
- draftErrands: true,
252
- team: true,
253
- maintenance: true,
254
- fuelLogs: true,
255
- invoices: true,
256
- remittances: true
257
- };
266
+ var DEFAULT_BUSINESS_MODULES = {};
258
267
  var DEFAULT_BUSINESS_SETTINGS = {
259
- whatsapp_notification_enabled: true,
268
+ whatsappNotificationEnabled: true,
260
269
  whatsapp: {
261
270
  enabled: false,
262
271
  templates: {}
263
272
  },
264
- is_online: true,
265
- opening_hours: {
273
+ isOnline: true,
274
+ openingHours: {
266
275
  monday: { open: "09:00", close: "17:00" },
267
276
  tuesday: { open: "09:00", close: "17:00" },
268
277
  wednesday: { open: "09:00", close: "17:00" },
@@ -271,7 +280,7 @@ var DEFAULT_BUSINESS_SETTINGS = {
271
280
  saturday: null,
272
281
  sunday: null
273
282
  },
274
- social_links: {
283
+ socialLinks: {
275
284
  instagram: null,
276
285
  facebook: null,
277
286
  twitter: null,
@@ -355,8 +364,10 @@ export {
355
364
  AuthType,
356
365
  BusinessCapability,
357
366
  BusinessCourierLinkStatus,
367
+ BusinessPlan,
358
368
  BusinessRole,
359
369
  BusinessStatus,
370
+ BusinessType,
360
371
  DEFAULT_BUSINESS_FUEL_SETTINGS,
361
372
  DEFAULT_BUSINESS_MODULES,
362
373
  DEFAULT_BUSINESS_RIDER_PAY_SETTINGS,
@@ -364,6 +375,7 @@ export {
364
375
  DeliveryStatus,
365
376
  DraftErrandStatus,
366
377
  EnterpriseType,
378
+ ErrandFulfilment,
367
379
  ErrandInvoiceState,
368
380
  ErrandStatus,
369
381
  FeePaymentStatus,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mydoormot/app-types",
3
- "version": "2.0.6",
3
+ "version": "2.1.1",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
package/src/business.ts CHANGED
@@ -5,10 +5,64 @@ import {
5
5
  User,
6
6
  } from '.';
7
7
 
8
+ /**
9
+ * @deprecated Retired. `SELF_FULFILLMENT` asked "may this business use its own
10
+ * rider instead of ours?" — a question that only makes sense when
11
+ * self-fulfilment is the exception. Every merchant has riders, so the flag was
12
+ * true for everyone and said nothing.
13
+ *
14
+ * What replaced it: the `riders` module for whether the business manages its
15
+ * own riders at all, and {@link ErrandFulfilment} on each errand for who
16
+ * actually carried it. A restaurant with two riders still overflows to the
17
+ * network on a busy Friday, which a business-level boolean cannot express and
18
+ * an errand-level field can — and the errand-level one is what rider-cost
19
+ * reporting needs.
20
+ */
8
21
  export enum BusinessCapability {
9
22
  SELF_FULFILLMENT = 'self_fulfillment',
10
23
  }
11
24
 
25
+
26
+ /**
27
+ * Who carried an errand: the originating business's own rider, or the wider
28
+ * network. The field rider-cost reporting splits on — own-rider cost against
29
+ * network payout.
30
+ */
31
+ export enum ErrandFulfilment {
32
+ OWN = 'own',
33
+ NETWORK = 'network',
34
+ }
35
+
36
+ /**
37
+ * Which product a business is using. The one stored fact about its shape —
38
+ * a courier runs deliveries for other businesses, a merchant sends its own out.
39
+ *
40
+ * Replaces the free-text business-category collection, whose only reader was a
41
+ * `name.includes('courier')` string match: a category rename silently reshaped
42
+ * the account, and five of the seven call sites omitted `toLowerCase()` so a
43
+ * capitalised name read as `false` everywhere.
44
+ */
45
+ export enum BusinessType {
46
+ MERCHANT = 'merchant',
47
+ COURIER = 'courier',
48
+ }
49
+
50
+ /**
51
+ * How much of its product a business gets. Orthogonal to {@link BusinessType}:
52
+ * `type` decides which features are even relevant, `plan` decides which of
53
+ * those are unlocked. A merchant's `full` and a courier's `full` are different
54
+ * sets, which is the point — upgrading a restaurant must never hand it
55
+ * client-invoicing.
56
+ *
57
+ * `internal` is where new work lands: features default to it alone, so nothing
58
+ * reaches customers by someone forgetting to hide it.
59
+ */
60
+ export enum BusinessPlan {
61
+ MVP = 'mvp',
62
+ FULL = 'full',
63
+ INTERNAL = 'internal',
64
+ }
65
+
12
66
  export enum BusinessStatus {
13
67
  ACTIVE = 'active',
14
68
  DISABLED = 'disabled',
@@ -20,6 +74,8 @@ export interface Business {
20
74
  name: string;
21
75
  description: string;
22
76
  officeNumber: string;
77
+ type: BusinessType | `${BusinessType}`;
78
+ plan: BusinessPlan | `${BusinessPlan}`;
23
79
  categoryId: string;
24
80
  address: string | NullOrUndefined;
25
81
  addressCoordinates:
@@ -57,8 +113,13 @@ export interface Business {
57
113
  updatedAt: string | NullOrUndefined | Date;
58
114
  verifiedAt: string | NullOrUndefined | Date;
59
115
  registrationCompletedAt: string | NullOrUndefined | Date;
116
+ /**
117
+ * Derived from `type`, not stored. Kept on the wire because installed mobile
118
+ * binaries still read it; new readers want `type`.
119
+ *
120
+ * @deprecated Read `type` instead.
121
+ */
60
122
  businessCategoryDetails: BusinessCategory | NullOrUndefined;
61
- capabilities: BusinessCapability[] | NullOrUndefined;
62
123
 
63
124
  status: BusinessStatus | `${BusinessStatus}`;
64
125
  disabledAt: string | NullOrUndefined | Date;
@@ -66,6 +127,13 @@ export interface Business {
66
127
  disabledReason: string | NullOrUndefined;
67
128
 
68
129
  settings: BusinessSettings | NullOrUndefined;
130
+
131
+ /**
132
+ * The resolved feature set — the plan's defaults with this business's own
133
+ * overrides applied. Server-computed; read this, never `settings.modules`,
134
+ * which holds only the deliberate exceptions.
135
+ */
136
+ modules: Required<{ [K in keyof BusinessModules]: boolean }>;
69
137
  }
70
138
 
71
139
  export interface BusinessPg extends Business {
@@ -109,15 +177,60 @@ export interface OpeningHours {
109
177
  close: string;
110
178
  }
111
179
 
180
+ /**
181
+ * Which features a business sees.
182
+ *
183
+ * Every value is optional, and `undefined` means *inherit from the plan* — not
184
+ * `false`. That distinction is the whole point: a stored `true` is a decision
185
+ * somebody made, so the plan can never quietly take it back, while an unset key
186
+ * follows whatever the plan says today. Storing a resolved default would
187
+ * collapse the two and freeze every business on the defaults it was created
188
+ * with.
189
+ *
190
+ * Resolve with `modulesForPlan(type, plan)[key] ?? ...` — never read a key off
191
+ * this object directly.
192
+ */
112
193
  export interface BusinessModules {
113
- draftErrands: boolean;
114
- team: boolean;
115
- maintenance: boolean;
116
- fuelLogs: boolean;
117
- invoices: boolean;
118
- remittances: boolean;
194
+ draftErrands?: boolean;
195
+ maintenance?: boolean;
196
+ fuelLogs?: boolean;
197
+ invoices?: boolean;
198
+ remittances?: boolean;
199
+ /** Manage its own riders: the roster, their pay, what they cost. */
200
+ riders?: boolean;
201
+ /**
202
+ * Route new errands to its own riders rather than to the network.
203
+ *
204
+ * Deliberately separate from `riders`. A merchant can run a roster and still
205
+ * send most deliveries out — managing riders and defaulting to them are
206
+ * different questions, and the old `SELF_FULFILLMENT` capability answered
207
+ * only the second one. Folding them together made every merchant
208
+ * self-fulfil and silently bypass each city's default courier.
209
+ */
210
+ selfFulfilment?: boolean;
211
+ vehicles?: boolean;
212
+ expenses?: boolean;
213
+ /**
214
+ * Calculate what riders earned for a period and generate payout records.
215
+ * `riders/rider-payouts.controller.ts`, and the `rider-payouts` screens.
216
+ */
217
+ riderPayouts?: boolean;
218
+ /** External GPS tracker feed; needs an API key to be useful. */
219
+ trackerDevices?: boolean;
220
+ /**
221
+ * WhatsApp notifications to the business's users and customers on errand
222
+ * events.
223
+ *
224
+ * Declared here so it appears in the plan map and the admin UI, but nothing
225
+ * reads it yet: `updateWhatsappConfig` is still gated on `isOwnFulfiller`.
226
+ * Moving that gate onto this key is the follow-up.
227
+ */
228
+ whatsapp?: boolean;
119
229
  }
120
230
 
231
+ /** Every module key, so a plan map can be checked for completeness. */
232
+ export type BusinessModuleKey = keyof BusinessModules;
233
+
121
234
  /**
122
235
  * How a business funds fuel. `revenuePercent` is the share of errand revenue a
123
236
  * vehicle sets aside for its own fuel — the single knob behind the fuel-owed
@@ -144,10 +257,10 @@ export interface BusinessRiderPaySettings {
144
257
  }
145
258
 
146
259
  export interface BusinessSettings {
147
- whatsapp_notification_enabled: boolean;
260
+ whatsappNotificationEnabled: boolean;
148
261
  whatsapp: BusinessWhatsappConfig;
149
- is_online: boolean;
150
- opening_hours: {
262
+ isOnline: boolean;
263
+ openingHours: {
151
264
  monday: OpeningHours | null;
152
265
  tuesday: OpeningHours | null;
153
266
  wednesday: OpeningHours | null;
@@ -156,18 +269,13 @@ export interface BusinessSettings {
156
269
  saturday: OpeningHours | null;
157
270
  sunday: OpeningHours | null;
158
271
  };
159
- social_links: {
272
+ socialLinks: {
160
273
  instagram: string | null;
161
274
  facebook: string | null;
162
275
  twitter: string | null;
163
276
  tiktok: string | null;
164
277
  website: string | null;
165
278
  };
166
- limits?: {
167
- maxRiders: number | null;
168
- maxVehicles: number | null;
169
- maxErrands: number | null;
170
- };
171
279
  modules: BusinessModules;
172
280
  fuel?: BusinessFuelSettings;
173
281
  riderPay?: BusinessRiderPaySettings;
@@ -182,23 +290,25 @@ export const DEFAULT_BUSINESS_RIDER_PAY_SETTINGS: BusinessRiderPaySettings = {
182
290
  periodType: null,
183
291
  };
184
292
 
185
- export const DEFAULT_BUSINESS_MODULES: BusinessModules = {
186
- draftErrands: true,
187
- team: true,
188
- maintenance: true,
189
- fuelLogs: true,
190
- invoices: true,
191
- remittances: true,
192
- };
293
+ /**
294
+ * @deprecated Defaults live in `modulesForPlan(type, plan)` on the server. This
295
+ * was an all-`true` deny-list: every new feature shipped to every business
296
+ * until someone remembered to switch it off, and writing it into each new
297
+ * business made the stored value indistinguishable from a deliberate grant.
298
+ *
299
+ * Kept only so nothing importing it breaks mid-migration. Empty on purpose —
300
+ * unset means inherit.
301
+ */
302
+ export const DEFAULT_BUSINESS_MODULES: BusinessModules = {};
193
303
 
194
304
  export const DEFAULT_BUSINESS_SETTINGS: BusinessSettings = {
195
- whatsapp_notification_enabled: true,
305
+ whatsappNotificationEnabled: true,
196
306
  whatsapp: {
197
307
  enabled: false,
198
308
  templates: {},
199
309
  },
200
- is_online: true,
201
- opening_hours: {
310
+ isOnline: true,
311
+ openingHours: {
202
312
  monday: { open: '09:00', close: '17:00' },
203
313
  tuesday: { open: '09:00', close: '17:00' },
204
314
  wednesday: { open: '09:00', close: '17:00' },
@@ -207,7 +317,7 @@ export const DEFAULT_BUSINESS_SETTINGS: BusinessSettings = {
207
317
  saturday: null,
208
318
  sunday: null,
209
319
  },
210
- social_links: {
320
+ socialLinks: {
211
321
  instagram: null,
212
322
  facebook: null,
213
323
  twitter: null,