@viyet/magento-client
Version:
Sotheby's Home Custom Magento API Client
235 lines (220 loc) • 12.3 kB
HTML
<html class="default no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>@viyet/magento-client</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="assets/css/main.css">
</head>
<body>
<header>
<div class="tsd-page-toolbar">
<div class="container">
<div class="table-wrap">
<div class="table-cell" id="tsd-search" data-index="assets/js/search.js" data-base=".">
<div class="field">
<label for="tsd-search-field" class="tsd-widget search no-caption">Search</label>
<input id="tsd-search-field" type="text" />
</div>
<ul class="results">
<li class="state loading">Preparing search index...</li>
<li class="state failure">The search index is not available</li>
</ul>
<a href="index.html" class="title">@viyet/magento-client</a>
</div>
<div class="table-cell" id="tsd-widgets">
<div id="tsd-filter">
<a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a>
<div class="tsd-filter-group">
<div class="tsd-select" id="tsd-filter-visibility">
<span class="tsd-select-label">All</span>
<ul class="tsd-select-list">
<li data-value="public">Public</li>
<li data-value="protected">Public/Protected</li>
<li data-value="private" class="selected">All</li>
</ul>
</div>
<input type="checkbox" id="tsd-filter-inherited" checked />
<label class="tsd-widget" for="tsd-filter-inherited">Inherited</label>
<input type="checkbox" id="tsd-filter-only-exported" />
<label class="tsd-widget" for="tsd-filter-only-exported">Only exported</label>
</div>
</div>
<a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a>
</div>
</div>
</div>
</div>
<div class="tsd-page-title">
<div class="container">
<ul class="tsd-breadcrumb">
<li>
<a href="globals.html">Globals</a>
</li>
</ul>
<h1> @viyet/magento-client</h1>
</div>
</div>
</header>
<div class="container container-main">
<div class="row">
<div class="col-8 col-content">
<div class="tsd-panel tsd-typography">
<h1 id="sothebys-home-magento-custom-api-client">Sothebys Home Magento Custom API Client</h1>
<p>A package that connects to Sothebys Home Magento Custom API</p>
<h2 id="installation">Installation</h2>
<pre><code class="language-sh">npm install @viyet/magento-client --save</code></pre>
<h2 id="usage">Usage</h2>
<pre><code class="language-javascript"><span class="hljs-keyword">import</span> { MagentoClient } <span class="hljs-keyword">from</span> <span class="hljs-string">"@viyet/magento-client"</span>;
<span class="hljs-comment">//Optional Client Configuration</span>
<span class="hljs-comment">//You can change baseURL value to hit staging, for instance</span>
<span class="hljs-keyword">const</span> myConfig = {
<span class="hljs-attr">api</span>: {
<span class="hljs-attr">baseUrl</span>: <span class="hljs-string">"https://staging.sothebyshome.biz/"</span>,
}
};
<span class="hljs-comment">//Instantiate class</span>
<span class="hljs-keyword">const</span> client = <span class="hljs-keyword">new</span> MagentoClient(myConfig);
<span class="hljs-comment">//Log in</span>
<span class="hljs-keyword">const</span> response = client.auth.login({
<span class="hljs-attr">email</span>: <span class="hljs-string">"email@domain.tld"</span>,
<span class="hljs-attr">password</span>: <span class="hljs-string">"password"</span>
});
<span class="hljs-comment">//After Log in you can start calling module methods</span>
login.then(<span class="hljs-function"><span class="hljs-params">response</span> =></span> {
<span class="hljs-keyword">const</span> headers = response.headers;
<span class="hljs-comment">//Make a Cookies string from Set-Cookie response header</span>
<span class="hljs-keyword">const</span> cookiesString = headers[<span class="hljs-string">"set-cookie"</span>].reduce(<span class="hljs-function">(<span class="hljs-params">prev, curr</span>) =></span> (prev + <span class="hljs-string">"; "</span> + curr.split(<span class="hljs-string">";"</span>)[<span class="hljs-number">0</span>]), <span class="hljs-string">""</span>);
<span class="hljs-comment">//Fetch User data</span>
<span class="hljs-keyword">const</span> userData = client.auth.findLoggedInUserByHeaders({<span class="hljs-string">"Cookie"</span>: cookiesString});
userData.then(<span class="hljs-function"><span class="hljs-params">response</span> =></span> {
<span class="hljs-comment">//Fetch User Offers - Here we also set "X-Requested-With" header, Magento API requires it on these routes</span>
<span class="hljs-keyword">const</span> offers = client.offers.findAll({}, {<span class="hljs-string">"X-Requested-With"</span>:<span class="hljs-string">"XMLHttpRequest"</span>, <span class="hljs-string">"Cookie"</span>: cookiesString});
});
});
<span class="hljs-comment">//Register new user</span>
<span class="hljs-keyword">const</span> response = client.auth.register({
<span class="hljs-attr">email</span>: <span class="hljs-string">"email@domain.tld"</span>,
<span class="hljs-attr">firstName</span>: <span class="hljs-string">"John"</span>,
<span class="hljs-attr">isDesigner</span>: <span class="hljs-literal">false</span>,
<span class="hljs-attr">lastName</span>: <span class="hljs-string">"Doe"</span>,
<span class="hljs-attr">password</span>: <span class="hljs-string">"verySecure"</span>,
<span class="hljs-attr">phone</span>: <span class="hljs-string">"666-777-8888"</span>,
<span class="hljs-attr">isSothebysCustomer</span>: <span class="hljs-literal">false</span>
});</code></pre>
<hr>
<h2 id="complete-documentation">Complete Documentation</h2>
<p>Link to <a href="./docs/index.html">complete Magento Client documentation</a></p>
</div>
</div>
<div class="col-4 col-menu menu-sticky-wrap menu-highlight">
<nav class="tsd-navigation primary">
<ul>
<li class="globals ">
<a href="globals.html"><em>Globals</em></a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_magentoclient_.html">"<wbr>Magento<wbr>Client"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_config_default_.html">"config/default"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_index_.html">"index"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_modules_auth_.html">"modules/<wbr>Auth"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_modules_checkout_.html">"modules/<wbr>Checkout"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_modules_offers_.html">"modules/<wbr>Offers"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_modules_products_.html">"modules/<wbr>Products"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_modules_transport_.html">"modules/<wbr>Transport"</a>
</li>
<li class=" tsd-kind-external-module">
<a href="modules/_modules_users_.html">"modules/<wbr>Users"</a>
</li>
</ul>
</nav>
<nav class="tsd-navigation secondary menu-sticky">
<ul class="before-current">
</ul>
</nav>
</div>
</div>
</div>
<footer class="with-border-bottom">
<div class="container">
<h2>Legend</h2>
<div class="tsd-legend-group">
<ul class="tsd-legend">
<li class="tsd-kind-module"><span class="tsd-kind-icon">Module</span></li>
<li class="tsd-kind-object-literal"><span class="tsd-kind-icon">Object literal</span></li>
<li class="tsd-kind-variable"><span class="tsd-kind-icon">Variable</span></li>
<li class="tsd-kind-function"><span class="tsd-kind-icon">Function</span></li>
<li class="tsd-kind-function tsd-has-type-parameter"><span class="tsd-kind-icon">Function with type parameter</span></li>
<li class="tsd-kind-index-signature"><span class="tsd-kind-icon">Index signature</span></li>
<li class="tsd-kind-type-alias"><span class="tsd-kind-icon">Type alias</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-enum"><span class="tsd-kind-icon">Enumeration</span></li>
<li class="tsd-kind-enum-member"><span class="tsd-kind-icon">Enumeration member</span></li>
<li class="tsd-kind-property tsd-parent-kind-enum"><span class="tsd-kind-icon">Property</span></li>
<li class="tsd-kind-method tsd-parent-kind-enum"><span class="tsd-kind-icon">Method</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-interface"><span class="tsd-kind-icon">Interface</span></li>
<li class="tsd-kind-interface tsd-has-type-parameter"><span class="tsd-kind-icon">Interface with type parameter</span></li>
<li class="tsd-kind-constructor tsd-parent-kind-interface"><span class="tsd-kind-icon">Constructor</span></li>
<li class="tsd-kind-property tsd-parent-kind-interface"><span class="tsd-kind-icon">Property</span></li>
<li class="tsd-kind-method tsd-parent-kind-interface"><span class="tsd-kind-icon">Method</span></li>
<li class="tsd-kind-index-signature tsd-parent-kind-interface"><span class="tsd-kind-icon">Index signature</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-class"><span class="tsd-kind-icon">Class</span></li>
<li class="tsd-kind-class tsd-has-type-parameter"><span class="tsd-kind-icon">Class with type parameter</span></li>
<li class="tsd-kind-constructor tsd-parent-kind-class"><span class="tsd-kind-icon">Constructor</span></li>
<li class="tsd-kind-property tsd-parent-kind-class"><span class="tsd-kind-icon">Property</span></li>
<li class="tsd-kind-method tsd-parent-kind-class"><span class="tsd-kind-icon">Method</span></li>
<li class="tsd-kind-accessor tsd-parent-kind-class"><span class="tsd-kind-icon">Accessor</span></li>
<li class="tsd-kind-index-signature tsd-parent-kind-class"><span class="tsd-kind-icon">Index signature</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-constructor tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited constructor</span></li>
<li class="tsd-kind-property tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited property</span></li>
<li class="tsd-kind-method tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited method</span></li>
<li class="tsd-kind-accessor tsd-parent-kind-class tsd-is-inherited"><span class="tsd-kind-icon">Inherited accessor</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-property tsd-parent-kind-class tsd-is-protected"><span class="tsd-kind-icon">Protected property</span></li>
<li class="tsd-kind-method tsd-parent-kind-class tsd-is-protected"><span class="tsd-kind-icon">Protected method</span></li>
<li class="tsd-kind-accessor tsd-parent-kind-class tsd-is-protected"><span class="tsd-kind-icon">Protected accessor</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-property tsd-parent-kind-class tsd-is-private"><span class="tsd-kind-icon">Private property</span></li>
<li class="tsd-kind-method tsd-parent-kind-class tsd-is-private"><span class="tsd-kind-icon">Private method</span></li>
<li class="tsd-kind-accessor tsd-parent-kind-class tsd-is-private"><span class="tsd-kind-icon">Private accessor</span></li>
</ul>
<ul class="tsd-legend">
<li class="tsd-kind-property tsd-parent-kind-class tsd-is-static"><span class="tsd-kind-icon">Static property</span></li>
<li class="tsd-kind-call-signature tsd-parent-kind-class tsd-is-static"><span class="tsd-kind-icon">Static method</span></li>
</ul>
</div>
</div>
</footer>
<div class="container tsd-generator">
<p>Generated using <a href="http://typedoc.org/" target="_blank">TypeDoc</a></p>
</div>
<div class="overlay"></div>
<script src="assets/js/main.js"></script>
<script>if (location.protocol == 'file:') document.write('<script src="assets/js/search.js"><' + '/script>');</script>
</body>
</html>