omnipartners
Version:
Node.js wrapper for Omniparners API.
471 lines (470 loc) • 18.8 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Api_1 = __importDefault(require("../../lib/Api"));
const apiDecorators_1 = require("../../lib/apiDecorators");
class Products extends Api_1.default {
constructor() {
super(...arguments);
this.defaultHost = "https://products.clixray.io/";
this.errorMap = {
1000: { message: "Action not available." },
1001: { message: "Invalid action." },
1002: { message: "Client key not available." },
1003: { message: "Invalid client key." },
1004: { message: "Hash not available." },
1005: { message: "Invalid hash." },
1006: { message: "Access denied." },
1014: { message: "Invalid language." },
1024: { message: "Invalid criteria filter type usage." },
1027: { message: "Input filter type parameters are required." },
1028: { message: "Invalid criteria filter type." },
1060: { message: "Invalid Value for Filter type Pet's BCS." },
1008: { message: "Invalid partner_ext_id." },
1009: { message: "Invalid partner_group_handle." },
1015: { message: "Pet GUID not available." },
1016: { message: "Invalid Pet GUID." },
1017: { message: "Inactive pet." },
1021: { message: "Internal error." },
1023: { message: "Invalid Request." },
1058: { message: "Invalid Terminal Id." },
1030: { message: "Missing required fields." },
1034: { message: "Pet owner not found." },
1035: { message: "Pet owner not active." },
1939: {
message: "Invalid Data Provided (Ration value cannot be calculated).",
},
1940: {
message: "Either energy level is not specified or collection doesn't have the energy level defined.",
},
1941: { message: "Invalid pet weight value." },
1942: { message: "Invalid pet BCS value." },
1943: {
message: "Invalid pet BCS constant (Which is used inside the calculation).",
},
1954: { message: "Pet Species not found." },
1955: { message: "Invalid pet Species." },
1968: {
message: "Pet Info not found. (When any of pet_species or pet_breed is not provided).",
},
1969: { message: "Invalid Breed." },
1973: { message: "Invalid Pet Stage." },
1974: { message: "Pet feeding Stage is Empty." },
1975: { message: "Cannot Derive Pet feeding Stage." },
1977: { message: "Pet neutered value is Invalid." },
1979: { message: "Pet's predicted Adult Weight is required." },
1980: { message: "Breed is required for the calculation." },
1981: { message: "Pet's Age is required for the calculation." },
1982: {
message: "Predicted Adult Weight is not supporting for the calculation (Value mismatch).",
},
1983: {
message: "Age is not supporting for the calculation ( Value mismatch).",
},
1984: {
message: "Pet is not in Growth feeding stage (Provided information does not match for the Growth Feeding stage).",
},
1991: { message: "Invalid Value for pet's predicted adult weight." },
1992: { message: "Invalid Value supplied for energy level." },
1989: { message: "Empty pet weight." },
2005: { message: "Invalid Component sort order field found." },
2010: { message: "No pets found for the user." },
};
}
_call(action, data, options = {}) {
return this.post("/", {
action,
...data,
}, {
hashKeys: ["action"],
...options,
});
}
getProduct(data) {
return this._call("get-product", data, {
errorMap: {
1020: { message: "Product ean or code required." },
},
retry: true,
});
}
getCollectionDetails(data) {
return this._call("get-collection-details", {
...data,
data_options: data.data_options
? Array.isArray(data.data_options)
? data.data_options.join(",")
: data.data_options
: undefined,
}, {
errorMap: {
1018: { message: "collection reference can not be empty." },
1019: { message: "language reference can not be empty." },
1014: { message: "Invalid language." },
2005: { message: "Invalid Component sort order field found." },
},
retry: true,
});
}
findProductCollection(data) {
return this._call("find-product-collection", {
"resolve-by": data.resolve_by,
data_options: data.data_options
? Array.isArray(data.data_options)
? data.data_options.join(",")
: data.data_options
: undefined,
...data,
}, {
errorMap: {
1011: { message: "resolve-by field can not be empty." },
1012: { message: "resolve-by field can not be empty." },
1013: { message: "resolve-by field can not be empty." },
1014: { message: "resolve-by field can not be empty." },
1029: { message: "resolve-by field can not be empty." },
},
retry: true,
});
}
getCollectionsByTargetingInfo(data) {
return this._call("get-collections-by-targeting-info", data, {
errorMap: {
1008: { message: "Invalid partner_ext_id." },
1009: { message: "Invalid partner_group_handle." },
1014: { message: "Invalid language." },
1022: { message: "Invalid range." },
1024: { message: "Invalid criteria filter type usage." },
1027: { message: "Input filter type parameters are required." },
1028: { message: "Invalid criteria filter type." },
1944: {
message: 'External services used to retrieve contents failed. Additional information of this failure will be displayed under the property, "ext_svc_err".',
},
1058: { message: "Invalid Terminal Id." },
1059: { message: "Invalid Value for Filter type Pet's weight." },
1060: { message: "Invalid Value for Filter type Pet's BCS." },
},
retry: true,
});
}
getCollectionsByPetGUID(data) {
return this._call("get-collections-by-pet-guid", data, {
errorMap: {},
retry: true,
});
}
getCollectionsWithProducts(data) {
return this._call("get-collections", data, {
errorMap: {},
retry: true,
});
}
getProductGroupList(data) {
return this._call("list-product-groups", data, {
errorMap: {},
retry: true,
});
}
getCollectionAvailablePackage(data) {
return this._call("get-available-packaging-info", data, {
errorMap: {},
retry: true,
});
}
getCollectionPetRation(data) {
return this._call("get-collection-pet-ration", data, {
errorMap: {},
retry: true,
});
}
/*
Manage advices
*/
getArticlesByTargetingInformation(data) {
return this._call("get-articles-by-targeting-info", {
...data,
data_options: data.data_options
? Array.isArray(data.data_options)
? data.data_options.join(",")
: data.data_options
: undefined,
}, {
errorMap: {},
retry: true,
});
}
getArticlesByPetGuid(data) {
return this._call("get-articles-by-pet-guid", {
...data,
data_options: data.data_options
? Array.isArray(data.data_options)
? data.data_options.join(",")
: data.data_options
: undefined,
}, {
errorMap: {},
retry: true,
});
}
// not yet implemented
getArticlesByUserGuid(data) {
return this._call("get-articles-by-user-guid", {
...data,
data_options: data.data_options
? Array.isArray(data.data_options)
? data.data_options.join(",")
: data.data_options
: undefined,
}, {
errorMap: {},
retry: true,
});
}
getArticle(data) {
return this._call("get-article-details", {
...data,
data_options: data.data_options
? Array.isArray(data.data_options)
? data.data_options.join(",")
: data.data_options
: undefined,
}, {
errorMap: {},
retry: true,
});
}
addProduct({ custom_fields, ...fields }) {
const data = {
...fields,
product_ean: Number(fields.product_ean),
...(custom_fields
? Object.entries(custom_fields).map(([key, value]) => ({
[`pro_${key}`]: value,
}))
: {}),
};
return this._call("add-product", data, {
errorMap: {
1039: {
message: "Invalid data. This code is returned upon data validation failure. A property named 'errors' in the returned object will contain more details of the failure.",
},
1978: {
message: "Invalid collection reference. Collection reference is invalid.",
},
2012: { message: "Error when adding a new collection." },
},
hashKeys: undefined, // all keys are hashed
});
}
}
__decorate([
(0, apiDecorators_1.doc)("http://doc.omnipartners.be/index.php/Get_Product_By_EAN_or_Code"),
(0, apiDecorators_1.filterInput)(["product_ean", "product_code"])
], Products.prototype, "getProduct", null);
__decorate([
(0, apiDecorators_1.doc)("http://doc.omnipartners.be/index.php/Get_Collection_Details"),
(0, apiDecorators_1.filterInput)([
"collection_reference",
"language",
"use_https_urls",
"data_options",
"component_sort_order",
"ignore_old_format",
])
], Products.prototype, "getCollectionDetails", null);
__decorate([
(0, apiDecorators_1.doc)("http://doc.omnipartners.be/index.php/Find_product_collection"),
(0, apiDecorators_1.filterInput)([
"use_https_urls",
"resolve_by",
"value",
"language",
"data_options",
"component_sort_order",
"ignore_old_format",
"search_mode", // Search mode of the searching value. Valid values are "exact", "sounds_like", "looks_like", "partial_string" and "partial_words". Default value is "exact". This parameter is valid for "collection_name", "collection_reference" and "collection_ranges" resolve-by values only.
])
], Products.prototype, "findProductCollection", null);
__decorate([
(0, apiDecorators_1.doc)("http://doc.omnipartners.be/index.php/List_Collections_by_Targeting_Information"),
(0, apiDecorators_1.filterInput)([
"partner_id",
"partner_id_type",
"deal_reference",
"partner_group_handle",
"pet_guid",
"user_guid",
"diagnostic_codes",
"filter_by_all",
"filter_type",
"species_type",
"univers",
"breed",
"neutered",
"gender",
"purchase_place",
"unit",
"age",
"age_from",
"age_to",
"dob",
"pathologies",
"lifestyle",
"operator",
"range_reference",
"pet_weight",
"pet_bcs",
"pet_stages",
"partners_visibility",
"public_visibility",
"partner_types",
"pet_allergens",
"pet_health_context",
"language",
"use_https_urls",
"show_ration",
"apply_range_exlusions",
"data_options",
"ration_predicted_weight",
])
], Products.prototype, "getCollectionsByTargetingInfo", null);
__decorate([
(0, apiDecorators_1.doc)("http://doc.omnipartners.be/index.php/List_Collection_by_Pet_GUID"),
(0, apiDecorators_1.filterInput)([
"pet_guid",
"user_guid",
"partner_id",
"partner_id_type",
"partner_group_handle",
"language",
"add_clientof_partner_groups",
"use_https_urls",
"apply_range_exlusions",
"data_options",
"is_gestation",
"sort_order",
"component_sort_order",
"ignore_old_format", // (Optional) Ignore the old format of the response.Valid values are 0 and 1. Default value is 0.
])
], Products.prototype, "getCollectionsByPetGUID", null);
__decorate([
(0, apiDecorators_1.doc)("https://doc.clixray.com/index.php?title=List_Collections_With_Products"),
(0, apiDecorators_1.filterInput)([
"use_https_urls",
"collection_reference",
"product_group_handle",
"add_product_details",
"add_product_groups",
"lang", // (Optional) The language which translations should be provided.
])
], Products.prototype, "getCollectionsWithProducts", null);
__decorate([
(0, apiDecorators_1.doc)("http://doc.omnipartners.be/index.php/Get_Product_Group_List"),
(0, apiDecorators_1.filterInput)([
"group_handle", // The “Product Group Handle” used to filter and retrieve product group information relative to the handle.
])
], Products.prototype, "getProductGroupList", null);
__decorate([
(0, apiDecorators_1.doc)("http://doc.omnipartners.be/index.php/Get_Product_Group_List"),
(0, apiDecorators_1.filterInput)([
"use_https_urls",
"collection_reference",
"show_public_products_only",
"language", // Optional Language ID, you can find this by using the following service. http://doc.omnipartners.be/index.php/Language_list . The language used to retrieve the translated names of the container type. If not specified , it will return all the translated names.
])
], Products.prototype, "getCollectionAvailablePackage", null);
__decorate([
(0, apiDecorators_1.doc)("http://doc.omnipartners.be/index.php/Get_Collection_Pet_Ration"),
(0, apiDecorators_1.filterInput)([
"pet_weight",
"pet_guid",
"pet_predicted_adult_weight",
"pet_bcs",
"energy_level",
"collection_reference",
"language", // (Optional) Language ID will use to translate the units of the result. (see http://doc.omnipartners.be/index.php/Language_list)
])
], Products.prototype, "getCollectionPetRation", null);
__decorate([
(0, apiDecorators_1.doc)("https://doc.clixray.com/index.php?title=List_Articles_By_Targeting_Information"),
(0, apiDecorators_1.filterInput)([
"filter_by_all",
"pet_guid",
"filter_type",
"species_type",
"universe",
"breed",
"neutered",
"gender",
"unit",
"age",
"age_from",
"age_to",
"dob",
"pathologies",
"lifestyle",
"operator",
"pet_bcs",
"pet_stages",
"pet_allergens",
"pet_health_context",
"language",
"data_options",
"user_guid",
])
], Products.prototype, "getArticlesByTargetingInformation", null);
__decorate([
(0, apiDecorators_1.doc)("https://doc.clixray.com/index.php?title=List_Articles_By_Pet_GUID"),
(0, apiDecorators_1.filterInput)([
"pet_guid",
"language",
"data_options", // (Optional) This defines information that is returned in the response. Multiple values should be comma separated. For more information please refer Data Options.
])
], Products.prototype, "getArticlesByPetGuid", null);
__decorate([
(0, apiDecorators_1.doc)("https://doc.clixray.com/index.php?title=List_Articles_By_User_GUID"),
(0, apiDecorators_1.filterInput)([
"user_guid",
"language",
"data_options", // (Optional) This defines information that is returned in the response. Multiple values should be comma separated. For more information please refer Data Options.
])
], Products.prototype, "getArticlesByUserGuid", null);
__decorate([
(0, apiDecorators_1.doc)("https://doc.clixray.com/index.php?title=Get_Article_Details"),
(0, apiDecorators_1.filterInput)([
"article_reference",
"language",
"data_options", // (Optional) This defines information that is returned in the response. Multiple values should be comma separated. For more information please refer Data Options.
])
], Products.prototype, "getArticle", null);
__decorate([
(0, apiDecorators_1.doc)("https://doc.clixray.com/index.php?title=Add_Product"),
(0, apiDecorators_1.filterInput)([
"product_ean",
"product_label",
"product_code",
"product_status",
"product_collection_reference",
"product_collection_gen_name",
"product_group_handles",
"product_friendly_name",
"product_rr_price",
"product_pp_price",
"product_weight",
"product_gross_weight",
"product_packaging_container_type",
"product_packaging_value",
"product_packaging_units",
"product_packaging_gross_weight",
"product_publicly_not_available",
"custom_fields", // Optional
])
], Products.prototype, "addProduct", null);
exports.default = Products;