ripe-tech / ripe-sdk

The public Javascript SDK for RIPE Core
https://www.platforme.com
Apache License 2.0
8 stars 4 forks source link

createAttachmentOrder with meta #282

Closed gcandal closed 3 years ago

gcandal commented 3 years ago

Rationale

The creation of order attachments expects a file and a meta dictionary (see https://github.com/ripe-tech/ripe-core/blob/ba23882efa65acb165e924c6f836c6933646604f/src/ripe_core/controllers/api/order.py#L97).

However, the current SDK implementation of the endpoint doesn't support meta (see https://github.com/ripe-tech/ripe-sdk/blob/c9e7b8ab715d4339ccaac26fbff734df6718a316/src/js/api/order.js#L201).

Description

The implementation of the rationale above could probably be similar to:

    options = Object.assign(options, {
        url: url,
        method: "POST",
        dataM: {
            file: file,
            meta: JSON.stringify(meta)
        },
        auth: true
    });

But unless I'm missing something obvious, ripe-sdk doesn't support strings as values when using a multipart payload dataM (see https://github.com/ripe-tech/ripe-sdk/blob/c9e7b8ab715d4339ccaac26fbff734df6718a316/src/js/base/api.js#L1238).

Trying to use them results in RangeError: offset is out of bounds because the string is not being encoded, resulting in this:

image

Related: https://github.com/ripe-tech/ripe-core/pull/4564

ripe-tobias-bot[bot] commented 3 years ago

Woof, Woof!

Thank you for submitting the "createAttachmentOrder with meta" issue 😎.

Please do not forget to review our internal guidelines:

Engaging in the development process in the best possible way helps it being efficient and fast.

Your friend, Tobias (Platforme's mascot)

Tobias Bot
joamag commented 3 years ago

The suggested implementation does not work... if working with multipart you cannot pass dictionaries

gcandal commented 3 years ago

You mean dictionaries as values? I didn't, I used a string.

joamag commented 3 years ago

yes, but on the server-side you'll not be able to de-serialize them automatically, so no good to pass JSON.dumps

joamag commented 3 years ago

You need to use something like meta in the order POST... and still the multi-part issue with strings (in the SDK) would have to be fixed

joamag commented 3 years ago

ok maybe I'm wrong and now we support automatic JSON casting in Appier... Go ahead and try to see what's wrong with the multi-part encoding... But check the appier and yonius implementations as the multipart encoder should be aligned with both

Screenshot 2021-06-08 at 11 40 19
joamag commented 3 years ago

@gcandal let's also create some unit tests to avoid regression for this mixed types multipart situation

gcandal commented 3 years ago

Requires https://github.com/hivesolutions/appier/pull/47