@bisondesk/core-sdk 1.0.677 → 1.0.679

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.
Files changed (159) hide show
  1. package/lib/apis/exchange-rates.d.ts +0 -3
  2. package/lib/apis/exchange-rates.d.ts.map +1 -1
  3. package/lib/apis/exchange-rates.js +0 -29
  4. package/lib/apis/exchange-rates.js.map +1 -1
  5. package/lib/apis/organization-bank-accounts.d.ts +11 -0
  6. package/lib/apis/organization-bank-accounts.d.ts.map +1 -0
  7. package/lib/apis/organization-bank-accounts.js +47 -0
  8. package/lib/apis/organization-bank-accounts.js.map +1 -0
  9. package/lib/types/intercompany-payments.d.ts.map +1 -1
  10. package/lib/types/intercompany-payments.js.map +1 -1
  11. package/lib/types/offers.d.ts +1 -2
  12. package/lib/types/offers.d.ts.map +1 -1
  13. package/lib/types/offers.js.map +1 -1
  14. package/lib/types/opportunities.d.ts +1 -8
  15. package/lib/types/opportunities.d.ts.map +1 -1
  16. package/lib/types/opportunities.js.map +1 -1
  17. package/lib/types/opportunity-payments.d.ts +0 -9
  18. package/lib/types/opportunity-payments.d.ts.map +1 -1
  19. package/lib/types/opportunity-payments.js.map +1 -1
  20. package/lib/types/organization-bank-accounts.d.ts +35 -0
  21. package/lib/types/organization-bank-accounts.d.ts.map +1 -0
  22. package/lib/types/organization-bank-accounts.js +9 -0
  23. package/lib/types/organization-bank-accounts.js.map +1 -0
  24. package/lib/types/payment-exports.d.ts +23 -0
  25. package/lib/types/payment-exports.d.ts.map +1 -0
  26. package/lib/types/payment-exports.js +2 -0
  27. package/lib/types/payment-exports.js.map +1 -0
  28. package/lib/types/tenants.d.ts +1 -1
  29. package/lib/types/tenants.d.ts.map +1 -1
  30. package/lib/types/tenants.js +1 -0
  31. package/lib/types/tenants.js.map +1 -1
  32. package/lib/types/transports.d.ts +1 -1
  33. package/lib/types/transports.d.ts.map +1 -1
  34. package/lib/types/transports.js +1 -1
  35. package/lib/types/transports.js.map +1 -1
  36. package/lib/types/vehicle-purchase-payments.d.ts +52 -8
  37. package/lib/types/vehicle-purchase-payments.d.ts.map +1 -1
  38. package/lib/types/vehicle-purchase-payments.js +6 -0
  39. package/lib/types/vehicle-purchase-payments.js.map +1 -1
  40. package/lib/types/vehicles.d.ts +1 -7
  41. package/lib/types/vehicles.d.ts.map +1 -1
  42. package/lib/types/vehicles.js.map +1 -1
  43. package/lib/utils/organization-bank-accounts.d.ts +3 -0
  44. package/lib/utils/organization-bank-accounts.d.ts.map +1 -0
  45. package/lib/utils/organization-bank-accounts.js +9 -0
  46. package/lib/utils/organization-bank-accounts.js.map +1 -0
  47. package/lib/utils/tenants.d.ts +0 -3
  48. package/lib/utils/tenants.d.ts.map +1 -1
  49. package/lib/utils/tenants.js +0 -3
  50. package/lib/utils/tenants.js.map +1 -1
  51. package/lib/utils/tenants.test.js +1 -27
  52. package/lib/utils/tenants.test.js.map +1 -1
  53. package/lib/utils/transports.d.ts +8 -4
  54. package/lib/utils/transports.d.ts.map +1 -1
  55. package/lib/utils/transports.js +13 -7
  56. package/lib/utils/transports.js.map +1 -1
  57. package/lib/utils/transports.test.d.ts +2 -0
  58. package/lib/utils/transports.test.d.ts.map +1 -0
  59. package/lib/utils/transports.test.js +40 -0
  60. package/lib/utils/transports.test.js.map +1 -0
  61. package/package.json +1 -1
  62. package/src/apis/exchange-rates.ts +0 -49
  63. package/src/apis/organization-bank-accounts.ts +123 -0
  64. package/src/types/intercompany-payments.ts +3 -4
  65. package/src/types/offers.ts +0 -2
  66. package/src/types/opportunities.ts +1 -15
  67. package/src/types/opportunity-payments.ts +0 -23
  68. package/src/types/organization-bank-accounts.ts +56 -0
  69. package/src/types/payment-exports.ts +40 -0
  70. package/src/types/tenants.ts +7 -6
  71. package/src/types/transports.ts +1 -1
  72. package/src/types/vehicle-purchase-payments.ts +114 -13
  73. package/src/types/vehicles.ts +4 -15
  74. package/src/utils/organization-bank-accounts.ts +19 -0
  75. package/src/utils/tenants.test.ts +1 -39
  76. package/src/utils/tenants.ts +0 -17
  77. package/src/utils/transports.test.ts +50 -0
  78. package/src/utils/transports.ts +39 -22
  79. package/tsconfig.tsbuildinfo +1 -1
  80. package/lib/utils/opportunity-payments.d.ts +0 -3
  81. package/lib/utils/opportunity-payments.d.ts.map +0 -1
  82. package/lib/utils/opportunity-payments.js +0 -5
  83. package/lib/utils/opportunity-payments.js.map +0 -1
  84. package/lib/utils/opportunity-payments.test.d.ts +0 -2
  85. package/lib/utils/opportunity-payments.test.d.ts.map +0 -1
  86. package/lib/utils/opportunity-payments.test.js +0 -23
  87. package/lib/utils/opportunity-payments.test.js.map +0 -1
  88. package/src/types/activities.js +0 -13
  89. package/src/types/activities.js.map +0 -1
  90. package/src/types/comparables.js +0 -2
  91. package/src/types/comparables.js.map +0 -1
  92. package/src/types/crm.js +0 -58
  93. package/src/types/crm.js.map +0 -1
  94. package/src/types/dashboard.js +0 -2
  95. package/src/types/dashboard.js.map +0 -1
  96. package/src/types/definitions.js +0 -2
  97. package/src/types/definitions.js.map +0 -1
  98. package/src/types/fields.js +0 -2
  99. package/src/types/fields.js.map +0 -1
  100. package/src/types/insights.js +0 -2
  101. package/src/types/insights.js.map +0 -1
  102. package/src/types/interests.js +0 -6
  103. package/src/types/interests.js.map +0 -1
  104. package/src/types/internal-events.js +0 -18
  105. package/src/types/internal-events.js.map +0 -1
  106. package/src/types/internet-opportunities.js +0 -2
  107. package/src/types/internet-opportunities.js.map +0 -1
  108. package/src/types/internet-vehicles.js +0 -2
  109. package/src/types/internet-vehicles.js.map +0 -1
  110. package/src/types/leasing-administration.js +0 -2
  111. package/src/types/leasing-administration.js.map +0 -1
  112. package/src/types/leasing-debtors.js +0 -2
  113. package/src/types/leasing-debtors.js.map +0 -1
  114. package/src/types/leasing-search.js +0 -2
  115. package/src/types/leasing-search.js.map +0 -1
  116. package/src/types/leasing-settings.js +0 -7
  117. package/src/types/leasing-settings.js.map +0 -1
  118. package/src/types/leasing.js +0 -38
  119. package/src/types/leasing.js.map +0 -1
  120. package/src/types/marketing.js +0 -35
  121. package/src/types/marketing.js.map +0 -1
  122. package/src/types/offers.js +0 -56
  123. package/src/types/opportunities.js +0 -107
  124. package/src/types/opportunities.js.map +0 -1
  125. package/src/types/payments.js +0 -7
  126. package/src/types/picklists.js +0 -2
  127. package/src/types/picklists.js.map +0 -1
  128. package/src/types/quotes.js +0 -42
  129. package/src/types/recently-viewed.js +0 -2
  130. package/src/types/recently-viewed.js.map +0 -1
  131. package/src/types/reservations.js +0 -5
  132. package/src/types/reservations.js.map +0 -1
  133. package/src/types/roi-ratings.js +0 -5
  134. package/src/types/roi-ratings.js.map +0 -1
  135. package/src/types/saved-filters.js +0 -9
  136. package/src/types/saved-filters.js.map +0 -1
  137. package/src/types/search.js +0 -2
  138. package/src/types/search.js.map +0 -1
  139. package/src/types/settings.js +0 -2
  140. package/src/types/settings.js.map +0 -1
  141. package/src/types/templates.js +0 -2
  142. package/src/types/templates.js.map +0 -1
  143. package/src/types/tenants.js +0 -21
  144. package/src/types/tenants.js.map +0 -1
  145. package/src/types/user-performance.js +0 -7
  146. package/src/types/user-performance.js.map +0 -1
  147. package/src/types/utils.js +0 -2
  148. package/src/types/validation.js +0 -2
  149. package/src/types/validation.js.map +0 -1
  150. package/src/types/vehicle-sales.js +0 -6
  151. package/src/types/vehicle-sales.js.map +0 -1
  152. package/src/types/vehicles.js +0 -98
  153. package/src/types/vehicles.js.map +0 -1
  154. package/src/utils/leasing.js +0 -6
  155. package/src/utils/leasing.js.map +0 -1
  156. package/src/utils/opportunities.js +0 -48
  157. package/src/utils/opportunities.js.map +0 -1
  158. package/src/utils/opportunity-payments.test.ts +0 -31
  159. package/src/utils/opportunity-payments.ts +0 -15
@@ -1,11 +1,5 @@
1
1
  import { Branch, Tenant } from '../types/tenants.js';
2
- import {
3
- areBranchesQuoteCompatible,
4
- getBranchAskingVies,
5
- getBranchPaymentCurrencies,
6
- hasForeignPaymentCurrency,
7
- isForeignPaymentCurrency,
8
- } from './tenants.js';
2
+ import { areBranchesQuoteCompatible, getBranchAskingVies } from './tenants.js';
9
3
 
10
4
  const createBranch = (override?: Partial<Branch>): Branch => ({
11
5
  id: 'TTC',
@@ -71,35 +65,3 @@ describe('getBranchAskingVies', () => {
71
65
  expect(getBranchAskingVies(tenantOf([bolivia]), 'BO')).toBeUndefined();
72
66
  });
73
67
  });
74
-
75
- describe('payment currencies of a branch', () => {
76
- const southAmerica = createBranch({
77
- id: 'HPA South America',
78
- paymentCurrencies: ['EUR', 'USD'],
79
- });
80
-
81
- test('a branch without a list is paid in its own currency only', () => {
82
- expect(getBranchPaymentCurrencies(createBranch())).toEqual(['EUR']);
83
- });
84
-
85
- test('a branch with a list is paid in the currencies it lists', () => {
86
- expect(getBranchPaymentCurrencies(southAmerica)).toEqual(['EUR', 'USD']);
87
- });
88
-
89
- test.each([
90
- ['a listed currency other than its own', 'USD', true],
91
- ['its own currency', 'EUR', false],
92
- ['a currency it does not list', 'BOB', false],
93
- ])('%s is a foreign payment currency: %s', (_label, currencyCode, expected) => {
94
- expect(isForeignPaymentCurrency(southAmerica, currencyCode)).toBe(expected);
95
- });
96
-
97
- test('a branch without a list has no foreign payment currency', () => {
98
- expect(isForeignPaymentCurrency(createBranch(), 'USD')).toBe(false);
99
- expect(hasForeignPaymentCurrency(createBranch())).toBe(false);
100
- });
101
-
102
- test('a branch listing another currency has a foreign payment currency', () => {
103
- expect(hasForeignPaymentCurrency(southAmerica)).toBe(true);
104
- });
105
- });
@@ -24,23 +24,6 @@ export const getBranchAskingVies = (tenant: Tenant, branchId?: string): Branch |
24
24
  return europeanBranches.find((branch) => branch.id === branchId) ?? europeanBranches.at(0);
25
25
  };
26
26
 
27
- /** The currencies money moves in at the branch, its own currency included. */
28
- export const getBranchPaymentCurrencies = (branch: Branch): string[] =>
29
- branch.paymentCurrencies ?? [branch.currency];
30
-
31
- /**
32
- * Whether the branch can be paid, price a purchase or receive a supplier invoice in a currency
33
- * other than its own. Its own currency is never a foreign one.
34
- */
35
- export const isForeignPaymentCurrency = (branch: Branch, currencyCode: string): boolean =>
36
- currencyCode !== branch.currency && getBranchPaymentCurrencies(branch).includes(currencyCode);
37
-
38
- /** Whether the branch lists any payment currency other than its own. */
39
- export const hasForeignPaymentCurrency = (branch: Branch): boolean =>
40
- getBranchPaymentCurrencies(branch).some((currencyCode) =>
41
- isForeignPaymentCurrency(branch, currencyCode),
42
- );
43
-
44
27
  /** The source invoices the end customer directly; this branch collects payment and earns
45
28
  * commission (see {@link Branch.dropshipping}). */
46
29
  export const isDropshippingBranch = (branch: Branch): boolean => branch.dropshipping === true;
@@ -0,0 +1,50 @@
1
+ import { BusinessEntityIds } from '../constants.js';
2
+ import { TransportStatus, TransportType } from '../types/transports.js';
3
+ import { VehiclePurchaseLogisticsStatus } from '../types/vehicles.js';
4
+ import { getTransportDocumentOwner, isTransportCompleted } from './transports.js';
5
+
6
+ describe('getTransportDocumentOwner', () => {
7
+ test.each([
8
+ {
9
+ description: 'a sale transport files on its deal',
10
+ transport: { type: TransportType.Sale, vehicleId: 'V1', opportunityId: 'OPP1' },
11
+ expected: { businessEntityId: BusinessEntityIds.Opportunities, recordId: 'OPP1' },
12
+ },
13
+ {
14
+ description: 'a purchase transport files on its vehicle',
15
+ transport: { type: TransportType.Purchase, vehicleId: 'V1' },
16
+ expected: { businessEntityId: BusinessEntityIds.Vehicles, recordId: 'V1' },
17
+ },
18
+ {
19
+ description: 'a sale transport without a deal has no owner',
20
+ transport: { type: TransportType.Sale, vehicleId: 'V1' },
21
+ expected: undefined,
22
+ },
23
+ ])('$description', ({ transport, expected }) => {
24
+ expect(getTransportDocumentOwner(transport)).toEqual(expected);
25
+ });
26
+ });
27
+
28
+ describe('isTransportCompleted', () => {
29
+ test.each([
30
+ { status: TransportStatus.Done, expected: true },
31
+ { status: TransportStatus.OngoingInternal, expected: false },
32
+ ])('a sale transport at $status is completed: $expected', ({ status, expected }) => {
33
+ expect(isTransportCompleted({ type: TransportType.Sale, status }, {})).toBe(expected);
34
+ });
35
+
36
+ test.each([
37
+ { logistics: VehiclePurchaseLogisticsStatus.Arrived, expected: true },
38
+ { logistics: VehiclePurchaseLogisticsStatus.AtOrigin, expected: false },
39
+ ])('a purchase transport whose vehicle is $logistics is completed: $expected', ({
40
+ logistics,
41
+ expected,
42
+ }) => {
43
+ expect(
44
+ isTransportCompleted(
45
+ { type: TransportType.Purchase, status: TransportStatus.OngoingInternal },
46
+ { purchase: { logistics: { status: logistics } } },
47
+ ),
48
+ ).toBe(expected);
49
+ });
50
+ });
@@ -1,7 +1,7 @@
1
+ import { BusinessEntityIds } from '../constants.js';
1
2
  import { PurchaseDeliveryTypes } from '../types/deliveries.js';
2
- import { Opportunity } from '../types/opportunities.js';
3
3
  import { PickFieldIds } from '../types/search.js';
4
- import { SearchTransport, Transport, TransportType } from '../types/transports.js';
4
+ import { SearchTransport, Transport, TransportStatus, TransportType } from '../types/transports.js';
5
5
  import { VehiclePurchase } from '../types/vehicles.js';
6
6
  import { hasPurchaseArrived } from './vehicles.js';
7
7
 
@@ -14,39 +14,56 @@ export const isPurchaseDropOffTransport = (
14
14
  isPurchaseTransport(transport) && transport.delivery.type === PurchaseDeliveryTypes.DROP_OFF;
15
15
 
16
16
  /**
17
- * A transport is finished when the journey it describes has demonstrably happened: the customer has
18
- * the vehicle for a sale delivery, the vehicle is on our park for a purchase. From then on
19
- * the record is history and the server refuses edits to it.
17
+ * A transport is finished when the journey it describes is over. From then on the record is
18
+ * history and the server refuses edits to it.
20
19
  *
21
- * Not the same thing as the transport's own `doneAt`. Delivery can be declared on the opportunity
22
- * (a CMR, a delivery confirmation) and arrival on the purchase, without the transport ever being
23
- * moved — and reversing either of those is what unlocks the transport again, which a status stamped
24
- * on the transport itself could not express.
20
+ * A sale delivery is over when the transport itself is at Done: the transport drives the deal's
21
+ * delivery, not the other way around, so a deal delivered some other way (a CMR or the Deliver
22
+ * action, before that rule) does not lock a transport that never got there. Moving it out of Done
23
+ * unlocks it again.
24
+ *
25
+ * A purchase is over when the vehicle is on our park. The park declares the arrival on the purchase,
26
+ * without the transport ever being moved, and putting the purchase back to At origin is what
27
+ * unlocks the transport again.
25
28
  *
26
29
  * Shared so the board, the drawer and the server all answer the question the same way.
27
30
  */
28
31
  export const isTransportCompleted = (
29
- transport: Pick<Transport, 'type'>,
30
- context: {
31
- opportunity?: Pick<Opportunity, 'deliveredAt'>;
32
- purchase?: { logistics: Pick<VehiclePurchase['logistics'], 'status'> };
33
- },
32
+ transport: Pick<Transport, 'type' | 'status'>,
33
+ context: { purchase?: { logistics: Pick<VehiclePurchase['logistics'], 'status'> } } = {},
34
34
  ): boolean => {
35
35
  if (transport.type === TransportType.Sale) {
36
- return context.opportunity?.deliveredAt != null;
36
+ return transport.status === TransportStatus.Done;
37
37
  }
38
38
 
39
39
  return context.purchase != null && hasPurchaseArrived(context.purchase);
40
40
  };
41
41
 
42
- /** The same question asked of a search document, which already carries both sides. */
42
+ /** The same question asked of a search document, which already carries the purchase. */
43
43
  export const isSearchTransportCompleted = (
44
44
  record: PickFieldIds<
45
45
  SearchTransport,
46
- 'transport.type' | 'opportunity.deliveredAt' | 'purchase.logistics.status'
46
+ 'transport.type' | 'transport.status' | 'purchase.logistics.status'
47
47
  >,
48
- ): boolean =>
49
- isTransportCompleted(record.transport, {
50
- opportunity: record.opportunity,
51
- purchase: record.purchase,
52
- });
48
+ ): boolean => isTransportCompleted(record.transport, { purchase: record.purchase });
49
+
50
+ export type TransportDocumentOwner = {
51
+ businessEntityId: BusinessEntityIds.Opportunities | BusinessEntityIds.Vehicles;
52
+ recordId: string;
53
+ };
54
+
55
+ /**
56
+ * Where a transport's documents are filed. A transport owns none: a sale's belong to the deal and a
57
+ * purchase's to the vehicle, whose purchase tab lists them. Undefined for a sale without a deal.
58
+ */
59
+ export const getTransportDocumentOwner = (
60
+ transport: Pick<Transport, 'type' | 'vehicleId' | 'opportunityId'>,
61
+ ): TransportDocumentOwner | undefined => {
62
+ if (isPurchaseTransport(transport)) {
63
+ return { businessEntityId: BusinessEntityIds.Vehicles, recordId: transport.vehicleId };
64
+ }
65
+
66
+ return transport.opportunityId == null
67
+ ? undefined
68
+ : { businessEntityId: BusinessEntityIds.Opportunities, recordId: transport.opportunityId };
69
+ };