<commit_before>/**
 * Products API requests and definitions for Amazon's MWS web services.
 * For information on using, please see examples folder.
 *
 * @author <NAME>
 */

var mws = require('./mws');
var _ = require('underscore');

module.exports = {

    /**
     * @abstract Returns the operational status of the Products API section.
     * @description

     The GetServiceStatus operation returns the operational status of the Products API section of Amazon Marketplace Web Service (Amazon MWS). Status values are GREEN, GREEN_I, YELLOW, and RED.

     The GetServiceStatus operation has a maximum request quota of two and a restore rate of one request every five minutes. For definitions of throttling terminology, see Throttling.

     * @param {Object} config Object of all needed IDs
     * @param {Boolean} xml Return xml if is true, default is false and returns object
     * @param {Function} cb Callback
     */

    ItemCondition: [
        'Any', 'New', 'Used', 'Collectible', 'Refurbished', 'Club'
    ],

    GetServiceStatus: function (config, xml, cb) {
        if (typeof xml == 'function') {
            cb = xml;
            xml = false;
        } else if (typeof xml == 'undefined') {
            console.warn("No callback provided. Throwing the request");
            return;
        }
        mws.createRequest({
            'action': 'GetServiceStatus',
            'config': config,
            'parameters': {},
            'type': 'Products',
            "xml": xml
        }, function (err, data) {
            cb(err, data);
        });


    },

    /**
     * @abstract Required: MarketplaceId, Query Optional: QueryContextId
     * @description The ListMatchingProducts operation returns a list of products and their attributes, ordered by relevancy, based on a search query that you specify. Your search query can be a phrase that describes the product or it can be a product identifier such as a GCID, UPC, EAN, ISBN, or JAN. If you have the ASIN associated with your product, use the GetMatchingProduct operation. Note that the product identifier cannot be a SellerSKU. If your query does not return any matching products, the query will be broadened using spelling correction or the removal of keywords to find matches. This operation returns a maximum of ten products and does not return non-buyable products.
     * @param {Object} config Configuration file
     * @param {Object} params Required: MarketplaceId, Query Optional: QueryContextId
     * @param {Boolean} xml xml flag. If true, returns raw xml although returns object
     * @param {Function} cb Callback function
     * @see http://docs.developer.amazonservices.com/en_US/products/Products_ListMatchingProducts.html
     */
    ListMatchingProducts: function (config, params, xml, cb) {
        if (typeof xml == 'function') {
            cb = xml;
            xml = false;
        } else if (typeof xml == 'undefined') {
            console.warn("No callback provided. Throwing the request");
            return;
        }

        if (!_.has(params, 'MarketplaceId') || !_.has(params, 'Query')) {
            cb({
                "Error": "You need to pass parameter MarketplaceId and Query"
            }, null);
            return;
        }

        var parameters = {
            'MarketplaceId': params['MarketplaceId'],
            'Query': params['Query']
        };
        if (_.has(params, 'QueryContextId')) {
            parameters['QueryContextId'] = params['QueryContextId'];
        }
        mws.createRequest({
            'action': 'ListMatchingProducts',
            'config': config,
            'parameters': parameters,
            'type': 'Products',
            'xml': xml
        }, function (err, data) {
            cb(err, data);
        });
    },

    /**
     * @absract Returns a list of products and their attributes, based on a list of ASIN values.
     * @description

     The GetMatchingProduct operation returns a list of products and their attributes, based on a list of ASIN values that you specify. This operation returns a maximum of ten products.

     Important. All of the functionality of the GetMatchingProduct operation can be found in the new GetMatchingProductForId operation. The GetMatchingProduct operation is included in the Products API section for backward compatibility, but you should use the GetMatchingProductForId operation in favor of the GetMatchingProduct operation whenever possible. For more information, see GetMatchingProductForId.

     * @param {Object} config Configuration file
     * @param {Object} params Required: MarketplaceId
     * @param {Boolean} xml flag. If true, returns raw xml although returns object
     * @param {Function} cb Callback function
     * @see http://docs.developer.amazonservices.com/en_US/products/Products_GetMatchingProduct.html
     */
    GetMatchingProduct: function (config, params, xml, cb) {
        if (typeof xml == 'function') {
            cb = xml;
            xml = false;
        } else if (typeof xml == 'undefined') {
            console.warn("No callback provided. Throwing the request");
            return;
        }

        /**
         * ASINList has to be as:
         * {
         *      ASINList : {
         *          ASINList.ASIN.1 : XXXX,
         *          ASINList.ASIN.2 : XXXX,
         *           ...
         *      }
         * }
         */
        if (!_.has(params, 'MarketplaceId') || !_.has(params, 'ASINList')) {
            cb({
                "Error": "You need to pass parameter MarketplaceId and ASINList"
            }, null);
            return;
        }

        var parameters = {
            'MarketplaceId': params['MarketplaceId']
        };

        // Testing
        // if ASINList is correct
        // Add ASINList items to paramaters of Query
        var counter = 1;
        for (var key in params['ASINList']) {
            if (/ASINList.ASIN.[1-5]{1}/.test(key)) {
                parameters[key] = params['ASINList'][key];
            }
            counter++;
        }
        mws.createRequest({
            'action': 'GetMatchingProduct',
            'config': config,
            'parameters': parameters,
            'type': 'Products',
            'xml': xml
        }, function (err, data) {
            cb(err, data);
        });
    },

    /**
     * @absract Returns a list of products and their attributes, based on a list of ASIN, GCID, SellerSKU, UPC, EAN, ISBN, and JAN values.
     * @description The GetMatchingProductForId operation returns a list of products and their attributes, based on a list of product identifier values that you specify. Possible product identifiers are ASIN, GCID, SellerSKU, UPC, EAN, ISBN, and JAN.
     * @param {Object} config Configuration file
     * @param {Object} params Required: MarketplaceId, IdType, IdList
     * @param {Boolean} xml flag. If true, returns raw xml although returns object
     * @param {Function} cb Callback function
     * @see http://docs.developer.amazonservices.com/en_US/products/Products_GetMatchingProductForId.html
     */
    GetMatchingProductForId: function (config, params, xml, cb) {
        if (typeof xml == 'function') {
            cb = xml;
            xml = false;
        } else if (typeof xml == 'undefined') {
            console.warn("No callback provided. Throwing the request");
            return;
        }

        if (!_.has(params, 'MarketplaceId') || !_.has(params, 'IdType') || !_.has(params, 'IdList')) {
            cb({
                "Error": "You need to pass parameter MarketplaceId, IdType and IdList"
            }, null);
            return;
        }

        // Control the IdType - allowed only (ASIN,GCID,SellerSKU,UPC,EAN,ISBN,JAN)
        if (params['IdType'] !== 'ASIN' && params['IdType'] !== 'GCID' && params['IdType'] !== 'SellerSKU' && params['IdType'] !== 'UPC' && params['IdType'] !== 'EAN' && params['IdType'] !== 'JAN') {
            cb({
                'Error': "Usage of unallowed IdType. Allowed are ASIN,GCID,SellerSKU,UPC,EAN,ISBN,JAN"
            }, null);
            return;
        }

        var parameters = {
            'MarketplaceId': params['MarketplaceId'],
            'IdType': params['IdType']<commit_msg>Check for ISBN in allowed "idType" was missing<commit_after>/**
 * Products API requests and definitions for Amazon's MWS web services.
 * For information on using, please see examples folder.
 *
 * @author <NAME>
 */

var mws = require('./mws');
var _ = require('underscore');

module.exports = {

    /**
     * @abstract Returns the operational status of the Products API section.
     * @description

     The GetServiceStatus operation returns the operational status of the Products API section of Amazon Marketplace Web Service (Amazon MWS). Status values are GREEN, GREEN_I, YELLOW, and RED.

     The GetServiceStatus operation has a maximum request quota of two and a restore rate of one request every five minutes. For definitions of throttling terminology, see Throttling.

     * @param {Object} config Object of all needed IDs
     * @param {Boolean} xml Return xml if is true, default is false and returns object
     * @param {Function} cb Callback
     */

    ItemCondition: [
        'Any', 'New', 'Used', 'Collectible', 'Refurbished', 'Club'
    ],

    GetServiceStatus: function (config, xml, cb) {
        if (typeof xml == 'function') {
            cb = xml;
            xml = false;
        } else if (typeof xml == 'undefined') {
            console.warn("No callback provided. Throwing the request");
            return;
        }
        mws.createRequest({
            'action': 'GetServiceStatus',
            'config': config,
            'parameters': {},
            'type': 'Products',
            "xml": xml
        }, function (err, data) {
            cb(err, data);
        });


    },

    /**
     * @abstract Required: MarketplaceId, Query Optional: QueryContextId
     * @description The ListMatchingProducts operation returns a list of products and their attributes, ordered by relevancy, based on a search query that you specify. Your search query can be a phrase that describes the product or it can be a product identifier such as a GCID, UPC, EAN, ISBN, or JAN. If you have the ASIN associated with your product, use the GetMatchingProduct operation. Note that the product identifier cannot be a SellerSKU. If your query does not return any matching products, the query will be broadened using spelling correction or the removal of keywords to find matches. This operation returns a maximum of ten products and does not return non-buyable products.
     * @param {Object} config Configuration file
     * @param {Object} params Required: MarketplaceId, Query Optional: QueryContextId
     * @param {Boolean} xml xml flag. If true, returns raw xml although returns object
     * @param {Function} cb Callback function
     * @see http://docs.developer.amazonservices.com/en_US/products/Products_ListMatchingProducts.html
     */
    ListMatchingProducts: function (config, params, xml, cb) {
        if (typeof xml == 'function') {
            cb = xml;
            xml = false;
        } else if (typeof xml == 'undefined') {
            console.warn("No callback provided. Throwing the request");
            return;
        }

        if (!_.has(params, 'MarketplaceId') || !_.has(params, 'Query')) {
            cb({
                "Error": "You need to pass parameter MarketplaceId and Query"
            }, null);
            return;
        }

        var parameters = {
            'MarketplaceId': params['MarketplaceId'],
            'Query': params['Query']
        };
        if (_.has(params, 'QueryContextId')) {
            parameters['QueryContextId'] = params['QueryContextId'];
        }
        mws.createRequest({
            'action': 'ListMatchingProducts',
            'config': config,
            'parameters': parameters,
            'type': 'Products',
            'xml': xml
        }, function (err, data) {
            cb(err, data);
        });
    },

    /**
     * @absract Returns a list of products and their attributes, based on a list of ASIN values.
     * @description

     The GetMatchingProduct operation returns a list of products and their attributes, based on a list of ASIN values that you specify. This operation returns a maximum of ten products.

     Important. All of the functionality of the GetMatchingProduct operation can be found in the new GetMatchingProductForId operation. The GetMatchingProduct operation is included in the Products API section for backward compatibility, but you should use the GetMatchingProductForId operation in favor of the GetMatchingProduct operation whenever possible. For more information, see GetMatchingProductForId.

     * @param {Object} config Configuration file
     * @param {Object} params Required: MarketplaceId
     * @param {Boolean} xml flag. If true, returns raw xml although returns object
     * @param {Function} cb Callback function
     * @see http://docs.developer.amazonservices.com/en_US/products/Products_GetMatchingProduct.html
     */
    GetMatchingProduct: function (config, params, xml, cb) {
        if (typeof xml == 'function') {
            cb = xml;
            xml = false;
        } else if (typeof xml == 'undefined') {
            console.warn("No callback provided. Throwing the request");
            return;
        }

        /**
         * ASINList has to be as:
         * {
         *      ASINList : {
         *          ASINList.ASIN.1 : XXXX,
         *          ASINList.ASIN.2 : XXXX,
         *           ...
         *      }
         * }
         */
        if (!_.has(params, 'MarketplaceId') || !_.has(params, 'ASINList')) {
            cb({
                "Error": "You need to pass parameter MarketplaceId and ASINList"
            }, null);
            return;
        }

        var parameters = {
            'MarketplaceId': params['MarketplaceId']
        };

        // Testing
        // if ASINList is correct
        // Add ASINList items to paramaters of Query
        var counter = 1;
        for (var key in params['ASINList']) {
            if (/ASINList.ASIN.[1-5]{1}/.test(key)) {
                parameters[key] = params['ASINList'][key];
            }
            counter++;
        }
        mws.createRequest({
            'action': 'GetMatchingProduct',
            'config': config,
            'parameters': parameters,
            'type': 'Products',
            'xml': xml
        }, function (err, data) {
            cb(err, data);
        });
    },

    /**
     * @absract Returns a list of products and their attributes, based on a list of ASIN, GCID, SellerSKU, UPC, EAN, ISBN, and JAN values.
     * @description The GetMatchingProductForId operation returns a list of products and their attributes, based on a list of product identifier values that you specify. Possible product identifiers are ASIN, GCID, SellerSKU, UPC, EAN, ISBN, and JAN.
     * @param {Object} config Configuration file
     * @param {Object} params Required: MarketplaceId, IdType, IdList
     * @param {Boolean} xml flag. If true, returns raw xml although returns object
     * @param {Function} cb Callback function
     * @see http://docs.developer.amazonservices.com/en_US/products/Products_GetMatchingProductForId.html
     */
    GetMatchingProductForId: function (config, params, xml, cb) {
        if (typeof xml == 'function') {
            cb = xml;
            xml = false;
        } else if (typeof xml == 'undefined') {
            console.warn("No callback provided. Throwing the request");
            return;
        }

        if (!_.has(params, 'MarketplaceId') || !_.has(params, 'IdType') || !_.has(params, 'IdList')) {
            cb({
                "Error": "You need to pass parameter MarketplaceId, IdType and IdList"
            }, null);
            return;
        }

        // Control the IdType - allowed only (ASIN,GCID,SellerSKU,UPC,EAN,ISBN,JAN)
        if (params['IdType'] !== 'ASIN' && params['IdType'] !== 'GCID' && params['IdType'] !== 'SellerSKU' && params['IdType'] !== 'UPC' && params['IdType'] !== 'EAN' && params['IdType'] !== 'JAN' && params['IdType'] !== 'ISBN') {
            cb({
                'Error': "Usage of unallowed IdType. Allowed are ASIN,GCID,SellerSKU,UPC,EAN,ISBN,JAN"
            }, null);
            return;
        }

        var parameters = {
            'MarketplaceId': params['MarketplaceId'],
            'IdType': params['IdType']
{'fraction_non_alphanumeric': 0.10598548972188633, 'fraction_numerical': 0.0007255139056831923, 'mean_word_length': 2.272853185595568, 'pattern_counts': {'":': 8, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 70}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '297477', 'n_tokens_mistral': 4414, 'n_tokens_neox': 4301, 'n_words': 1568}