@bisondesk/core-sdk 1.0.647 → 1.0.649
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.
- package/lib/utils/search.d.ts +3 -3
- package/lib/utils/search.d.ts.map +1 -1
- package/lib/utils/search.js +6 -0
- package/lib/utils/search.js.map +1 -1
- package/package.json +1 -1
- package/src/utils/search.ts +10 -1
- package/tsconfig.tsbuildinfo +1 -1
package/lib/utils/search.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { BusinessEntityIds } from '../constants.js';
|
|
2
|
-
import { Contact, Organization, SearchOrganization } from '../types/crm.js';
|
|
2
|
+
import { Contact, Organization, SearchContact, SearchOrganization } from '../types/crm.js';
|
|
3
3
|
import { LeasingContract } from '../types/leasing.js';
|
|
4
4
|
import { DebtorsDossier, SearchDebtorsDossier } from '../types/leasing-debtors.js';
|
|
5
5
|
import { SearchLeasingContract } from '../types/leasing-search.js';
|
|
6
6
|
import { Opportunity, SearchOpportunity } from '../types/opportunities.js';
|
|
7
7
|
import { SearchTransport, Transport } from '../types/transports.js';
|
|
8
8
|
import { SearchVehicle, Vehicle } from '../types/vehicles.js';
|
|
9
|
-
export type GlobalBusinessEntity = Opportunity | Vehicle | Organization | LeasingContract | DebtorsDossier | Transport;
|
|
10
|
-
export type GlobalSearchEntity = SearchOpportunity | SearchVehicle | SearchOrganization | SearchLeasingContract | SearchDebtorsDossier | SearchTransport;
|
|
9
|
+
export type GlobalBusinessEntity = Opportunity | Vehicle | Organization | Contact | LeasingContract | DebtorsDossier | Transport;
|
|
10
|
+
export type GlobalSearchEntity = SearchOpportunity | SearchVehicle | SearchOrganization | SearchContact | SearchLeasingContract | SearchDebtorsDossier | SearchTransport;
|
|
11
11
|
export declare const getCustomerInformation: (org?: Organization, contact?: Contact) => {
|
|
12
12
|
countryCode: string;
|
|
13
13
|
title: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.d.ts","sourceRoot":"/","sources":["utils/search.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"/","sources":["utils/search.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAC3F,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACnF,OAAO,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE9D,MAAM,MAAM,oBAAoB,GAC5B,WAAW,GACX,OAAO,GACP,YAAY,GACZ,OAAO,GACP,eAAe,GACf,cAAc,GACd,SAAS,CAAC;AACd,MAAM,MAAM,kBAAkB,GAC1B,iBAAiB,GACjB,aAAa,GACb,kBAAkB,GAClB,aAAa,GACb,qBAAqB,GACrB,oBAAoB,GACpB,eAAe,CAAC;AAEpB,eAAO,MAAM,sBAAsB,SAAU,YAAY,YAAY,OAAO;;;;;;;;aAe3E,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE;KACpB,GAAG,IAAI,iBAAiB,CAAC,CAAC,EAAE;QAC3B,aAAa,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,oBAAoB,CAAC;QACrD,QAAQ,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,MAAM,CAAC;QAClC,uBAAuB,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,MAAM,CAAC;QAClD,OAAO,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,MAAM,EAAE,CAAC;QACnC,sBAAsB,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,MAAM,EAAE,CAAC;QACnD,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,MAAM,CAAC;QACzC,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;KAChD;CA6GF,CAAC;AAUF,eAAO,MAAM,wBAAwB,qBACjB,iBAAiB,UAC3B,oBAAoB,KAC3B,MAAM,EAAkD,CAAC;AAE5D,eAAO,MAAM,8BAA8B,qBACvB,iBAAiB,UAC3B,kBAAkB,aAY3B,CAAC;AAEF,eAAO,MAAM,+BAA+B,qBACxB,iBAAiB,UAC3B,oBAAoB,WAC4C,CAAC;AAE3E,eAAO,MAAM,qCAAqC,qBAC9B,iBAAiB,UAC3B,kBAAkB,WAS3B,CAAC;AAEF,eAAO,MAAM,6BAA6B,qBACtB,iBAAiB,UAC3B,kBAAkB,yBAC2B,CAAC;AAExD,eAAO,MAAM,yBAAyB,qBAClB,iBAAiB,UAC3B,oBAAoB,WACoB,CAAC;AAEnD,eAAO,MAAM,+BAA+B,qBACxB,iBAAiB,gBACrB,kBAAkB,WAM/B,CAAC;AAEJ,eAAO,MAAM,wBAAwB,qBACjB,iBAAiB,UAC3B,oBAAoB,oCACqB,CAAC;AAEpD,eAAO,MAAM,8BAA8B,qBACvB,iBAAiB,gBACrB,kBAAkB,oCAK/B,CAAC"}
|
package/lib/utils/search.js
CHANGED
|
@@ -59,6 +59,12 @@ export const mappings = {
|
|
|
59
59
|
getTitle: (org) => org.name,
|
|
60
60
|
getTags: (org) => [`${org.externalId}`, org.vatNumber].filter(Boolean),
|
|
61
61
|
},
|
|
62
|
+
[BusinessEntityIds.Contacts]: {
|
|
63
|
+
getMainEntity: (entity) => entity.contact,
|
|
64
|
+
getTitle: (contact) => [contact.firstName, contact.lastName].filter(Boolean).join(' '),
|
|
65
|
+
getTags: (contact) => [contact.id],
|
|
66
|
+
getDescription: (entity) => entity.org?.name ?? entity.contact.orgName ?? entity.contact.id,
|
|
67
|
+
},
|
|
62
68
|
[BusinessEntityIds.LeasingContracts]: {
|
|
63
69
|
getMainEntity: (entity) => entity.contract,
|
|
64
70
|
getTitle: (contract) => contract.contractNumber ?? contract.id,
|
package/lib/utils/search.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.js","sourceRoot":"/","sources":["utils/search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAwBpD,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,GAAkB,EAAE,OAAiB,EAAE,EAAE;IAC9E,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;QAChB,OAAO;YACL,WAAW,EAAE,GAAG,CAAC,WAAW;YAC5B,KAAK,EAAE,GAAG,CAAC,IAAI;YACf,IAAI,EAAE,GAAG,CAAC,UAAU;SACrB,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;QACpB,OAAO;YACL,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,KAAK,EAAE,CAAC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;SACzE,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,QAAQ,GAUjB;IACF,CAAC,iBAAiB,CAAC,aAAa,CAAC,EAAE;QACjC,aAAa,EAAE,CAAC,MAAyB,EAAE,EAAE,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C,EAChC,EAAE,CACF,UAAU,CAAC,gBAAgB,CAAC,CAAC,uBAAuB,EAAE,CAAC,YAAY,CAAC;IACpE,yBAAyB,CACvB,gBAAgB,EAChB,6BAA6B,CAAC,gBAAgB,EAAE,YAAY,CAAC,CAC9D,CAAC;AAEJ,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACtC,gBAAmC,EACnC,MAA4B,EAC5B,EAAE,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC;AAEpD,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAC5C,gBAAmC,EACnC,YAAgC,EAChC,EAAE,CACF,wBAAwB,CACtB,gBAAgB,EAChB,6BAA6B,CAAC,gBAAgB,EAAE,YAAY,CAAC,CAC9D,CAAC","sourcesContent":["import { joinWithSeparator } from '@bisondesk/commons-sdk/formatting';\nimport { BusinessEntityIds } from '../constants.js';\nimport { Contact, Organization, SearchOrganization } from '../types/crm.js';\nimport { LeasingContract } from '../types/leasing.js';\nimport { DebtorsDossier, SearchDebtorsDossier } from '../types/leasing-debtors.js';\nimport { SearchLeasingContract } from '../types/leasing-search.js';\nimport { Opportunity, SearchOpportunity } from '../types/opportunities.js';\nimport { SearchTransport, Transport } from '../types/transports.js';\nimport { SearchVehicle, Vehicle } from '../types/vehicles.js';\n\nexport type GlobalBusinessEntity =\n | Opportunity\n | Vehicle\n | Organization\n | LeasingContract\n | DebtorsDossier\n | Transport;\nexport type GlobalSearchEntity =\n | SearchOpportunity\n | SearchVehicle\n | SearchOrganization\n | SearchLeasingContract\n | SearchDebtorsDossier\n | SearchTransport;\n\nexport const getCustomerInformation = (org?: Organization, contact?: Contact) => {\n if (org != null) {\n return {\n countryCode: org.countryCode,\n title: org.name,\n code: org.externalId,\n };\n }\n\n if (contact != null) {\n return {\n countryCode: contact.countryCode,\n title: [contact?.firstName, contact?.lastName].filter(Boolean).join(' '),\n };\n }\n};\n\nexport const mappings: {\n [key in BusinessEntityIds]?: {\n getMainEntity: (entity: any) => GlobalBusinessEntity;\n getTitle: (entity: any) => string;\n getTitleForSearchEntity?: (entity: any) => string;\n getTags: (entity: any) => string[];\n getTagsForSearchEntity?: (entity: any) => string[];\n getDescription?: (entity: any) => string;\n getMeta?: (entity: any) => Record<string, any>;\n };\n} = {\n [BusinessEntityIds.Opportunities]: {\n getMainEntity: (entity: SearchOpportunity) => entity.opportunity,\n getTitle: (opp: Opportunity) => opp.id,\n getDescription: (opp: SearchOpportunity) => {\n const customer = getCustomerInformation(opp.org, opp.contact);\n return joinWithSeparator(\n [customer?.code, customer?.title, opp.vehicle?.external.identification.stockNumber].filter(\n Boolean,\n ),\n );\n },\n getTags: (opp: Opportunity) => [opp.id],\n getTagsForSearchEntity: (opp: SearchOpportunity) => {\n const vehicleTags =\n opp.vehicle != null\n ? getTagsForBusinessEntity(BusinessEntityIds.Vehicles, opp.vehicle)\n : [];\n return [...vehicleTags, opp.opportunity.id];\n },\n getMeta: (opp: Opportunity) => ({\n status: opp.status,\n wonAt: opp.wonAt,\n lostAt: opp.lostAt,\n }),\n },\n [BusinessEntityIds.Vehicles]: {\n getMainEntity: (entity: SearchVehicle) => entity.vehicle,\n getTitle: (vehicle: Vehicle) => vehicle.internal.description.title,\n getTags: (vehicle: Vehicle) =>\n [\n // the order of the tags here is relevant for exact integration\n // see: packages/exact/src/service/purchase.ts\n vehicle.external.identification?.stockNumber,\n vehicle.internal.identification?.administrativeNumber,\n vehicle.external.identification?.vin,\n ].filter(Boolean) as string[],\n },\n [BusinessEntityIds.ExternalVehicleSale]: {\n getMainEntity: (entity: SearchVehicle) => entity.vehicle,\n getTitle: (vehicle: Vehicle) => vehicle.internal.description.title,\n getTags: (vehicle: Vehicle) =>\n [\n // the order of the tags here is relevant for exact integration\n // see: packages/exact/src/service/purchase.ts\n vehicle.external.identification?.stockNumber,\n vehicle.internal.identification?.administrativeNumber,\n vehicle.external.identification?.vin,\n ].filter(Boolean) as string[],\n },\n [BusinessEntityIds.Organizations]: {\n getMainEntity: (entity: SearchOrganization) => entity.org,\n getTitle: (org: Organization) => org.name,\n getTags: (org: Organization) =>\n [`${org.externalId}`, org.vatNumber].filter(Boolean) as string[],\n },\n [BusinessEntityIds.LeasingContracts]: {\n getMainEntity: (entity: SearchLeasingContract) => entity.contract,\n getTitle: (contract: LeasingContract) => contract.contractNumber ?? contract.id,\n getTags: (contract: LeasingContract) =>\n [contract.id, contract.contractNumber].filter(Boolean) as string[],\n },\n [BusinessEntityIds.FinanceDocuments]: {\n getMainEntity: (entity: any) => entity.doc,\n getTitle: (entity: any) => entity.doc.reference,\n getTags: (entity: any) => [entity.id],\n },\n [BusinessEntityIds.AdministrativeDocuments]: {\n getMainEntity: (entity: any) => entity.doc,\n getTitle: (entity: any) => entity.doc.category,\n getTags: (entity: any) => [entity.id],\n },\n [BusinessEntityIds.DebtorsDossier]: {\n getMainEntity: (entity: SearchDebtorsDossier) => entity.debtorsDossier,\n getTitle: (dossier: DebtorsDossier) => dossier.id,\n getTags: (dossier: DebtorsDossier) => [dossier.id].filter(Boolean) as string[],\n },\n // A transport on its own knows only ids, so the readable title and description come from the\n // search entity (vehicle + customer). The bare-record variants stay on the id as a fallback.\n [BusinessEntityIds.Transports]: {\n getMainEntity: (entity: SearchTransport) => entity.transport,\n getTitle: (transport: Transport) => transport.id,\n getTitleForSearchEntity: (entity: SearchTransport) =>\n entity.vehicle?.external.identification?.stockNumber ?? entity.transport.id,\n getDescription: (entity: SearchTransport) => {\n const customer = getCustomerInformation(entity.org);\n const parts = [customer?.code, customer?.title].filter(Boolean) as string[];\n // The API rejects an empty association description, so never return one.\n return parts.length > 0 ? joinWithSeparator(parts) : entity.transport.id;\n },\n getTags: (transport: Transport) => [transport.id],\n getTagsForSearchEntity: (entity: SearchTransport) => {\n const vehicleTags =\n entity.vehicle != null\n ? getTagsForBusinessEntity(BusinessEntityIds.Vehicles, entity.vehicle)\n : [];\n return [...vehicleTags, entity.transport.id, entity.transport.opportunityId].filter(\n Boolean,\n ) as string[];\n },\n },\n};\n\nconst getMapping = (businessEntityId: BusinessEntityIds) => {\n const mapping = mappings[businessEntityId];\n if (!mapping) {\n throw new Error(`Invalid business entity id ${businessEntityId}`);\n }\n return mapping;\n};\n\nexport const getTagsForBusinessEntity = (\n businessEntityId: BusinessEntityIds,\n entity: GlobalBusinessEntity,\n): string[] => getMapping(businessEntityId).getTags(entity);\n\nexport const getTagsForSearchBusinessEntity = (\n businessEntityId: BusinessEntityIds,\n entity: GlobalSearchEntity,\n) => {\n const tags = getMapping(businessEntityId).getTagsForSearchEntity?.(entity);\n\n if (tags) {\n return tags;\n }\n\n return getTagsForBusinessEntity(\n businessEntityId,\n getMainEntityFromSearchEntity(businessEntityId, entity),\n );\n};\n\nexport const getDescriptionForBusinessEntity = (\n businessEntityId: BusinessEntityIds,\n entity: GlobalBusinessEntity,\n) => joinWithSeparator(getTagsForBusinessEntity(businessEntityId, entity));\n\nexport const getDescriptionForSearchBusinessEntity = (\n businessEntityId: BusinessEntityIds,\n entity: GlobalSearchEntity,\n) => {\n return (\n getMapping(businessEntityId).getDescription?.(entity) ??\n getDescriptionForBusinessEntity(\n businessEntityId,\n getMainEntityFromSearchEntity(businessEntityId, entity),\n )\n );\n};\n\nexport const getMainEntityFromSearchEntity = (\n businessEntityId: BusinessEntityIds,\n entity: GlobalSearchEntity,\n) => getMapping(businessEntityId).getMainEntity(entity);\n\nexport const getTitleForBusinessEntity = (\n businessEntityId: BusinessEntityIds,\n entity: GlobalBusinessEntity,\n) => getMapping(businessEntityId).getTitle(entity);\n\nexport const getTitleForSearchBusinessEntity = (\n businessEntityId: BusinessEntityIds,\n searchEntity: GlobalSearchEntity,\n) =>\n getMapping(businessEntityId).getTitleForSearchEntity?.(searchEntity) ??\n getTitleForBusinessEntity(\n businessEntityId,\n getMainEntityFromSearchEntity(businessEntityId, searchEntity),\n );\n\nexport const getMetaForBusinessEntity = (\n businessEntityId: BusinessEntityIds,\n entity: GlobalBusinessEntity,\n) => getMapping(businessEntityId).getMeta?.(entity);\n\nexport const getMetaForSearchBusinessEntity = (\n businessEntityId: BusinessEntityIds,\n searchEntity: GlobalSearchEntity,\n) =>\n getMetaForBusinessEntity(\n businessEntityId,\n getMainEntityFromSearchEntity(businessEntityId, searchEntity),\n );\n"]}
|
|
1
|
+
{"version":3,"file":"search.js","sourceRoot":"/","sources":["utils/search.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AA0BpD,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,GAAkB,EAAE,OAAiB,EAAE,EAAE;IAC9E,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;QAChB,OAAO;YACL,WAAW,EAAE,GAAG,CAAC,WAAW;YAC5B,KAAK,EAAE,GAAG,CAAC,IAAI;YACf,IAAI,EAAE,GAAG,CAAC,UAAU;SACrB,CAAC;IACJ,CAAC;IAED,IAAI,OAAO,IAAI,IAAI,EAAE,CAAC;QACpB,OAAO;YACL,WAAW,EAAE,OAAO,CAAC,WAAW;YAChC,KAAK,EAAE,CAAC,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC;SACzE,CAAC;IACJ,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,QAAQ,GAUjB;IACF,CAAC,iBAAiB,CAAC,aAAa,CAAC,EAAE;QACjC,aAAa,EAAE,CAAC,MAAyB,EAAE,EAAE,CAAC,MAAM,CAAC,WAAW;QAChE,QAAQ,EAAE,CAAC,GAAgB,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE;QACtC,cAAc,EAAE,CAAC,GAAsB,EAAE,EAAE;YACzC,MAAM,QAAQ,GAAG,sBAAsB,CAAC,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,OAAO,CAAC,CAA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,EAAE,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;AAExD,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,gBAAmC,EACnC,MAA4B,EAC5B,EAAE,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;AAEnD,MAAM,CAAC,MAAM,+BAA+B,GAAG,CAC7C,gBAAmC,EACnC,YAAgC,EAChC,EAAE,CACF,UAAU,CAAC,gBAAgB,CAAC,CAAC,uBAAuB,EAAE,CAAC,YAAY,CAAC;IACpE,yBAAyB,CACvB,gBAAgB,EAChB,6BAA6B,CAAC,gBAAgB,EAAE,YAAY,CAAC,CAC9D,CAAC;AAEJ,MAAM,CAAC,MAAM,wBAAwB,GAAG,CACtC,gBAAmC,EACnC,MAA4B,EAC5B,EAAE,CAAC,UAAU,CAAC,gBAAgB,CAAC,CAAC,OAAO,EAAE,CAAC,MAAM,CAAC,CAAC;AAEpD,MAAM,CAAC,MAAM,8BAA8B,GAAG,CAC5C,gBAAmC,EACnC,YAAgC,EAChC,EAAE,CACF,wBAAwB,CACtB,gBAAgB,EAChB,6BAA6B,CAAC,gBAAgB,EAAE,YAAY,CAAC,CAC9D,CAAC","sourcesContent":["import { joinWithSeparator } from '@bisondesk/commons-sdk/formatting';\nimport { BusinessEntityIds } from '../constants.js';\nimport { Contact, Organization, SearchContact, SearchOrganization } from '../types/crm.js';\nimport { LeasingContract } from '../types/leasing.js';\nimport { DebtorsDossier, SearchDebtorsDossier } from '../types/leasing-debtors.js';\nimport { SearchLeasingContract } from '../types/leasing-search.js';\nimport { Opportunity, SearchOpportunity } from '../types/opportunities.js';\nimport { SearchTransport, Transport } from '../types/transports.js';\nimport { SearchVehicle, Vehicle } from '../types/vehicles.js';\n\nexport type GlobalBusinessEntity =\n | Opportunity\n | Vehicle\n | Organization\n | Contact\n | LeasingContract\n | DebtorsDossier\n | Transport;\nexport type GlobalSearchEntity =\n | SearchOpportunity\n | SearchVehicle\n | SearchOrganization\n | SearchContact\n | SearchLeasingContract\n | SearchDebtorsDossier\n | SearchTransport;\n\nexport const getCustomerInformation = (org?: Organization, contact?: Contact) => {\n if (org != null) {\n return {\n countryCode: org.countryCode,\n title: org.name,\n code: org.externalId,\n };\n }\n\n if (contact != null) {\n return {\n countryCode: contact.countryCode,\n title: [contact?.firstName, contact?.lastName].filter(Boolean).join(' '),\n };\n }\n};\n\nexport const mappings: {\n [key in BusinessEntityIds]?: {\n getMainEntity: (entity: any) => GlobalBusinessEntity;\n getTitle: (entity: any) => string;\n getTitleForSearchEntity?: (entity: any) => string;\n getTags: (entity: any) => string[];\n getTagsForSearchEntity?: (entity: any) => string[];\n getDescription?: (entity: any) => string;\n getMeta?: (entity: any) => Record<string, any>;\n };\n} = {\n [BusinessEntityIds.Opportunities]: {\n getMainEntity: (entity: SearchOpportunity) => entity.opportunity,\n getTitle: (opp: Opportunity) => opp.id,\n getDescription: (opp: SearchOpportunity) => {\n const customer = getCustomerInformation(opp.org, opp.contact);\n return joinWithSeparator(\n [customer?.code, customer?.title, opp.vehicle?.external.identification.stockNumber].filter(\n Boolean,\n ),\n );\n },\n getTags: (opp: Opportunity) => [opp.id],\n getTagsForSearchEntity: (opp: SearchOpportunity) => {\n const vehicleTags =\n opp.vehicle != null\n ? getTagsForBusinessEntity(BusinessEntityIds.Vehicles, opp.vehicle)\n : [];\n return [...vehicleTags, opp.opportunity.id];\n },\n getMeta: (opp: Opportunity) => ({\n status: opp.status,\n wonAt: opp.wonAt,\n lostAt: opp.lostAt,\n }),\n },\n [BusinessEntityIds.Vehicles]: {\n getMainEntity: (entity: SearchVehicle) => entity.vehicle,\n getTitle: (vehicle: Vehicle) => vehicle.internal.description.title,\n getTags: (vehicle: Vehicle) =>\n [\n // the order of the tags here is relevant for exact integration\n // see: packages/exact/src/service/purchase.ts\n vehicle.external.identification?.stockNumber,\n vehicle.internal.identification?.administrativeNumber,\n vehicle.external.identification?.vin,\n ].filter(Boolean) as string[],\n },\n [BusinessEntityIds.ExternalVehicleSale]: {\n getMainEntity: (entity: SearchVehicle) => entity.vehicle,\n getTitle: (vehicle: Vehicle) => vehicle.internal.description.title,\n getTags: (vehicle: Vehicle) =>\n [\n // the order of the tags here is relevant for exact integration\n // see: packages/exact/src/service/purchase.ts\n vehicle.external.identification?.stockNumber,\n vehicle.internal.identification?.administrativeNumber,\n vehicle.external.identification?.vin,\n ].filter(Boolean) as string[],\n },\n [BusinessEntityIds.Organizations]: {\n getMainEntity: (entity: SearchOrganization) => entity.org,\n getTitle: (org: Organization) => org.name,\n getTags: (org: Organization) =>\n [`${org.externalId}`, org.vatNumber].filter(Boolean) as string[],\n },\n [BusinessEntityIds.Contacts]: {\n getMainEntity: (entity: SearchContact) => entity.contact,\n getTitle: (contact: Contact) => [contact.firstName, contact.lastName].filter(Boolean).join(' '),\n getTags: (contact: Contact) => [contact.id],\n getDescription: (entity: SearchContact) =>\n entity.org?.name ?? entity.contact.orgName ?? entity.contact.id,\n },\n [BusinessEntityIds.LeasingContracts]: {\n getMainEntity: (entity: SearchLeasingContract) => entity.contract,\n getTitle: (contract: LeasingContract) => contract.contractNumber ?? contract.id,\n getTags: (contract: LeasingContract) =>\n [contract.id, contract.contractNumber].filter(Boolean) as string[],\n },\n [BusinessEntityIds.FinanceDocuments]: {\n getMainEntity: (entity: any) => entity.doc,\n getTitle: (entity: any) => entity.doc.reference,\n getTags: (entity: any) => [entity.id],\n },\n [BusinessEntityIds.AdministrativeDocuments]: {\n getMainEntity: (entity: any) => entity.doc,\n getTitle: (entity: any) => entity.doc.category,\n getTags: (entity: any) => [entity.id],\n },\n [BusinessEntityIds.DebtorsDossier]: {\n getMainEntity: (entity: SearchDebtorsDossier) => entity.debtorsDossier,\n getTitle: (dossier: DebtorsDossier) => dossier.id,\n getTags: (dossier: DebtorsDossier) => [dossier.id].filter(Boolean) as string[],\n },\n // A transport on its own knows only ids, so the readable title and description come from the\n // search entity (vehicle + customer). The bare-record variants stay on the id as a fallback.\n [BusinessEntityIds.Transports]: {\n getMainEntity: (entity: SearchTransport) => entity.transport,\n getTitle: (transport: Transport) => transport.id,\n getTitleForSearchEntity: (entity: SearchTransport) =>\n entity.vehicle?.external.identification?.stockNumber ?? entity.transport.id,\n getDescription: (entity: SearchTransport) => {\n const customer = getCustomerInformation(entity.org);\n const parts = [customer?.code, customer?.title].filter(Boolean) as string[];\n // The API rejects an empty association description, so never return one.\n return parts.length > 0 ? joinWithSeparator(parts) : entity.transport.id;\n },\n getTags: (transport: Transport) => [transport.id],\n getTagsForSearchEntity: (entity: SearchTransport) => {\n const vehicleTags =\n entity.vehicle != null\n ? getTagsForBusinessEntity(BusinessEntityIds.Vehicles, entity.vehicle)\n : [];\n return [...vehicleTags, entity.transport.id, entity.transport.opportunityId].filter(\n Boolean,\n ) as string[];\n },\n },\n};\n\nconst getMapping = (businessEntityId: BusinessEntityIds) => {\n const mapping = mappings[businessEntityId];\n if (!mapping) {\n throw new Error(`Invalid business entity id ${businessEntityId}`);\n }\n return mapping;\n};\n\nexport const getTagsForBusinessEntity = (\n businessEntityId: BusinessEntityIds,\n entity: GlobalBusinessEntity,\n): string[] => getMapping(businessEntityId).getTags(entity);\n\nexport const getTagsForSearchBusinessEntity = (\n businessEntityId: BusinessEntityIds,\n entity: GlobalSearchEntity,\n) => {\n const tags = getMapping(businessEntityId).getTagsForSearchEntity?.(entity);\n\n if (tags) {\n return tags;\n }\n\n return getTagsForBusinessEntity(\n businessEntityId,\n getMainEntityFromSearchEntity(businessEntityId, entity),\n );\n};\n\nexport const getDescriptionForBusinessEntity = (\n businessEntityId: BusinessEntityIds,\n entity: GlobalBusinessEntity,\n) => joinWithSeparator(getTagsForBusinessEntity(businessEntityId, entity));\n\nexport const getDescriptionForSearchBusinessEntity = (\n businessEntityId: BusinessEntityIds,\n entity: GlobalSearchEntity,\n) => {\n return (\n getMapping(businessEntityId).getDescription?.(entity) ??\n getDescriptionForBusinessEntity(\n businessEntityId,\n getMainEntityFromSearchEntity(businessEntityId, entity),\n )\n );\n};\n\nexport const getMainEntityFromSearchEntity = (\n businessEntityId: BusinessEntityIds,\n entity: GlobalSearchEntity,\n) => getMapping(businessEntityId).getMainEntity(entity);\n\nexport const getTitleForBusinessEntity = (\n businessEntityId: BusinessEntityIds,\n entity: GlobalBusinessEntity,\n) => getMapping(businessEntityId).getTitle(entity);\n\nexport const getTitleForSearchBusinessEntity = (\n businessEntityId: BusinessEntityIds,\n searchEntity: GlobalSearchEntity,\n) =>\n getMapping(businessEntityId).getTitleForSearchEntity?.(searchEntity) ??\n getTitleForBusinessEntity(\n businessEntityId,\n getMainEntityFromSearchEntity(businessEntityId, searchEntity),\n );\n\nexport const getMetaForBusinessEntity = (\n businessEntityId: BusinessEntityIds,\n entity: GlobalBusinessEntity,\n) => getMapping(businessEntityId).getMeta?.(entity);\n\nexport const getMetaForSearchBusinessEntity = (\n businessEntityId: BusinessEntityIds,\n searchEntity: GlobalSearchEntity,\n) =>\n getMetaForBusinessEntity(\n businessEntityId,\n getMainEntityFromSearchEntity(businessEntityId, searchEntity),\n );\n"]}
|
package/package.json
CHANGED
package/src/utils/search.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { joinWithSeparator } from '@bisondesk/commons-sdk/formatting';
|
|
2
2
|
import { BusinessEntityIds } from '../constants.js';
|
|
3
|
-
import { Contact, Organization, SearchOrganization } from '../types/crm.js';
|
|
3
|
+
import { Contact, Organization, SearchContact, SearchOrganization } from '../types/crm.js';
|
|
4
4
|
import { LeasingContract } from '../types/leasing.js';
|
|
5
5
|
import { DebtorsDossier, SearchDebtorsDossier } from '../types/leasing-debtors.js';
|
|
6
6
|
import { SearchLeasingContract } from '../types/leasing-search.js';
|
|
@@ -12,6 +12,7 @@ export type GlobalBusinessEntity =
|
|
|
12
12
|
| Opportunity
|
|
13
13
|
| Vehicle
|
|
14
14
|
| Organization
|
|
15
|
+
| Contact
|
|
15
16
|
| LeasingContract
|
|
16
17
|
| DebtorsDossier
|
|
17
18
|
| Transport;
|
|
@@ -19,6 +20,7 @@ export type GlobalSearchEntity =
|
|
|
19
20
|
| SearchOpportunity
|
|
20
21
|
| SearchVehicle
|
|
21
22
|
| SearchOrganization
|
|
23
|
+
| SearchContact
|
|
22
24
|
| SearchLeasingContract
|
|
23
25
|
| SearchDebtorsDossier
|
|
24
26
|
| SearchTransport;
|
|
@@ -106,6 +108,13 @@ export const mappings: {
|
|
|
106
108
|
getTags: (org: Organization) =>
|
|
107
109
|
[`${org.externalId}`, org.vatNumber].filter(Boolean) as string[],
|
|
108
110
|
},
|
|
111
|
+
[BusinessEntityIds.Contacts]: {
|
|
112
|
+
getMainEntity: (entity: SearchContact) => entity.contact,
|
|
113
|
+
getTitle: (contact: Contact) => [contact.firstName, contact.lastName].filter(Boolean).join(' '),
|
|
114
|
+
getTags: (contact: Contact) => [contact.id],
|
|
115
|
+
getDescription: (entity: SearchContact) =>
|
|
116
|
+
entity.org?.name ?? entity.contact.orgName ?? entity.contact.id,
|
|
117
|
+
},
|
|
109
118
|
[BusinessEntityIds.LeasingContracts]: {
|
|
110
119
|
getMainEntity: (entity: SearchLeasingContract) => entity.contract,
|
|
111
120
|
getTitle: (contract: LeasingContract) => contract.contractNumber ?? contract.id,
|