omnipartners
Version:
Node.js wrapper for Omniparners API.
491 lines (490 loc) • 18 kB
JavaScript
"use strict";
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");
const createUpdatePartnerAllowKeys = [
"partner_ext_id",
"partner_inv_name",
"partner_inv_street1",
"partner_inv_street2",
"partner_inv_streetnum",
"partner_inv_postal_code",
"partner_inv_city",
"partner_inv_region",
"partner_inv_country",
"partner_pub_name",
"partner_pub_street1",
"partner_pub_street2",
"partner_pub_streetnum",
"partner_pub_postal_code",
"partner_pub_city",
"partner_pub_region",
"partner_pub_country",
"partner_email",
"partner_emergency",
"partner_phone",
"partner_fax",
"partner_website",
"partner_facebook",
"partner_twitter",
"partner_instagram",
"partner_linkedin",
"partner_whatsapp",
"partner_youtube",
"partner_snap",
"partner_pinterest",
"partner_viadeo",
"partner_vat",
"partner_type",
"partner_subtype",
"partner_prim_cnt_title",
"partner_prim_cnt_first_name",
"partner_prim_cnt_last_name",
"partner_prim_cnt_email",
"partner_prim_cnt_mobile",
"partner_salesrep",
"partner_sales_support",
"partner_prim_cnt_language",
"partner_short_description",
"partner_short_description_translations",
"partner_eshop_url",
"partner_lat",
"partner_lng",
"partner_status",
"partner_is_hidden",
"partner_timezone",
"partner_self_id",
"partner_self_prefix",
"partner_deals_redirection_url",
"partner_referral_code",
"partner_group_handles",
];
class Partners extends Api_1.default {
constructor() {
super(...arguments);
this.defaultHost = "https://partners.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." },
1007: {
message: "Invalid request. This code is returned upon data validation failure.",
},
1008: { message: "Missing required fields" },
1025: { message: "Internal Error" },
1032: { message: "Partner_ext_id not found." },
1036: { message: "Service input data is Invalid." },
1040: { message: "Terminal id not found." },
};
}
_call(action, data, options = {}) {
return this.post("/", {
action,
...data,
}, {
hashKeys: ["action"],
...options,
});
}
listPartners(data) {
return this._call("get-partners", data, { retry: true });
}
findPartners(data) {
return this._call("find-partners", data, {
errorMap: {
1008: { message: "Missing required fields" },
1030: { message: "Invalid partner group handle." },
1031: { message: "Invalid partner type." },
},
hashKeys: ["action", "partner_lat", "partner_lng"],
retry: true,
});
}
locatePartners({ data_options, ...data } = {}) {
return this._call("locate-partners", {
...data,
data_options: data_options
? Array.isArray(data_options)
? data_options.join(",")
: data_options
: undefined,
}, {
errorMap: {
1008: { message: "Missing required fields" },
1030: { message: "Invalid partner group handle." },
1031: { message: "Invalid partner type." },
},
hashKeys: undefined,
retry: true,
});
}
partnerDetails({ partner_ext_id, data_options, ...data }) {
return this._call("get-partner-details", {
...data,
partner_ext_id: Array.isArray(partner_ext_id)
? partner_ext_id.join(",")
: partner_ext_id,
data_options: data_options
? Array.isArray(data_options)
? data_options.join(",")
: data_options
: undefined,
}, {
hashKeys: ["action", "partner_ext_id"],
retry: true,
});
}
featuredActivities(data) {
return this._call("get-featured-activities", {
...data,
}, { retry: true });
}
getLinks(data) {
return this._call("get-partner-links", {
...data,
partner_ext_id: data.partner_ext_id
? data.partner_ext_id.toString()
: null,
}, {
errorMap: {
1032: { message: "Partner_ext_id not found." },
},
hashKeys: ["action", "partner_ext_id"],
retry: true,
});
}
addLink(data) {
return this._call("add-partner-links", {
...data,
partner_ext_id: data.partner_ext_id
? data.partner_ext_id.toString()
: null,
}, {
hashKeys: ["action", "partner_ext_id", "type"],
retry: true,
});
}
deleteLink(data) {
return this._call("delete-partner-links", {
...data,
partner_ext_id: data.partner_ext_id
? data.partner_ext_id.toString()
: null,
}, {
hashKeys: ["action", "partner_ext_id", "type", "link_id"],
retry: true,
});
}
updatePartner(data) {
return this._call("update-partner", data, {
hashKeys: ["action", "partner_ext_id"],
});
}
addPartner(data) {
return this._call("add-partner", data, {
hashKeys: ["action", "partner_ext_id", "partner_type"],
});
}
resolvePartnerByTerminalId(data) {
return this._call("resolve-partner-by-terminal-id", data, {
hashKeys: ["action", "key", "terminal_id"],
retry: true,
});
}
listPartnerGroups(data) {
return this._call("get-partner-groups", data, {
retry: true,
});
}
addRelation(data) {
return this._call("add-partner-relations", data, {
hashKeys: [
"action",
"key",
"partner_ext_id",
"reference",
"relation_type",
],
retry: true,
});
}
deleteRelation(data) {
return this._call("delete-partner-relations", data, {
hashKeys: [
"action",
"key",
"partner_ext_id",
"reference",
"relation_type",
],
retry: true,
});
}
updatePartnerLogo(data) {
return this._call("update-partner-logo", data, {
hashKeys: ["action", "partner_ext_id"],
multipart: true,
errorMap: {
1033: {
message: "Partner logo image upload error. Partner logo should be with valid file type - JPG, PNG or GIF",
},
},
});
}
getLogoURLs(data) {
return this._call("get-partner-logo-urls", data, {
hashKeys: ["action", "partner_ext_id"],
});
}
addOpeningHours(data) {
return this._call("add-partner-opening-hours", data, {
hashKeys: ["action", "partner_ext_id"],
retry: true,
});
}
deleteOpeningHours(data) {
return this._call("delete-partner-opening-hours", data, {
hashKeys: ["action", "partner_ext_id", "day"],
retry: true,
});
}
updatePartnerStock(data) {
return this._call("update-partner-stock", data, {
hashKeys: [
"action",
"key",
"partner_ext_id",
"product_ean",
"stock_level",
],
retry: true,
});
}
addMissingStockItem(data) {
return this._call("add-missing-stock-item", data, {
hashKeys: [
"action",
"collection_ref",
"key",
"partner_ext_id",
"product_ean",
"user_guid",
],
retry: true,
});
}
addToGroup(data) {
return this._call("add-to-group", data, {
hashKeys: ["action", "partner_group_handle", "partner_ext_id"],
retry: true,
});
}
removeFromGroup(data) {
return this._call("remove-from-group", data, {
hashKeys: ["action", "partner_group_handle", "partner_ext_id"],
retry: true,
});
}
}
__decorate([
(0, apiDecorators_1.doc)("http://doc.omnipartners.be/index.php/List_Partners"),
(0, apiDecorators_1.filterInput)([
"partner_type",
"partner_group_handle",
"collection_ref",
"stock_level",
"search_term",
"search_strict",
"partner_status",
"partner_updated_date",
// (Eg: partner_updated_date:"2014-06-05" OR partner_updated_date:"2014-06-05 14:10" time should be in 24H format )
// When the partner_updated_date is empty string OR not send with request we return all records.
"page",
"rows",
"show_hidden", // (Optional) States whether to include the hidden partners in the result. (Valid Values: 0 OR 1) default 0
])
], Partners.prototype, "listPartners", null);
__decorate([
(0, apiDecorators_1.doc)("https://doc.clixray.com/index.php?title=Find_Partners"),
(0, apiDecorators_1.filterInput)([
"partner_lat",
"partner_lng",
"indexed_result",
"partner_type",
"partner_group_handle",
"excl_partner_group_handle",
"product_ean",
"collection_ref",
"stock_level",
"search_term",
"radius",
"limit",
"show_hidden",
"add_cis_guid",
"partner_status",
"include_unknown_stock_level",
])
], Partners.prototype, "findPartners", null);
__decorate([
(0, apiDecorators_1.doc)("https://doc.clixray.com/index.php?title=Locate_Partners"),
(0, apiDecorators_1.filterInput)([
"partner_lat",
"partner_lng",
"indexed_result",
"partner_type",
"partner_group_handle",
"excl_partner_group_handle",
"product_ean",
"collection_ref",
"stock_level",
"search_term",
"radius",
"show_hidden",
"partner_status",
"deal_ref",
"partner_mode",
"page",
"records_per_page",
"data_options", // (Optional)This defines information that is returned in the profile object. It should be a comma separated list of values. For more information please refer Data Options. Default value contains groups and location. It's recommended to use minimal set of data_options to improve performance. It's recommended to use minimal set of data_options to improve performance.
])
], Partners.prototype, "locatePartners", null);
__decorate([
(0, apiDecorators_1.doc)("https://doc.clixray.com/index.php/Get_Partners_Details"),
(0, apiDecorators_1.filterInput)([
"partner_ext_id",
"indexed_result",
"lang",
"data_options", // This defines information that is returned in the profile object. It should be a comma separated list of values. For more information please refer Data Options.
])
], Partners.prototype, "partnerDetails", null);
__decorate([
(0, apiDecorators_1.doc)("http://doc.omnipartners.be/index.php/Get_Featured_Activities"),
(0, apiDecorators_1.filterInput)([
"lang", // (Optional) The language used to return the translated contents
])
], Partners.prototype, "featuredActivities", null);
__decorate([
(0, apiDecorators_1.doc)("http://doc.omnipartners.be/index.php/Retrieve_Links"),
(0, apiDecorators_1.filterInput)([
"partner_ext_id",
"type", // (Optional) Links have a type (photo, video) to start with. If set then gives relative type of records only.
])
], Partners.prototype, "getLinks", null);
__decorate([
(0, apiDecorators_1.doc)("http://doc.omnipartners.be/index.php/Add_Link"),
(0, apiDecorators_1.filterInput)([
"partner_ext_id",
"type",
"link_data", // (Required) json enccoded array data, it fill with languge code and its link data
])
], Partners.prototype, "addLink", null);
__decorate([
(0, apiDecorators_1.doc)("http://doc.omnipartners.be/index.php/Delete_Links"),
(0, apiDecorators_1.filterInput)([
"partner_ext_id",
"type",
"link_id",
])
], Partners.prototype, "deleteLink", null);
__decorate([
(0, apiDecorators_1.doc)("https://doc.clixray.com/index.php/Update_Partner"),
(0, apiDecorators_1.filterInput)((keys) => {
const rgxFieldCustom = /^partner_custom_/;
return keys.filter((key) => {
return (createUpdatePartnerAllowKeys.indexOf(key) >= 0 ||
rgxFieldCustom.test(key));
});
})
], Partners.prototype, "updatePartner", null);
__decorate([
(0, apiDecorators_1.doc)("https://doc.clixray.com/index.php?title=Add_Partner"),
(0, apiDecorators_1.filterInput)((keys) => {
const rgxFieldCustom = /^partner_custom_/;
return keys.filter((key) => {
return (createUpdatePartnerAllowKeys.indexOf(key) >= 0 ||
rgxFieldCustom.test(key));
});
})
], Partners.prototype, "addPartner", null);
__decorate([
(0, apiDecorators_1.doc)("http://doc.omnipartners.be/index.php/Resolve_Partner_by_Terminal_Id"),
(0, apiDecorators_1.filterInput)([
"terminal_id", // (Required) The terminal id associated to the partner
])
], Partners.prototype, "resolvePartnerByTerminalId", null);
__decorate([
(0, apiDecorators_1.doc)("http://doc.omnipartners.be/index.php/List_Partners_Group"),
(0, apiDecorators_1.filterInput)([
"partner_group_handle",
"partner_type", // (Optional) The “Partner Type” used to filter and retrieve partner group information based on the partner assignment to that group.
])
], Partners.prototype, "listPartnerGroups", null);
__decorate([
(0, apiDecorators_1.doc)("http://doc.omnipartners.be/index.php/Add_Relation"),
(0, apiDecorators_1.filterInput)([
"partner_ext_id",
"relation_type",
"reference",
])
], Partners.prototype, "addRelation", null);
__decorate([
(0, apiDecorators_1.doc)("http://doc.omnipartners.be/index.php/Delete_Relation"),
(0, apiDecorators_1.filterInput)([
"partner_ext_id",
"relation_type",
"reference",
])
], Partners.prototype, "deleteRelation", null);
__decorate([
(0, apiDecorators_1.doc)("http://doc.omnipartners.be/index.php/Update_Partner_Logo_Image"),
(0, apiDecorators_1.filterInput)(["partner_ext_id", "partner_logo"])
], Partners.prototype, "updatePartnerLogo", null);
__decorate([
(0, apiDecorators_1.doc)("https://doc.clixray.com/index.php?title=Retrieve_Partner_Logo_URLs"),
(0, apiDecorators_1.filterInput)(["partner_ext_id"])
], Partners.prototype, "getLogoURLs", null);
__decorate([
(0, apiDecorators_1.doc)("http://doc.omnipartners.be/index.php/Add_Partner_Opening_Hours"),
(0, apiDecorators_1.filterInput)(["partner_ext_id", "data"])
], Partners.prototype, "addOpeningHours", null);
__decorate([
(0, apiDecorators_1.doc)("http://doc.omnipartners.be/index.php/Delete_Partner_Opening_Hours"),
(0, apiDecorators_1.filterInput)([
"partner_ext_id",
"day", // Day is the day number (Mon = 1, Sun = 7) Eg: "day":"1,3,4"
])
], Partners.prototype, "deleteOpeningHours", null);
__decorate([
(0, apiDecorators_1.doc)("https://doc.clixray.com/index.php?title=Update_Partner_Stock"),
(0, apiDecorators_1.filterInput)([
"partner_ext_id",
"product_ean",
"stock_level", // Stock level which is a value between 0 and 10. If this parameter is omitted from the request the stock level will be updated as null.
])
], Partners.prototype, "updatePartnerStock", null);
__decorate([
(0, apiDecorators_1.doc)("https://doc.clixray.com/index.php?title=Add_Missing_Stock_Item"),
(0, apiDecorators_1.filterInput)(["partner_ext_id", "product_ean", "collection_ref", "user_guid"])
], Partners.prototype, "addMissingStockItem", null);
__decorate([
(0, apiDecorators_1.doc)("https://doc.clixray.com/index.php?title=Add_to_Partner_Group"),
(0, apiDecorators_1.filterInput)(["partner_ext_id", "partner_group_handle", "email_notify"])
], Partners.prototype, "addToGroup", null);
__decorate([
(0, apiDecorators_1.doc)("https://doc.clixray.com/index.php?title=Remove_from_Partner_Group"),
(0, apiDecorators_1.filterInput)(["partner_ext_id", "partner_group_handle"])
], Partners.prototype, "removeFromGroup", null);
exports.default = Partners;