open-index/open-npm huggingface dataset:
npm package: @shopletzy/shop-sdk
Description: Shop SDK for Shopletzy Storefront APIs
Author: Shopletzy
Latest version: 0.1.37

# [Shopletzy](https://shopletzy.com) JavaScript Shop SDK

[![npm version][npmimg]][npm]
[![Downloads][downloadsimg]][downloads]

Shop SDK provides nice javascript api to interact with Shopletzy Storefront APIs

- [Shopletzy JavaScript Shop SDK](#shopletzy-javascript-shop-sdk)
  - [Getting started](#getting-started)
    - [Installation](#installation)

## Getting started

### Installation
This library is distributed on `npm`. In order to add it as a dependency, run the following command:

``` sh
$ npm i @shopletzy/shop-sdk
```

[npmimg]: https://img.shields.io/npm/v/@shopletzy/shop-sdk.svg
[npm]: https://www.npmjs.org/package/@shopletzy/shop-sdk
[downloadsimg]: https://img.shields.io/npm/dm/@shopletzy/shop-sdk.svg
[downloads]: https://www.npmjs.com/package/@shopletzy/shop-sdk

                    if (url.includes("locations")) {
                        url = 'https://shop-api.testing.shopletzy.com' + url
                    } else {
                        url = 'http://localhost:4000' + url
                    }
npm package: @shopline/admin-embedded-app-sdk
Description: Admin Embedded App SDK
Latest version: 1.3.1

## AdminEmbeddedAppSdk
AdminEmbeddedAppSdk lives in an iframe. It provides interface to trigger request to EC Admin(parent frame)

### Configuration

```javascript
import { AdminEmbeddedAppSdk } from 'admin-app-extension';

const clientId = 'developer app client id';
const authUrl = 'https://developer.com/auth'
const AdminEmbeddedAppSdk = await AdminEmbeddedAppSdk.init({clientId, authUrl});
```

### API References

---
> adminEmbeddedAppSdk.onLanguageChanged(callback)

- Triggered when admin language is changed
- Returns an unsubscribe function

```javascript
// to subscribe
const unsubscribe = adminEmbeddedAppSdk.onLanguageChanged(function(language) {
  console.log(language)
});

// to unsubscribe
unsubscribe();
```

---
> adminEmbeddedAppSdk.getSessionToken()

- returning a JWT token used to identify current logged in user
- session token contains `staff_id`, `merchant_id`, `client_id` in token payload
   
```javascript
const sessionToken = await adminEmbeddedAppSdk.getSessionToken();
```

---
> adminEmbeddedAppSdk.redirect(`url`)

- performing a parent frame redirect

```javascript
adminEmbeddedAppSdk.redirect('https://shoplineapp.com')
```
---
> adminEmbeddedAppSdk.goBack()

- navigate to the last route. will not exit the admin app.

```javascript
adminEmbeddedAppSdk.goBack()
```
---
> adminEmbeddedAppSdk.oauth()

- execute the oauth flow to obtain access token 

```javascript
adminEmbeddedAppSdk.oauth()
```

---
> adminEmbeddedAppSdk.getLanguage()

- get the current language setting from EC Admin

```javascript
  const language = await adminEmbeddedAppSdk.getLanguage()
```

---

> adminEmbeddedAppSdk.getCurrentUrl()

- get the top frame url

```javascript
  const parentUrl = await adminEmbeddedAppSdk.getCurrentUrl()
```

---
> adminEmbeddedAppSdk.routeChange()

- notify parent frame to update the top frame route

```javascript
const path = '/page1';
const querystring = 'foo=bar&bar=foo';
adminEmbeddedAppSdk.routeChange(path, querystring)
```

---
> adminEmbeddedAppSdk.intercom()

- open intercom dialog in EC Admin

```javascript
adminEmbeddedAppSdk.intercom()
```

---
> adminEmbeddedAppSdk.changePageTitle()

- change page title in EC Admin

```javascript
adminEmbeddedAppSdk.changePageTitle('Demo Page Title')
```

---
> adminEmbeddedAppSdk.interceptRouteChange(callback)

- Intercept admin route change and trigger callback
- Returns a function to stop interception

```javascript
// to intercept
const stopInterception = adminEmbeddedAppSdk.interceptRouteChange(function(fromUrl, toUrl) {
  console.log('From:', fromUrl);
  console.log('To:', toUrl);
});

// to stop interception
stopInterception();
```

---
> adminEmbeddedAppSdk.retryRouteChange()

- Notify EC Admin to retry the latest intercepted route change

```javascript
adminEmbeddedAppSdk.retryRouteChange();
```