{"version":3,"file":"products-BC2K18Na.js","sources":["../../../../scripts/services/api/products.ts"],"sourcesContent":["import { DotCMSProductLandingPageResponse, DotCMSResponse } from \"interfaces/responses/dotcms-responses\";\r\nimport { BrandsResponse, ProductDetailsAdvisorResponse, ProductDetailsCruiseResponse, ProductDetailsHotelResponse, ProductDetailsTourResponse, ReviewDetailsResponse, ShipDetailsResponse, SupplierDetailResponse } from \"interfaces/responses/product-detail-responses\";\r\nimport { ProductType } from \"interfaces/enums\";\r\nimport { ProductBrandsRequestPayload } from \"interfaces/product\";\r\nimport { getJSON } from \"services/api/request-manager\";\r\nimport { buildPageEndpointUrl, buildSearchEndpointUrl } from \"services/cms/cms\";\r\n\r\n\r\n/**\r\n * Fetches the JSON data for a product landing page by its content identifier.\r\n *\r\n * @param productLandingContentIdentifier - The identifier of the product landing content.\r\n * @returns A promise that resolves to the JSON data of the product landing page.\r\n */\r\nexport function getProductLandingJSON(productLandingContentIdentifier: string): Promise<DotCMSResponse<DotCMSProductLandingPageResponse[]>> {\r\n    return getJSON(buildSearchEndpointUrl({\r\n        contentTypes: [\"ProductLandingPage\"],\r\n        depth: 1,\r\n        limit: 1,\r\n        queryClauses: [\r\n            `+(identifier:${productLandingContentIdentifier})`\r\n        ]\r\n    }));\r\n}\r\n\r\n/**\r\n * Fetches the JSON data for a landing page based on the product type.\r\n *\r\n * @param theProductType - The type of the product.\r\n * @returns A promise that resolves to the JSON data of the landing page.\r\n */\r\nexport function getLandingPageJSON(theProductType: ProductType): Promise<any> {\r\n    return getJSON(buildPageEndpointUrl(`/${theProductType}-landing-page`));\r\n}\r\n\r\n\r\n/**\r\n * Call the product detail endpoint with supplied ID\r\n * @param catalogType\r\n * @param productId\r\n */\r\nexport function getProductDetails(catalogType: ProductType, productId: number): Promise<ProductDetailsAdvisorResponse | ProductDetailsCruiseResponse | ProductDetailsHotelResponse | ProductDetailsTourResponse> {\r\n    return new Promise((resolve, reject) => {\r\n        getJSON(`/travel/api/${catalogType.slice(0, -1)}/${productId}`).then((resultsJSON: ProductDetailsAdvisorResponse | ProductDetailsCruiseResponse | ProductDetailsHotelResponse | ProductDetailsTourResponse) => {\r\n            resolve(resultsJSON);\r\n        }, (error: Error) => {\r\n            reject(error);\r\n        });\r\n    });\r\n}\r\n\r\n/**\r\n * Retrives a set of product reviews\r\n * @param catalogType\r\n * @param companyId - this is the Supplier MEID for hotels, ship ID for ships\r\n * @param startRow\r\n * @param rowsPerPage\r\n */\r\nexport function getProductReviews(catalogType: ProductType, companyId: number, startRow: number, rowsPerPage = 4): Promise<ReviewDetailsResponse> {\r\n    const reviewsParams = {\r\n        Id: companyId,\r\n        ProductType: catalogType.slice(0, -1), // de-pluralize\r\n        RowsPerPage: rowsPerPage,\r\n        StartRow: startRow\r\n    };\r\n    return new Promise((resolve, reject) => {\r\n        getJSON(\"/travel/api/reviews\", reviewsParams).then((resultsJSON: ReviewDetailsResponse) => {\r\n            resolve(resultsJSON);\r\n        }, (error: Error) => {\r\n            reject(error);\r\n        });\r\n    });\r\n}\r\n\r\n\r\n/**\r\n * Call the supplier detail endpoint with supplied ID\r\n * @param supplierId\r\n */\r\nexport function getSupplierDetails(supplierId: number): Promise<SupplierDetailResponse> {\r\n    return new Promise((resolve, reject) => {\r\n        getJSON(`/travel/api/supplier/${supplierId}`).then((resultsJSON: SupplierDetailResponse) => {\r\n            resolve(resultsJSON);\r\n        }, (error: Error) => {\r\n            reject(error);\r\n        });\r\n    });\r\n}\r\n\r\n\r\n\r\n/**\r\n * Call the ship detail endpoint with supplied ID\r\n * @param shipId\r\n */\r\nexport function getShipDetails(shipId: number): Promise<ShipDetailsResponse> {\r\n    return new Promise<ShipDetailsResponse>((resolve, reject) => {\r\n        getJSON(`/travel/api/ship/${shipId}`).then((resultsJSON: ShipDetailsResponse) => {\r\n            resolve(resultsJSON);\r\n        }, (error: Error): void => {\r\n            reject(error);\r\n        });\r\n    });\r\n}\r\n\r\n\r\n\r\n/**\r\n * Call the appropriate product brand endpoint to get a collection of brands\r\n * @param productType\r\n * @param payload\r\n */\r\nexport function getProductBrands(productType: ProductType, payload?: ProductBrandsRequestPayload): Promise<BrandsResponse[]> {\r\n    let apiUrl = \"\";\r\n    if (productType === ProductType.CRUISES) {\r\n        apiUrl = \"/travel/api/cruises/cruise-lines\";\r\n    } else if (productType === ProductType.TOURS) {\r\n        apiUrl = \"/travel/api/tours/suppliers\";\r\n    }\r\n\r\n    return new Promise((resolve, reject) => {\r\n        getJSON<BrandsResponse[], ProductBrandsRequestPayload>(apiUrl, payload).then((brandsJSON) => {\r\n            resolve(brandsJSON);\r\n        }, (error: Error): void => {\r\n            reject(error);\r\n        });\r\n    });\r\n}"],"names":["getProductLandingJSON","productLandingContentIdentifier","getJSON","buildSearchEndpointUrl","getLandingPageJSON","theProductType","buildPageEndpointUrl","getProductDetails","catalogType","productId","resolve","reject","resultsJSON","error","getProductReviews","companyId","startRow","rowsPerPage","reviewsParams","getSupplierDetails","supplierId","getShipDetails","shipId","getProductBrands","productType","payload","apiUrl","ProductType","brandsJSON"],"mappings":"oEAcO,SAASA,EAAsBC,EAAsG,CACxI,OAAOC,EAAQC,EAAuB,CAClC,aAAc,CAAC,oBAAoB,EACnC,MAAO,EACP,MAAO,EACP,aAAc,CACV,gBAAgBF,CAA+B,GACnD,CACH,CAAA,CAAC,CACN,CAQO,SAASG,EAAmBC,EAA2C,CAC1E,OAAOH,EAAQI,EAAqB,IAAID,CAAc,eAAe,CAAC,CAC1E,CAQgB,SAAAE,EAAkBC,EAA0BC,EAAqJ,CAC7M,OAAO,IAAI,QAAQ,CAACC,EAASC,IAAW,CACpCT,EAAQ,eAAeM,EAAY,MAAM,EAAG,EAAE,CAAC,IAAIC,CAAS,EAAE,EAAE,KAAMG,GAAyI,CAC3MF,EAAQE,CAAW,CACvB,EAAIC,GAAiB,CACjBF,EAAOE,CAAK,CAAA,CACf,CAAA,CACJ,CACL,CASO,SAASC,EAAkBN,EAA0BO,EAAmBC,EAAkBC,EAAc,EAAmC,CAC9I,MAA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