UNPKG

@ikas/admin-api-client

Version:

ikas public node api client for store apps and private apps

62 lines 2.56 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __exportStar = (this && this.__exportStar) || function(m, exports) { for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.OAuthAPI = void 0; const axios_1 = __importDefault(require("axios")); const qs_1 = __importDefault(require("qs")); const models_1 = require("./models"); const globals_1 = require("../../globals"); __exportStar(require("./models"), exports); class OAuthAPI { static getOAuthUrl(options) { return `https://${options.storeName}${options.storeDomain || globals_1.STORE_DOMAIN}/api/admin/oauth`; } static async getTokenWithAuthorizationCode(request, options) { return axios_1.default.post(`${OAuthAPI.getOAuthUrl(options)}/token`, qs_1.default.stringify({ ...request, grant_type: models_1.GrantTypeEnum.AUTHORIZATION_CODE, }), { headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, }); } static async refreshToken(request, options) { return axios_1.default.post(`${OAuthAPI.getOAuthUrl(options)}/token`, qs_1.default.stringify({ ...request, grant_type: models_1.GrantTypeEnum.REFRESH_TOKEN, }), { headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, }); } static async getTokenWithClientCredentials(request, options) { return axios_1.default.post(`${OAuthAPI.getOAuthUrl(options)}/token`, qs_1.default.stringify({ ...request, grant_type: models_1.GrantTypeEnum.CLIENT_CREDENTIALS, }), { headers: { 'Content-Type': 'application/x-www-form-urlencoded', }, }); } } exports.OAuthAPI = OAuthAPI; //# sourceMappingURL=index.js.map