@plastichub/magento
v1.0.17
Published
```bash npm i @plastichub/magento ```
Downloads
3
Readme
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
- Grab your swagger config from (make sure you are logged in) https://shop.plastic-hub.com/swagger
- Drop the content at https://app.swaggerhub.com/
- Export client -> typescrip-node-fetch-client
- Include the generated api.ts
- Drop the typescript compiler error output in a file, eg
tsc -p . > shop_errors
- Run ./tools/clean_magento to fix the swagger-io bugs for unresolved types
- 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