This repository has been archived on 2021-12-11. You can view files and clone it, but cannot push or open issues or pull requests.
magento-ts-client/Readme.md
2021-07-24 13:30:56 +02:00

43 lines
1.3 KiB
Markdown

# Magento Typescript client
## Installation
```bash
npm i @plastichub/magento
```
## Usage
```typescript
import { Magento } 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 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](https://shop.plastic-hub.com/swagger)
2. Drop the content at [https://app.swaggerhub.com/](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](./tools/clean_magento) to fix the swagger-io bugs for unresolved types
7. Done ;-)