@mydoormot/app-types 2.0.6 → 2.1.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,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.1 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.94 KB
12
+ ESM ⚡️ Build success in 161ms
13
+ CJS dist/index.cjs 17.98 KB
14
+ CJS ⚡️ Build success in 171ms
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 737ms
17
+ DTS dist/index.d.ts 56.99 KB
18
+ DTS dist/index.d.cts 56.99 KB
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @mydoormot/app-types
2
2
 
3
+ ## 2.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Aded moduleStates
8
+
9
+ ## 2.1.1
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated business schema
14
+
3
15
  ## 2.0.6
4
16
 
5
17
  ### 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,23 @@ 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["NONE"] = "none";
309
+ BusinessPlan2["MVP"] = "mvp";
310
+ BusinessPlan2["FULL"] = "full";
311
+ BusinessPlan2["INTERNAL"] = "internal";
312
+ return BusinessPlan2;
313
+ })(BusinessPlan || {});
294
314
  var BusinessStatus = /* @__PURE__ */ ((BusinessStatus2) => {
295
315
  BusinessStatus2["ACTIVE"] = "active";
296
316
  BusinessStatus2["DISABLED"] = "disabled";
@@ -316,22 +336,15 @@ var DEFAULT_BUSINESS_RIDER_PAY_SETTINGS = {
316
336
  defaultPercentage: null,
317
337
  periodType: null
318
338
  };
319
- var DEFAULT_BUSINESS_MODULES = {
320
- draftErrands: true,
321
- team: true,
322
- maintenance: true,
323
- fuelLogs: true,
324
- invoices: true,
325
- remittances: true
326
- };
339
+ var DEFAULT_BUSINESS_MODULES = {};
327
340
  var DEFAULT_BUSINESS_SETTINGS = {
328
- whatsapp_notification_enabled: true,
341
+ whatsappNotificationEnabled: true,
329
342
  whatsapp: {
330
343
  enabled: false,
331
344
  templates: {}
332
345
  },
333
- is_online: true,
334
- opening_hours: {
346
+ isOnline: true,
347
+ openingHours: {
335
348
  monday: { open: "09:00", close: "17:00" },
336
349
  tuesday: { open: "09:00", close: "17:00" },
337
350
  wednesday: { open: "09:00", close: "17:00" },
@@ -340,7 +353,7 @@ var DEFAULT_BUSINESS_SETTINGS = {
340
353
  saturday: null,
341
354
  sunday: null
342
355
  },
343
- social_links: {
356
+ socialLinks: {
344
357
  instagram: null,
345
358
  facebook: null,
346
359
  twitter: null,
@@ -425,8 +438,10 @@ var LinkDestination = /* @__PURE__ */ ((LinkDestination2) => {
425
438
  AuthType,
426
439
  BusinessCapability,
427
440
  BusinessCourierLinkStatus,
441
+ BusinessPlan,
428
442
  BusinessRole,
429
443
  BusinessStatus,
444
+ BusinessType,
430
445
  DEFAULT_BUSINESS_FUEL_SETTINGS,
431
446
  DEFAULT_BUSINESS_MODULES,
432
447
  DEFAULT_BUSINESS_RIDER_PAY_SETTINGS,
@@ -434,6 +449,7 @@ var LinkDestination = /* @__PURE__ */ ((LinkDestination2) => {
434
449
  DeliveryStatus,
435
450
  DraftErrandStatus,
436
451
  EnterpriseType,
452
+ ErrandFulfilment,
437
453
  ErrandInvoiceState,
438
454
  ErrandStatus,
439
455
  FeePaymentStatus,
package/dist/index.d.cts CHANGED
@@ -309,9 +309,85 @@ 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
+ /**
362
+ * No tier at all — every module falls to its default of off.
363
+ *
364
+ * For a business that has bought nothing, or whose access is being pulled
365
+ * without deleting anything. Per-business overrides in `settings.modules`
366
+ * still apply on top: an override is a deliberate grant, and a plan change
367
+ * must not silently revoke one. For a hard cut-off use `BusinessStatus`.
368
+ */
369
+ NONE = "none",
370
+ MVP = "mvp",
371
+ FULL = "full",
372
+ INTERNAL = "internal"
373
+ }
374
+ /**
375
+ * What a module looks like to one business.
376
+ *
377
+ * The distinction `modules` alone cannot make. A boolean says only on or off,
378
+ * so a dashboard reading it hides everything that is off — including things
379
+ * the business could have, which is how a feature disappears instead of
380
+ * inviting an upgrade.
381
+ *
382
+ * - `available` — they have it.
383
+ * - `locked` — real for this kind of business, their tier does not include
384
+ * it. Show the screen, show the pitch. This is the upsell.
385
+ * - `hidden` — no tier for their type ever grants it. A restaurant is not
386
+ * a lapsed courier; offering to sell them client-invoicing is
387
+ * noise.
388
+ */
389
+ type ModuleState = 'available' | 'locked' | 'hidden';
390
+ type BusinessModuleStates = Record<keyof BusinessModules, ModuleState>;
315
391
  declare enum BusinessStatus {
316
392
  ACTIVE = "active",
317
393
  DISABLED = "disabled"
@@ -322,6 +398,8 @@ interface Business {
322
398
  name: string;
323
399
  description: string;
324
400
  officeNumber: string;
401
+ type: BusinessType | `${BusinessType}`;
402
+ plan: BusinessPlan | `${BusinessPlan}`;
325
403
  categoryId: string;
326
404
  address: string | NullOrUndefined;
327
405
  addressCoordinates: number[] | NullOrUndefined | {
@@ -351,13 +429,33 @@ interface Business {
351
429
  updatedAt: string | NullOrUndefined | Date;
352
430
  verifiedAt: string | NullOrUndefined | Date;
353
431
  registrationCompletedAt: string | NullOrUndefined | Date;
432
+ /**
433
+ * Derived from `type`, not stored. Kept on the wire because installed mobile
434
+ * binaries still read it; new readers want `type`.
435
+ *
436
+ * @deprecated Read `type` instead.
437
+ */
354
438
  businessCategoryDetails: BusinessCategory | NullOrUndefined;
355
- capabilities: BusinessCapability[] | NullOrUndefined;
356
439
  status: BusinessStatus | `${BusinessStatus}`;
357
440
  disabledAt: string | NullOrUndefined | Date;
358
441
  disabledBy: string | NullOrUndefined;
359
442
  disabledReason: string | NullOrUndefined;
360
443
  settings: BusinessSettings | NullOrUndefined;
444
+ /**
445
+ * The resolved feature set — the plan's defaults with this business's own
446
+ * overrides applied. Server-computed; read this, never `settings.modules`,
447
+ * which holds only the deliberate exceptions.
448
+ */
449
+ modules: Required<{
450
+ [K in keyof BusinessModules]: boolean;
451
+ }>;
452
+ /**
453
+ * Per module: available, locked, or hidden. Render from this, not from
454
+ * `modules` — a boolean cannot tell "you don't have this yet" apart from
455
+ * "this isn't for you", and hiding the first kind is how a customer never
456
+ * learns the feature exists.
457
+ */
458
+ moduleStates: BusinessModuleStates;
361
459
  }
362
460
  interface BusinessPg extends Business {
363
461
  pgId: any;
@@ -392,14 +490,58 @@ interface OpeningHours {
392
490
  open: string;
393
491
  close: string;
394
492
  }
493
+ /**
494
+ * Which features a business sees.
495
+ *
496
+ * Every value is optional, and `undefined` means *inherit from the plan* — not
497
+ * `false`. That distinction is the whole point: a stored `true` is a decision
498
+ * somebody made, so the plan can never quietly take it back, while an unset key
499
+ * follows whatever the plan says today. Storing a resolved default would
500
+ * collapse the two and freeze every business on the defaults it was created
501
+ * with.
502
+ *
503
+ * Resolve with `modulesForPlan(type, plan)[key] ?? ...` — never read a key off
504
+ * this object directly.
505
+ */
395
506
  interface BusinessModules {
396
- draftErrands: boolean;
397
- team: boolean;
398
- maintenance: boolean;
399
- fuelLogs: boolean;
400
- invoices: boolean;
401
- remittances: boolean;
507
+ draftErrands?: boolean;
508
+ maintenance?: boolean;
509
+ fuelLogs?: boolean;
510
+ invoices?: boolean;
511
+ remittances?: boolean;
512
+ /** Manage its own riders: the roster, their pay, what they cost. */
513
+ riders?: boolean;
514
+ /**
515
+ * Route new errands to its own riders rather than to the network.
516
+ *
517
+ * Deliberately separate from `riders`. A merchant can run a roster and still
518
+ * send most deliveries out — managing riders and defaulting to them are
519
+ * different questions, and the old `SELF_FULFILLMENT` capability answered
520
+ * only the second one. Folding them together made every merchant
521
+ * self-fulfil and silently bypass each city's default courier.
522
+ */
523
+ selfFulfilment?: boolean;
524
+ vehicles?: boolean;
525
+ expenses?: boolean;
526
+ /**
527
+ * Calculate what riders earned for a period and generate payout records.
528
+ * `riders/rider-payouts.controller.ts`, and the `rider-payouts` screens.
529
+ */
530
+ riderPayouts?: boolean;
531
+ /** External GPS tracker feed; needs an API key to be useful. */
532
+ trackerDevices?: boolean;
533
+ /**
534
+ * WhatsApp notifications to the business's users and customers on errand
535
+ * events.
536
+ *
537
+ * Declared here so it appears in the plan map and the admin UI, but nothing
538
+ * reads it yet: `updateWhatsappConfig` is still gated on `isOwnFulfiller`.
539
+ * Moving that gate onto this key is the follow-up.
540
+ */
541
+ whatsapp?: boolean;
402
542
  }
543
+ /** Every module key, so a plan map can be checked for completeness. */
544
+ type BusinessModuleKey = keyof BusinessModules;
403
545
  /**
404
546
  * How a business funds fuel. `revenuePercent` is the share of errand revenue a
405
547
  * vehicle sets aside for its own fuel — the single knob behind the fuel-owed
@@ -424,10 +566,10 @@ interface BusinessRiderPaySettings {
424
566
  periodType: PayoutPeriodType | `${PayoutPeriodType}` | null;
425
567
  }
426
568
  interface BusinessSettings {
427
- whatsapp_notification_enabled: boolean;
569
+ whatsappNotificationEnabled: boolean;
428
570
  whatsapp: BusinessWhatsappConfig;
429
- is_online: boolean;
430
- opening_hours: {
571
+ isOnline: boolean;
572
+ openingHours: {
431
573
  monday: OpeningHours | null;
432
574
  tuesday: OpeningHours | null;
433
575
  wednesday: OpeningHours | null;
@@ -436,24 +578,28 @@ interface BusinessSettings {
436
578
  saturday: OpeningHours | null;
437
579
  sunday: OpeningHours | null;
438
580
  };
439
- social_links: {
581
+ socialLinks: {
440
582
  instagram: string | null;
441
583
  facebook: string | null;
442
584
  twitter: string | null;
443
585
  tiktok: string | null;
444
586
  website: string | null;
445
587
  };
446
- limits?: {
447
- maxRiders: number | null;
448
- maxVehicles: number | null;
449
- maxErrands: number | null;
450
- };
451
588
  modules: BusinessModules;
452
589
  fuel?: BusinessFuelSettings;
453
590
  riderPay?: BusinessRiderPaySettings;
454
591
  }
455
592
  declare const DEFAULT_BUSINESS_FUEL_SETTINGS: BusinessFuelSettings;
456
593
  declare const DEFAULT_BUSINESS_RIDER_PAY_SETTINGS: BusinessRiderPaySettings;
594
+ /**
595
+ * @deprecated Defaults live in `modulesForPlan(type, plan)` on the server. This
596
+ * was an all-`true` deny-list: every new feature shipped to every business
597
+ * until someone remembered to switch it off, and writing it into each new
598
+ * business made the stored value indistinguishable from a deliberate grant.
599
+ *
600
+ * Kept only so nothing importing it breaks mid-migration. Empty on purpose —
601
+ * unset means inherit.
602
+ */
457
603
  declare const DEFAULT_BUSINESS_MODULES: BusinessModules;
458
604
  declare const DEFAULT_BUSINESS_SETTINGS: BusinessSettings;
459
605
  interface BusinessMember {
@@ -1723,4 +1869,4 @@ declare enum LinkDestination {
1723
1869
  }
1724
1870
  type NullOrUndefined = null | undefined;
1725
1871
 
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 };
1872
+ 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 BusinessModuleStates, 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 ModuleState, 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,85 @@ 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
+ /**
362
+ * No tier at all — every module falls to its default of off.
363
+ *
364
+ * For a business that has bought nothing, or whose access is being pulled
365
+ * without deleting anything. Per-business overrides in `settings.modules`
366
+ * still apply on top: an override is a deliberate grant, and a plan change
367
+ * must not silently revoke one. For a hard cut-off use `BusinessStatus`.
368
+ */
369
+ NONE = "none",
370
+ MVP = "mvp",
371
+ FULL = "full",
372
+ INTERNAL = "internal"
373
+ }
374
+ /**
375
+ * What a module looks like to one business.
376
+ *
377
+ * The distinction `modules` alone cannot make. A boolean says only on or off,
378
+ * so a dashboard reading it hides everything that is off — including things
379
+ * the business could have, which is how a feature disappears instead of
380
+ * inviting an upgrade.
381
+ *
382
+ * - `available` — they have it.
383
+ * - `locked` — real for this kind of business, their tier does not include
384
+ * it. Show the screen, show the pitch. This is the upsell.
385
+ * - `hidden` — no tier for their type ever grants it. A restaurant is not
386
+ * a lapsed courier; offering to sell them client-invoicing is
387
+ * noise.
388
+ */
389
+ type ModuleState = 'available' | 'locked' | 'hidden';
390
+ type BusinessModuleStates = Record<keyof BusinessModules, ModuleState>;
315
391
  declare enum BusinessStatus {
316
392
  ACTIVE = "active",
317
393
  DISABLED = "disabled"
@@ -322,6 +398,8 @@ interface Business {
322
398
  name: string;
323
399
  description: string;
324
400
  officeNumber: string;
401
+ type: BusinessType | `${BusinessType}`;
402
+ plan: BusinessPlan | `${BusinessPlan}`;
325
403
  categoryId: string;
326
404
  address: string | NullOrUndefined;
327
405
  addressCoordinates: number[] | NullOrUndefined | {
@@ -351,13 +429,33 @@ interface Business {
351
429
  updatedAt: string | NullOrUndefined | Date;
352
430
  verifiedAt: string | NullOrUndefined | Date;
353
431
  registrationCompletedAt: string | NullOrUndefined | Date;
432
+ /**
433
+ * Derived from `type`, not stored. Kept on the wire because installed mobile
434
+ * binaries still read it; new readers want `type`.
435
+ *
436
+ * @deprecated Read `type` instead.
437
+ */
354
438
  businessCategoryDetails: BusinessCategory | NullOrUndefined;
355
- capabilities: BusinessCapability[] | NullOrUndefined;
356
439
  status: BusinessStatus | `${BusinessStatus}`;
357
440
  disabledAt: string | NullOrUndefined | Date;
358
441
  disabledBy: string | NullOrUndefined;
359
442
  disabledReason: string | NullOrUndefined;
360
443
  settings: BusinessSettings | NullOrUndefined;
444
+ /**
445
+ * The resolved feature set — the plan's defaults with this business's own
446
+ * overrides applied. Server-computed; read this, never `settings.modules`,
447
+ * which holds only the deliberate exceptions.
448
+ */
449
+ modules: Required<{
450
+ [K in keyof BusinessModules]: boolean;
451
+ }>;
452
+ /**
453
+ * Per module: available, locked, or hidden. Render from this, not from
454
+ * `modules` — a boolean cannot tell "you don't have this yet" apart from
455
+ * "this isn't for you", and hiding the first kind is how a customer never
456
+ * learns the feature exists.
457
+ */
458
+ moduleStates: BusinessModuleStates;
361
459
  }
362
460
  interface BusinessPg extends Business {
363
461
  pgId: any;
@@ -392,14 +490,58 @@ interface OpeningHours {
392
490
  open: string;
393
491
  close: string;
394
492
  }
493
+ /**
494
+ * Which features a business sees.
495
+ *
496
+ * Every value is optional, and `undefined` means *inherit from the plan* — not
497
+ * `false`. That distinction is the whole point: a stored `true` is a decision
498
+ * somebody made, so the plan can never quietly take it back, while an unset key
499
+ * follows whatever the plan says today. Storing a resolved default would
500
+ * collapse the two and freeze every business on the defaults it was created
501
+ * with.
502
+ *
503
+ * Resolve with `modulesForPlan(type, plan)[key] ?? ...` — never read a key off
504
+ * this object directly.
505
+ */
395
506
  interface BusinessModules {
396
- draftErrands: boolean;
397
- team: boolean;
398
- maintenance: boolean;
399
- fuelLogs: boolean;
400
- invoices: boolean;
401
- remittances: boolean;
507
+ draftErrands?: boolean;
508
+ maintenance?: boolean;
509
+ fuelLogs?: boolean;
510
+ invoices?: boolean;
511
+ remittances?: boolean;
512
+ /** Manage its own riders: the roster, their pay, what they cost. */
513
+ riders?: boolean;
514
+ /**
515
+ * Route new errands to its own riders rather than to the network.
516
+ *
517
+ * Deliberately separate from `riders`. A merchant can run a roster and still
518
+ * send most deliveries out — managing riders and defaulting to them are
519
+ * different questions, and the old `SELF_FULFILLMENT` capability answered
520
+ * only the second one. Folding them together made every merchant
521
+ * self-fulfil and silently bypass each city's default courier.
522
+ */
523
+ selfFulfilment?: boolean;
524
+ vehicles?: boolean;
525
+ expenses?: boolean;
526
+ /**
527
+ * Calculate what riders earned for a period and generate payout records.
528
+ * `riders/rider-payouts.controller.ts`, and the `rider-payouts` screens.
529
+ */
530
+ riderPayouts?: boolean;
531
+ /** External GPS tracker feed; needs an API key to be useful. */
532
+ trackerDevices?: boolean;
533
+ /**
534
+ * WhatsApp notifications to the business's users and customers on errand
535
+ * events.
536
+ *
537
+ * Declared here so it appears in the plan map and the admin UI, but nothing
538
+ * reads it yet: `updateWhatsappConfig` is still gated on `isOwnFulfiller`.
539
+ * Moving that gate onto this key is the follow-up.
540
+ */
541
+ whatsapp?: boolean;
402
542
  }
543
+ /** Every module key, so a plan map can be checked for completeness. */
544
+ type BusinessModuleKey = keyof BusinessModules;
403
545
  /**
404
546
  * How a business funds fuel. `revenuePercent` is the share of errand revenue a
405
547
  * vehicle sets aside for its own fuel — the single knob behind the fuel-owed
@@ -424,10 +566,10 @@ interface BusinessRiderPaySettings {
424
566
  periodType: PayoutPeriodType | `${PayoutPeriodType}` | null;
425
567
  }
426
568
  interface BusinessSettings {
427
- whatsapp_notification_enabled: boolean;
569
+ whatsappNotificationEnabled: boolean;
428
570
  whatsapp: BusinessWhatsappConfig;
429
- is_online: boolean;
430
- opening_hours: {
571
+ isOnline: boolean;
572
+ openingHours: {
431
573
  monday: OpeningHours | null;
432
574
  tuesday: OpeningHours | null;
433
575
  wednesday: OpeningHours | null;
@@ -436,24 +578,28 @@ interface BusinessSettings {
436
578
  saturday: OpeningHours | null;
437
579
  sunday: OpeningHours | null;
438
580
  };
439
- social_links: {
581
+ socialLinks: {
440
582
  instagram: string | null;
441
583
  facebook: string | null;
442
584
  twitter: string | null;
443
585
  tiktok: string | null;
444
586
  website: string | null;
445
587
  };
446
- limits?: {
447
- maxRiders: number | null;
448
- maxVehicles: number | null;
449
- maxErrands: number | null;
450
- };
451
588
  modules: BusinessModules;
452
589
  fuel?: BusinessFuelSettings;
453
590
  riderPay?: BusinessRiderPaySettings;
454
591
  }
455
592
  declare const DEFAULT_BUSINESS_FUEL_SETTINGS: BusinessFuelSettings;
456
593
  declare const DEFAULT_BUSINESS_RIDER_PAY_SETTINGS: BusinessRiderPaySettings;
594
+ /**
595
+ * @deprecated Defaults live in `modulesForPlan(type, plan)` on the server. This
596
+ * was an all-`true` deny-list: every new feature shipped to every business
597
+ * until someone remembered to switch it off, and writing it into each new
598
+ * business made the stored value indistinguishable from a deliberate grant.
599
+ *
600
+ * Kept only so nothing importing it breaks mid-migration. Empty on purpose —
601
+ * unset means inherit.
602
+ */
457
603
  declare const DEFAULT_BUSINESS_MODULES: BusinessModules;
458
604
  declare const DEFAULT_BUSINESS_SETTINGS: BusinessSettings;
459
605
  interface BusinessMember {
@@ -1723,4 +1869,4 @@ declare enum LinkDestination {
1723
1869
  }
1724
1870
  type NullOrUndefined = null | undefined;
1725
1871
 
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 };
1872
+ 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 BusinessModuleStates, 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 ModuleState, 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,23 @@ 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["NONE"] = "none";
237
+ BusinessPlan2["MVP"] = "mvp";
238
+ BusinessPlan2["FULL"] = "full";
239
+ BusinessPlan2["INTERNAL"] = "internal";
240
+ return BusinessPlan2;
241
+ })(BusinessPlan || {});
225
242
  var BusinessStatus = /* @__PURE__ */ ((BusinessStatus2) => {
226
243
  BusinessStatus2["ACTIVE"] = "active";
227
244
  BusinessStatus2["DISABLED"] = "disabled";
@@ -247,22 +264,15 @@ var DEFAULT_BUSINESS_RIDER_PAY_SETTINGS = {
247
264
  defaultPercentage: null,
248
265
  periodType: null
249
266
  };
250
- var DEFAULT_BUSINESS_MODULES = {
251
- draftErrands: true,
252
- team: true,
253
- maintenance: true,
254
- fuelLogs: true,
255
- invoices: true,
256
- remittances: true
257
- };
267
+ var DEFAULT_BUSINESS_MODULES = {};
258
268
  var DEFAULT_BUSINESS_SETTINGS = {
259
- whatsapp_notification_enabled: true,
269
+ whatsappNotificationEnabled: true,
260
270
  whatsapp: {
261
271
  enabled: false,
262
272
  templates: {}
263
273
  },
264
- is_online: true,
265
- opening_hours: {
274
+ isOnline: true,
275
+ openingHours: {
266
276
  monday: { open: "09:00", close: "17:00" },
267
277
  tuesday: { open: "09:00", close: "17:00" },
268
278
  wednesday: { open: "09:00", close: "17:00" },
@@ -271,7 +281,7 @@ var DEFAULT_BUSINESS_SETTINGS = {
271
281
  saturday: null,
272
282
  sunday: null
273
283
  },
274
- social_links: {
284
+ socialLinks: {
275
285
  instagram: null,
276
286
  facebook: null,
277
287
  twitter: null,
@@ -355,8 +365,10 @@ export {
355
365
  AuthType,
356
366
  BusinessCapability,
357
367
  BusinessCourierLinkStatus,
368
+ BusinessPlan,
358
369
  BusinessRole,
359
370
  BusinessStatus,
371
+ BusinessType,
360
372
  DEFAULT_BUSINESS_FUEL_SETTINGS,
361
373
  DEFAULT_BUSINESS_MODULES,
362
374
  DEFAULT_BUSINESS_RIDER_PAY_SETTINGS,
@@ -364,6 +376,7 @@ export {
364
376
  DeliveryStatus,
365
377
  DraftErrandStatus,
366
378
  EnterpriseType,
379
+ ErrandFulfilment,
367
380
  ErrandInvoiceState,
368
381
  ErrandStatus,
369
382
  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.2",
4
4
  "description": "",
5
5
  "main": "./dist/index.cjs",
6
6
  "module": "./dist/index.js",
package/src/business.ts CHANGED
@@ -5,10 +5,95 @@ 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
+ /**
62
+ * No tier at all — every module falls to its default of off.
63
+ *
64
+ * For a business that has bought nothing, or whose access is being pulled
65
+ * without deleting anything. Per-business overrides in `settings.modules`
66
+ * still apply on top: an override is a deliberate grant, and a plan change
67
+ * must not silently revoke one. For a hard cut-off use `BusinessStatus`.
68
+ */
69
+ NONE = 'none',
70
+ MVP = 'mvp',
71
+ FULL = 'full',
72
+ INTERNAL = 'internal',
73
+ }
74
+
75
+ /**
76
+ * What a module looks like to one business.
77
+ *
78
+ * The distinction `modules` alone cannot make. A boolean says only on or off,
79
+ * so a dashboard reading it hides everything that is off — including things
80
+ * the business could have, which is how a feature disappears instead of
81
+ * inviting an upgrade.
82
+ *
83
+ * - `available` — they have it.
84
+ * - `locked` — real for this kind of business, their tier does not include
85
+ * it. Show the screen, show the pitch. This is the upsell.
86
+ * - `hidden` — no tier for their type ever grants it. A restaurant is not
87
+ * a lapsed courier; offering to sell them client-invoicing is
88
+ * noise.
89
+ */
90
+ export type ModuleState = 'available' | 'locked' | 'hidden';
91
+
92
+ export type BusinessModuleStates = Record<
93
+ keyof BusinessModules,
94
+ ModuleState
95
+ >;
96
+
12
97
  export enum BusinessStatus {
13
98
  ACTIVE = 'active',
14
99
  DISABLED = 'disabled',
@@ -20,6 +105,8 @@ export interface Business {
20
105
  name: string;
21
106
  description: string;
22
107
  officeNumber: string;
108
+ type: BusinessType | `${BusinessType}`;
109
+ plan: BusinessPlan | `${BusinessPlan}`;
23
110
  categoryId: string;
24
111
  address: string | NullOrUndefined;
25
112
  addressCoordinates:
@@ -57,8 +144,13 @@ export interface Business {
57
144
  updatedAt: string | NullOrUndefined | Date;
58
145
  verifiedAt: string | NullOrUndefined | Date;
59
146
  registrationCompletedAt: string | NullOrUndefined | Date;
147
+ /**
148
+ * Derived from `type`, not stored. Kept on the wire because installed mobile
149
+ * binaries still read it; new readers want `type`.
150
+ *
151
+ * @deprecated Read `type` instead.
152
+ */
60
153
  businessCategoryDetails: BusinessCategory | NullOrUndefined;
61
- capabilities: BusinessCapability[] | NullOrUndefined;
62
154
 
63
155
  status: BusinessStatus | `${BusinessStatus}`;
64
156
  disabledAt: string | NullOrUndefined | Date;
@@ -66,6 +158,21 @@ export interface Business {
66
158
  disabledReason: string | NullOrUndefined;
67
159
 
68
160
  settings: BusinessSettings | NullOrUndefined;
161
+
162
+ /**
163
+ * The resolved feature set — the plan's defaults with this business's own
164
+ * overrides applied. Server-computed; read this, never `settings.modules`,
165
+ * which holds only the deliberate exceptions.
166
+ */
167
+ modules: Required<{ [K in keyof BusinessModules]: boolean }>;
168
+
169
+ /**
170
+ * Per module: available, locked, or hidden. Render from this, not from
171
+ * `modules` — a boolean cannot tell "you don't have this yet" apart from
172
+ * "this isn't for you", and hiding the first kind is how a customer never
173
+ * learns the feature exists.
174
+ */
175
+ moduleStates: BusinessModuleStates;
69
176
  }
70
177
 
71
178
  export interface BusinessPg extends Business {
@@ -109,15 +216,60 @@ export interface OpeningHours {
109
216
  close: string;
110
217
  }
111
218
 
219
+ /**
220
+ * Which features a business sees.
221
+ *
222
+ * Every value is optional, and `undefined` means *inherit from the plan* — not
223
+ * `false`. That distinction is the whole point: a stored `true` is a decision
224
+ * somebody made, so the plan can never quietly take it back, while an unset key
225
+ * follows whatever the plan says today. Storing a resolved default would
226
+ * collapse the two and freeze every business on the defaults it was created
227
+ * with.
228
+ *
229
+ * Resolve with `modulesForPlan(type, plan)[key] ?? ...` — never read a key off
230
+ * this object directly.
231
+ */
112
232
  export interface BusinessModules {
113
- draftErrands: boolean;
114
- team: boolean;
115
- maintenance: boolean;
116
- fuelLogs: boolean;
117
- invoices: boolean;
118
- remittances: boolean;
233
+ draftErrands?: boolean;
234
+ maintenance?: boolean;
235
+ fuelLogs?: boolean;
236
+ invoices?: boolean;
237
+ remittances?: boolean;
238
+ /** Manage its own riders: the roster, their pay, what they cost. */
239
+ riders?: boolean;
240
+ /**
241
+ * Route new errands to its own riders rather than to the network.
242
+ *
243
+ * Deliberately separate from `riders`. A merchant can run a roster and still
244
+ * send most deliveries out — managing riders and defaulting to them are
245
+ * different questions, and the old `SELF_FULFILLMENT` capability answered
246
+ * only the second one. Folding them together made every merchant
247
+ * self-fulfil and silently bypass each city's default courier.
248
+ */
249
+ selfFulfilment?: boolean;
250
+ vehicles?: boolean;
251
+ expenses?: boolean;
252
+ /**
253
+ * Calculate what riders earned for a period and generate payout records.
254
+ * `riders/rider-payouts.controller.ts`, and the `rider-payouts` screens.
255
+ */
256
+ riderPayouts?: boolean;
257
+ /** External GPS tracker feed; needs an API key to be useful. */
258
+ trackerDevices?: boolean;
259
+ /**
260
+ * WhatsApp notifications to the business's users and customers on errand
261
+ * events.
262
+ *
263
+ * Declared here so it appears in the plan map and the admin UI, but nothing
264
+ * reads it yet: `updateWhatsappConfig` is still gated on `isOwnFulfiller`.
265
+ * Moving that gate onto this key is the follow-up.
266
+ */
267
+ whatsapp?: boolean;
119
268
  }
120
269
 
270
+ /** Every module key, so a plan map can be checked for completeness. */
271
+ export type BusinessModuleKey = keyof BusinessModules;
272
+
121
273
  /**
122
274
  * How a business funds fuel. `revenuePercent` is the share of errand revenue a
123
275
  * vehicle sets aside for its own fuel — the single knob behind the fuel-owed
@@ -144,10 +296,10 @@ export interface BusinessRiderPaySettings {
144
296
  }
145
297
 
146
298
  export interface BusinessSettings {
147
- whatsapp_notification_enabled: boolean;
299
+ whatsappNotificationEnabled: boolean;
148
300
  whatsapp: BusinessWhatsappConfig;
149
- is_online: boolean;
150
- opening_hours: {
301
+ isOnline: boolean;
302
+ openingHours: {
151
303
  monday: OpeningHours | null;
152
304
  tuesday: OpeningHours | null;
153
305
  wednesday: OpeningHours | null;
@@ -156,18 +308,13 @@ export interface BusinessSettings {
156
308
  saturday: OpeningHours | null;
157
309
  sunday: OpeningHours | null;
158
310
  };
159
- social_links: {
311
+ socialLinks: {
160
312
  instagram: string | null;
161
313
  facebook: string | null;
162
314
  twitter: string | null;
163
315
  tiktok: string | null;
164
316
  website: string | null;
165
317
  };
166
- limits?: {
167
- maxRiders: number | null;
168
- maxVehicles: number | null;
169
- maxErrands: number | null;
170
- };
171
318
  modules: BusinessModules;
172
319
  fuel?: BusinessFuelSettings;
173
320
  riderPay?: BusinessRiderPaySettings;
@@ -182,23 +329,25 @@ export const DEFAULT_BUSINESS_RIDER_PAY_SETTINGS: BusinessRiderPaySettings = {
182
329
  periodType: null,
183
330
  };
184
331
 
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
- };
332
+ /**
333
+ * @deprecated Defaults live in `modulesForPlan(type, plan)` on the server. This
334
+ * was an all-`true` deny-list: every new feature shipped to every business
335
+ * until someone remembered to switch it off, and writing it into each new
336
+ * business made the stored value indistinguishable from a deliberate grant.
337
+ *
338
+ * Kept only so nothing importing it breaks mid-migration. Empty on purpose —
339
+ * unset means inherit.
340
+ */
341
+ export const DEFAULT_BUSINESS_MODULES: BusinessModules = {};
193
342
 
194
343
  export const DEFAULT_BUSINESS_SETTINGS: BusinessSettings = {
195
- whatsapp_notification_enabled: true,
344
+ whatsappNotificationEnabled: true,
196
345
  whatsapp: {
197
346
  enabled: false,
198
347
  templates: {},
199
348
  },
200
- is_online: true,
201
- opening_hours: {
349
+ isOnline: true,
350
+ openingHours: {
202
351
  monday: { open: '09:00', close: '17:00' },
203
352
  tuesday: { open: '09:00', close: '17:00' },
204
353
  wednesday: { open: '09:00', close: '17:00' },
@@ -207,7 +356,7 @@ export const DEFAULT_BUSINESS_SETTINGS: BusinessSettings = {
207
356
  saturday: null,
208
357
  sunday: null,
209
358
  },
210
- social_links: {
359
+ socialLinks: {
211
360
  instagram: null,
212
361
  facebook: null,
213
362
  twitter: null,