|
| 1 | +import { MCSetsAPI } from 'mcsets-js-sdk-client' |
| 2 | +import dotenv from 'dotenv' |
| 3 | + |
| 4 | +// Inject ENV vars from ENV file |
| 5 | +dotenv.config({quiet: true}) |
| 6 | + |
| 7 | +// Create constants with API keys from ENV vars |
| 8 | +const enterpriseApiKey = process.env.ENTERPRISE_API_KEY |
| 9 | +const setStorePluginApiKey = process.env.SETSTORE_PLUGIN_API_KEY |
| 10 | +const setStoreConnectionApiKey = process.env.SETSTORE_CONNECTION_API_KEY |
| 11 | + |
| 12 | +// Base API required no auth so we will set the key to null |
| 13 | +const baseApi = MCSetsAPI.from(null, 'base') |
| 14 | + |
| 15 | +const enterpriseApi = MCSetsAPI.from(enterpriseApiKey, 'enterprise') |
| 16 | + |
| 17 | +// Create two set store API instances with both API keys to support both auth methods |
| 18 | +const setStorePluginApi = MCSetsAPI.from(setStorePluginApiKey, 'setstore') |
| 19 | +const setStoreConnectionApi = MCSetsAPI.from(setStoreConnectionApiKey, 'setstore') |
| 20 | + |
| 21 | +/** |
| 22 | + * Example API calls are made below |
| 23 | + */ |
| 24 | + |
| 25 | +// Use base API to fetch health status (no auth required) |
| 26 | +await baseApi.getHealth().then(console.log) |
| 27 | + |
| 28 | +// Use the enterprise API to fetch products (requires enterprise API key, see ENV for key examples) |
| 29 | +await enterpriseApi.getProducts().then(console.log) |
| 30 | + |
| 31 | +// Use the set store plugin API to fetch pending delivery commands (requires set store plugin API key, see ENV for key examples) |
| 32 | +await setStorePluginApi.fetchPendingDeliveryCommands().then(console.log) |
0 commit comments