Magento - OSR - Typescript CLI client
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
guenter.baumgart a41ead28ca updates 5 months ago
src updates 5 months ago
tools v1 10 months ago
.gh-sync.json init 10 months ago
.gitignore init 10 months ago
.npmignore init 10 months ago
Readme.md latest 10 months ago
api.d.ts custom.d.ts & npm bump 10 months ago
api.js update deps 6 months ago
api.js.map remove test 10 months ago
configuration.d.ts v1 10 months ago
configuration.js update deps 6 months ago
configuration.js.map v1 10 months ago
index.d.ts v1 10 months ago
index.js update deps 6 months ago
index.js.map updates 5 months ago
package.json updates 5 months ago
tsconfig.json v1 10 months ago
tslint.json init 10 months ago

Readme.md

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