ericblade / mws-advanced

Javascript (node) Amazon Merchant Web Services (MWS) code with mws-simple as it's underpinnings
Apache License 2.0
41 stars 11 forks source link

add a handler for 3-7-7 orderId format to validation.js::isValid #12

Open ericblade opened 6 years ago

ericblade commented 6 years ago

... should check that an item is a string, matching the (3-digit)-(7-digit)-(7-digit) amazon order ID format.

Useful in ListFinancialEvents (AmazonOrderId) parameter, among others.

aflansburg commented 6 years ago

I've rolled a method for this, but I'm not sure how to include - could not find an isValid method currently and wasn't quite sure if you meant it should be included somehow in validation.js::validateAndTransfromParameters.

const isValid = (value, type) => {
    let valid = false;
    switch (type) {
        default:
            console.log('No valid type supplied for validation.');
            break;
        case 'orderId': {
            const re = new RegExp('\\d{3}-\\d{7}-\\d{7}', 'g');
            if (re.test(value)) {
                valid = true;
            }
        }
    }
    return valid;
};
ericblade commented 6 years ago

i meant isType. i thought i had renamed it isValid at some point. maybe that makes more sense.

I guess let's add that to isType, call it amazonOrderId (some calls may have a sellerOrderId or something similar), and.. throw an error describing that it's not the correct format, if it fails the regex match?

aflansburg commented 6 years ago

Sorry to rehash this, but the isType function seems to validate type exclusively currently. Wouldn't 'amazonOrderId' and 'sellerOrderId' be validated by the 'xs:string' case already? If we create another validation method that validates format we could include order ID validation as well as ASINs and other specific formats. Not sure if I'm going off the rails here in regards to my understanding of what validation.js is doing.

ericblade commented 6 years ago

I was thinking that as well, there are probably at least a few other string types that could use format validation. I know in at least one of the mws apis they refer to orderid or marketid as something other than xs:string, but I can't find it right off hand right now.

I would also agree with adding a format parameter that can be specified to validate string formats to a spec.

On the bright side, if we do it one way then decide a different way is better it doesn't affect users to any degree really. :)

On Dec 8, 2017 3:38 PM, "Abram Flansburg" notifications@github.com wrote:

Sorry to rehash this, but the isType function seems to validate type exclusively currently. Wouldn't 'amazonOrderId' and 'sellerOrderId' be validated by the 'xs:string' case already? If we create another validation method that validates format we could include order ID validation as well as ASINs and other specific formats. Not sure if I'm going off the rails here in regards to my understanding of what validation.js is doing.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/ericblade/mws-advanced/issues/12#issuecomment-350366253, or mute the thread https://github.com/notifications/unsubscribe-auth/ABYnR7vqooO3_d6KX_GetY44eHR1uLI_ks5s-Z5WgaJpZM4Qv3BW .