npm promulgates marsupials

    @plastichub/magento
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.17 • Public • Published

    Magento Typescript client

    Installation

    npm i @plastichub/magento

    Usage

    import { Magento, API } from '@plastichub/magento';
    
    process.on('unhandledRejection', (reason: string) => {
        console.error('Unhandled rejection, reason: ', reason);
    });
    
    // init with profile.json : {
    //    "username":"admin",
    //    "password":"password"
    //}
     
    await Magento.initWithProfile('~/.magento.json', 'https://shop.plastic-hub.com/rest/all');
    
    // await Magento.init('https://shop.plastic-hub.com/rest/all', 'admin', 'password');
    console.log('Magento API Config', Magento.apiConfig);
    const storeApi = new API.StoreStoreRepositoryV1Api(Magento.apiConfig);
    const stores = await storeApi.storeStoreRepositoryV1GetListGet({});
    console.log('stores', stores);

    Re-generate API via Swagger

    1. Grab your swagger config from (make sure you are logged in) https://shop.plastic-hub.com/swagger
    2. Drop the content at https://app.swaggerhub.com/
    3. Export client -> typescrip-node-fetch-client
    4. Include the generated api.ts
    5. Drop the typescript compiler error output in a file, eg tsc -p . > shop_errors
    6. Run ./tools/clean_magento to fix the swagger-io bugs for unresolved types
    7. Now add in the api.ts the following content :
    const realFetch = require('node-fetch');
    let auth = {}
    
    export const setAuth = (options) => {
        auth = options;
    }
    
    const portableFetch: any = (url, options) => 
        realFetch.call(this, url, { ... options, ...auth});

    Otherwise the access token won't be processed by the API, eg : 403

    Enjoy Magento

    Keywords

    none

    Install

    npm i @plastichub/magento

    DownloadsWeekly Downloads

    0

    Version

    1.0.17

    License

    ISC

    Unpacked Size

    3.98 MB

    Total Files

    15

    Last publish

    Collaborators

    • plastichubdev