@cargochain/sdk-js
Version:
The CargoChain platform allows application developers to build supply chain solutions that enable the secure distribution of cargo information among trusted partners.
281 lines (251 loc) • 9.61 kB
JavaScript
/**
* This class provides all the methods that allows to get the reference data provided
* by the CargoChain API.
*/
class ReferenceDataClient {
constructor(cargoChainClient) {
this._client = cargoChainClient;
}
/**
* Gets all "Bureau International des Containers et du Transport Intermodal (B.I.C.)"
* codes.
* @returns {Promise<Object[]>} An array of BIC Codes.
*/
getBiccodes() {
return this._client._get("/getBiccodes");
}
/**
* Retrieves a specific entry from the "Bureau International des Containers et du Transport
* Intermodal (B.I.C.)" Codes Register.
* @param {string} id - A BIC Code Id.
* @returns {Promise<Object>} The specified BIC code information from
* "Bureau International des Containers et du Transport Intermodal (B.I.C.)"
*/
getBiccode(id) {
return this._client._get("/getBiccodes", { id });
}
/**
* Gets all Cargo Types.
* @returns {Promise<Object[]>} An array of Cargo Types.
*/
getCargoTypes() {
return this._client._get("/getCargoTypes");
}
/**
* Gets a Cargo Type.
* @param {string} id - A Cargo Type Id.
* @returns {Promise<Object>} The specified Cargo Type.
*/
getCargoType(id) {
return this._client._get("/getCargoType", { id });
}
/**
* Checks whether a container number is ISO-6346 compliant.
* @param {string} containerNumber - The Container Number that has to be validated.
* @returns {Promise<Object>} The property IsValid of the result object indicates
* if the container number is valid or not.
*/
validateContainerNumber(containerNumber) {
return this._client._get("/validateContainerNumber", { containerNumber });
}
/**
* Gets the container owner information taken from the "Bureau International des
* Containers et du Transport Intermodal (B.I.C.)" list.
* @param {string} containerNumber - A valid container number
* @returns {Promise<Object>} The matching BIC code information from "Bureau
* International des Containers et du Transport Intermodal (B.I.C.)".
*/
getContainerOwner(containerNumber) {
return this._client._get("/getContainerOwner", { containerNumber });
}
/**
* Decodes a container ISO 6346 type code.
* @param {string} code - A valid container ISO type.
* @returns {Promise<Object>} Container type information.
*/
getContainerIsoType(code) {
return this._client._get("/getContainerIsoType", { code });
}
/**
* Gets all countries.
* @returns {Promise<Object[]>} An array of country.
*/
getCountries() {
return this._client._get("/getCountries");
}
/**
* Gets a country.
* @param {string} id - A country Id.
* @returns {Promise<Object>} The specified country.
*/
getCountry(id) {
return this._client._get("/getCountry", { id });
}
/**
* Gets all ISO 4217 Currencies.
* @returns {Promise<Object[]>} An array of Currencies.
*/
getCurrencies() {
return this._client._get("/getCurrencies");
}
/**
* Gets Currency details.
* @param {string} id - A currency code.
* @returns {Promise<Object>} The specified currency.
*/
getCurrency(id) {
return this._client._get("/getCurrency", { id });
}
/**
* Gets a UN/LOCODE.
* @param {string} id - A currency code.
* @returns {Promise<Object>} The specified UN/LOCODE.
*/
getLocode(id) {
return this._client._get("/getLocode", { id });
}
/**
* Searches UN/LOCODEs by country and/or function code.
* @param {Object} data - An object that allows to specify the search criteria ({ countryId, functionCode })
* @returns {Promise<Object>} An array of UN/LOCODE that match the search criteria.
* @example
* var res = CargoChainClient.instance.referenceData.searchLocodes({ countryId: 'FR' });
* var res = CargoChainClient.instance.referenceData.searchLocodes({ countryId: 'NZ', functionCode: '4' });
*/
searchLocodes(data) {
return this._client._get("/searchLocodes", data);
}
/**
* Gets all UN/LOCODE Functions.
* @returns {Promise<Object[]>} An array of UN/LOCODE functions.
*/
getLocodeFunctions() {
return this._client._get("/getLocodeFunctions");
}
/**
* Gets all UN/LOCODE Statuses.
* @returns {Promise<Object[]>} An array of UN/LOCODE statuses.
*/
getLocodeStatuses() {
return this._client._get("/getLocodeStatuses");
}
/**
* Gets all Packing Types.
* @returns {Promise<Object[]>} An array of Packing Type.
*/
getPackingTypes() {
return this._client._get("/getPackingTypes");
}
/**
* Gets a Packing Type.
* @param {string} id - A packing type Id.
* @returns {Promise<Object>} The specified Packing Type.
*/
getPackingType(id) {
return this._client._get("/getPackingType", { id });
}
/**
* Converts from one currency to another.
* @param {Object} data - The information for the conversion: { from, to, amount, date }
* @returns {Promise<Object>} The result of the conversion.
* @example
* var res = CargoChainClient.instance.referenceData.getExchangeRate({ from: 'EUR', to: 'USD', amount: '340' });
*/
getExchangeRate(data) {
return this._client._get("/getExchangeRate", data);
}
/**
* Finds a location from a position (latitude and longitude) in WGS84 / GPS format.
* @param {Object} data - The position: { latitude, longitude }
* @returns {Promise<Object>} The location.
* @example
* var res = CargoChainClient.instance.referenceData.getLocation({ latitude: 43.230, longitude: 12.1238 });
*/
getLocation(data) {
return this._client._get("/getLocation", data);
}
/**
* Gets one HS Code by its Product code and Nomenclature. If its Nomenclature is not specified,
* the world bank's HS list will be used to find the product.
* @param {Object} data - { productCode, nomenclatureCode }
* @returns {Promise<Object>} The specified HS Code.
*/
getHsCode(data) {
return this._client._get("/getHscode", data);
}
/**
* Gets HS Codes by Nomenclature.
* @param {string} nomenclatureCode - The Nomenclature Code.
* @returns {Promise<Object[]>} An array of HS Code.
*/
getHsNomenclature(nomenclatureCode) {
return this._client._get("/getHsNomenclature", { nomenclatureCode });
}
/**
* Searches HS Codes.
* @param {Object} data - Search criteria: { nomenclatureCode, query, productCodes }.
* @returns {Promise<Object[]>} An array of HS Code.
*/
searchHsCodes(data) {
return this._client._get("/searchHsCodes", data);
}
/**
* Gets a Hazardous Material.
* @param {Object} data - Hazardous Material information: { hazardousMaterialId, classCode, categoryCode }
* @returns {Promise<Object>} The specified Hazardous Material.
*/
getHazardousMaterial(data) {
return this._client._get("/getHazardousMaterial", data);
}
/**
* Gets Hazardous Materials by class.
* @param {Object} classCode - The hazardous material class code.
* @returns {Promise<Object[]>} An array of Hazardous Material.
*/
getHazardousMaterialsByClass(classCode) {
return this._client._get("/getHazardousMaterialsByClass", { classCode });
}
/**
* Gets all Hazardous Material classes.
* @returns {Promise<Object[]>} An array of Hazardous Material class.
*/
getHazardousMaterialClasses() {
return this._client._get("/getHazardousMaterialClasses");
}
/**
* Gets the current date time for the specified position.
* @param {Object} data - The position: { latitude, longitude }.
* @returns {Promise<Object>} Returns a date time string in ISO 8601 format
* containing the position's time zone.
*/
getCurrentDateTimeForPosition(data) {
return this._client._get("/getCurrentDateTimeForPosition", data);
}
/**
* Gets the date and time from a time zone from a specified time zone to a specified
* destination time zone.
* @param {Object} data - { year, month, day, hour, minute, second, fromTimeZone, toTimeZone }.
* @returns {Promise<Object>} A date time string in ISO 8601 format containing the
* destination time zone.
*/
getDateTimeFromTimeZoneToTimeZone(data) {
return this._client._get("/getDateTimeFromTimeZoneToTimeZone", data);
}
/**
* Gets the time zone for the specified position.
* @param {Object} data - The position: { latitude, longitude }.
* @returns {Promise<Object>} The string of the time zone for the given position
* in IANA timezone format.
*/
getTimeZoneForPosition(data) {
return this._client._get("/getTimeZoneForPosition", data);
}
/**
* Gets the timezones list.
* @returns {Promise<Object[]>} An array of timezone.
*/
getTimeZones() {
return this._client._get("/getTimeZones");
}
}
module.exports = ReferenceDataClient;