0.7.1 • Published 26 days ago

@quatico/magellan-client v0.7.1

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
github
Last release
26 days ago

Transport configuration

Magellan uses the global.qsMagellanConfig object to access transport configurations at runtime.

{
    "namespaces": {
        "default": {
            "endpoint": "/api",
            "transport": "default"
        }
    }
}

This configuration is injected to the window object by @quatico/magellan-client/lib/transport/config.js which can be replaced during bundling with Webpack to invoke a request against a my-api endpoint, merging its transport configuration if another magellan-client based frontend was already loaded previously.

magellan.config.js

const createFormData = ({name, payload, namespace}) => {
    const formData = new FormData();
    formData.set("name", name);
    formData.set("data", payload);
    formData.set("namespace", namespace);
    return formData;
};

// func is of type @quatico/magellan-client TransportFunction
const myTransportFunction = async func => {
    const {name, payload, namespace, endpoint} = func;
    if (!name) {
        throw new Error('Cannot invoke this remote function without "name" property.');
    }
    try {
        const response = await fetch(endpoint, {
            method: "POST",
            body: createFormData({name, payload, namespace}),
        });
        return await response.text();
    } catch (err) {
        throw new Error(`Cannot invoke remote function: "${name}". Reason: "${err}".`);
    }
};
module.exports = {
    namespaces: {"test-namespace": {endpoint: "/my-api", transport: "my-transport"}},
    transports: {"my-transport": myTransportFunction},
    merge: true
};

webpack.config.js

plugins: [
    new webpack.NormalModuleReplacementPlugin(
        /@quatico[\\/]magellan-client[\\/]lib[\\/]transport[\\/]config.js/,
        path.join(__dirname, "magellan.config.js")
    ),
]
0.7.1

26 days ago

0.7.0

1 month ago

0.6.2

1 month ago

0.6.1

3 months ago

0.6.0

3 months ago

0.5.5

5 months ago

0.5.4

5 months ago

0.5.3

5 months ago

0.4.5

8 months ago

0.4.4

8 months ago

0.5.0

6 months ago

0.5.2

6 months ago

0.4.3

9 months ago

0.5.1

6 months ago

0.3.0

1 year ago

0.2.1

1 year ago

0.2.2

1 year ago

0.2.0

1 year ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago