@tiendanube/nexo 0.1.5 → 0.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.prettierrc ADDED
@@ -0,0 +1,4 @@
1
+ {
2
+ "singleQuote": true,
3
+ "trailingComma": "all"
4
+ }
package/README.md CHANGED
@@ -1 +1,395 @@
1
- # nexo
1
+ # `@tiendanube/nexo`
2
+ ***Nexo*** provides tools that allow communication between an external application and the Nuvemshop administrator.
3
+
4
+ Communication between the Admin and the App is done through messages following the observer pattern ( events subscribe/unsubscribe)
5
+
6
+ The messages that can be exchanged and are defined as [Actions](#actions), these actions are typed and associated to [Helpers](#helpers) that allows them to be used as promises
7
+
8
+ - [`@tiendanube/nexo`](#tiendanubenexo)
9
+ - [Instalation](#instalation)
10
+ - [Getting Started](#getting-started)
11
+ - [Create a Nexo instance.](#create-a-nexo-instance)
12
+ - [Check if the app is connected](#check-if-the-app-is-connected)
13
+ - [Enable route synchronization](#enable-route-synchronization)
14
+ - [Get Session Token](#get-session-token)
15
+ - [Actions](#actions)
16
+ - [Helpers](#helpers)
17
+ - [connect](#connect)
18
+ - [iAmReady](#iamready)
19
+ - [navigateExit](#navigateexit)
20
+ - [getSessionToken](#getsessiontoken)
21
+ - [syncPathname](#syncpathname)
22
+ - [getStoreInfo](#getstoreinfo)
23
+ - [getIsMobileDevice](#getismobiledevice)
24
+ - [goTo](#goto)
25
+ - [goToOldAdmin](#gotooldadmin)
26
+ - [copyToClipboard](#copytoclipboard)
27
+ - [navigateHeader](#navigateheader)
28
+ - [navigateHeaderRemove](#navigateheaderremove)
29
+
30
+ ## Instalation
31
+ ```
32
+ $ npm install @tiendanube/nexo
33
+ ```
34
+ ```
35
+ $ yarn add @tiendanube/nexo
36
+ ```
37
+ ## Getting Started
38
+
39
+ ### Create a Nexo instance.
40
+
41
+ | Config | Type | Description |
42
+ |----------|---------------------------|--------------------------------------------------------------------|
43
+ | clientId | `string` required | This value is provided by Nuvemshop |
44
+ | log | `boolean` default `false` | Allows to show the message transfers between the App and the Admin |
45
+
46
+ ```ts
47
+ import nexo from '@tiendanube/nexo';
48
+
49
+ const instance = nexo.create({
50
+ clientId: '123',
51
+ log: true,
52
+ });
53
+
54
+ export default instance;
55
+
56
+ ```
57
+
58
+ ### Check if the app is connected
59
+ Through the `connect` util you can check if the Admin allows you to exchange messages and at the same time with `iAmReady` notify that your application is ready to show.
60
+
61
+ To react application
62
+ ```tsx
63
+ import { useEffect, useState } from 'react';
64
+ import { connect, iAmReady } from '@tiendanube/nexo/helpers';
65
+ import nexo from './nexoClient'; // Nexo instance
66
+
67
+ function App() {
68
+ const [isConnect, setIsConnect] = useState(false);
69
+
70
+ useEffect(() => {
71
+ connect(nexo).then(() => {
72
+ setIsConnect(true);
73
+ iAmReady(nexo);
74
+ });
75
+ }, []);
76
+
77
+ if (!isConnect) return <MyAppSkeleton />;
78
+
79
+ return <MyApp />
80
+ }
81
+ ```
82
+
83
+ ### Enable route synchronization
84
+
85
+ This functionality will allow you to record the app navigation of your app in the browser URL via fragment (#myroute)
86
+
87
+ This example is made with `react-router-dom`
88
+
89
+ ```jsx
90
+ import { useEffect } from 'react';
91
+
92
+ import { useLocation, useHistory } from 'react-router-dom';
93
+ import { syncPathname } from '@tiendanube/nexo/helpers';
94
+ import nexo from './nexoClient';
95
+ import {
96
+ ACTION_NAVIGATE_SYNC,
97
+ NavigateSyncResponse,
98
+ } from '@tiendanube/nexo/actions';
99
+
100
+ function NexoSyncRoute({ children }: { children: React.ReactNode }) {
101
+ const { pathname } = useLocation();
102
+ const { push: goTo, replace: replaceTo } = useHistory();
103
+
104
+ //to send the current path of the app to the browser url
105
+ useEffect(() => {
106
+ syncPathname(nexo, pathname);
107
+ }, [pathname]);
108
+
109
+ //to navigate in the app if the browser url changes
110
+ useEffect(() => {
111
+ const unsuscribe = nexo.suscribe(
112
+ ACTION_NAVIGATE_SYNC,
113
+ ({ path, replace }: NavigateSyncResponse) => {
114
+ replace ? goTo(path) : replaceTo(path);
115
+ },
116
+ );
117
+
118
+ return unsuscribe;
119
+ }, [goTo, replaceTo]);
120
+
121
+ return children;
122
+
123
+ ```
124
+
125
+ ### Get Session Token
126
+ Through the `getSessionToken` util we can obtain a session token (JWT) that will be used to verify the authenticity of the request to your Backend. The JWT is signed with the Application's Client Secret
127
+
128
+ ```ts
129
+ import axios from "axios";
130
+ import { getSessionToken } from '@tiendanube/nexo/helpers';
131
+ import nexo from "./nexoClient";
132
+
133
+ const axiosIntance = axios.create({
134
+ baseURL: 'https://my-backend.com',
135
+ });
136
+
137
+ axiosIntance.interceptors.request.use(async (request) => {
138
+ const token = await getSessionToken(nexo);
139
+ const bearerToken = `Bearer ${token}`;
140
+ request.headers = { ...request.headers, Authorization: bearerToken };
141
+ return request;
142
+ });
143
+
144
+ export default axiosIntance;
145
+ ```
146
+ ## Actions
147
+
148
+ | Internal name | External name | Description | Payload request | Data response |
149
+ |-----------------------------|----------------------------------|-------------------------------------------------------------------------|------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------|
150
+ | `app/navigate/exit` | `ACTION_NAVEGATE_EXIT` | To navigate to the route from which the application was accessed. | - | - |
151
+ | `app/navigate/sync` | `ACTION_NAVIGATE_SYNC` | To update his current location to propagate the internal navegation. | `{ pathname: string }` | - |
152
+ | `app/navigate/goTo` | `ACTION_NAVIGATE_GOTO` | To navigate to a specific route in Admin | `{ pathname: string}` | `{ path: string, replace?: boolean }` |
153
+ | `app/navigate/pathname` | `ACTION_NAVIGATE_PATHNAME` | To current subPathname, which represents the path of the embedded app. | - | `{ pathname: string}` |
154
+ | `app/auth/sessionToken` | `ACTION_AUTH_SESSION_TOKEN` | To requests the session token (JWT) | - | `{ token: string }` |
155
+ | `app/store/info` | `ACTION_STORE_INFO` | To request information about current Store logged | - | `{ id: string, name: string, url: string, country: string, language: string, currency: string }` |
156
+ | `app/utils/copyToClipboard` | `ACTION_UTILS_COPY_TO_CLIPBOARD` | To copy the sent text to the device's clipboard | `{ text: string }` | `{ success: boolean }` |
157
+ | `app/navigate/goToOldAdmin` | `ACTION_NAVIGATE_GOTO_OLD_ADMIN` | To navigate to a specific route located in the old admin (admin/...) | `{ pathToOldAdmin: string}` | |
158
+ | `app/navigate/header` | `ACTION_NAVIGATE_HEADER` | To show the navigation action in the Header Top | `{ goTo?: 'back' \| string, goToAdmin?: string, text?: string, remove?: boolean }` | |
159
+ | `app/device` | `ACTION_DEVICE` | To requests information about if mobile device | - | `{ isMobileDevice: boolean}` |
160
+
161
+ ## Helpers
162
+
163
+ ### connect
164
+
165
+ To wait if the application is ready to render
166
+
167
+ **Arguments**
168
+ `nexo (NexoClient)`: The Nexo Instance
169
+ `ttl (number)`: Maximum time waiting for the admin, default 3000
170
+
171
+ **Response**
172
+ `Promise<void>` Success or Fail
173
+
174
+ **Example**
175
+ ```ts
176
+ connect(nexo).then(() => {
177
+ //success
178
+ }).catch(() => {
179
+ //fail
180
+ })
181
+ ```
182
+
183
+ ### iAmReady
184
+
185
+ To notify that the app is rendering
186
+
187
+ **Arguments**
188
+ `nexo (NexoClient)`: The Nexo Instance
189
+
190
+ **Response**
191
+ `void`
192
+
193
+ **Example**
194
+ ```ts
195
+ iAmReady(nexo);
196
+ ```
197
+
198
+ ### navigateExit
199
+
200
+ To navigate to the route from which the application was accessed.
201
+
202
+ **Action**: `app/navigate/exit`
203
+
204
+ **Arguments**
205
+ `nexo (NexoClient)`: The Nexo Instance
206
+
207
+ **Response**
208
+ `void`
209
+
210
+ **Example**
211
+ ```ts
212
+ navigateExit(nexo);
213
+ ```
214
+
215
+
216
+ ### getSessionToken
217
+
218
+ To requests the session token (JWT)
219
+
220
+ **Action**: `app/auth/sessionToken`
221
+
222
+ **Arguments**
223
+ `nexo (NexoClient)`: The Nexo Instance
224
+
225
+ **Response**
226
+ `Promise<token: string>`: Promise with session token
227
+
228
+ **Example**
229
+ ```ts
230
+ const token = await getSessionToken(nexo);
231
+ ```
232
+
233
+ ### syncPathname
234
+ To update his current location to propagate the internal navegation.
235
+
236
+ **Action**: `app/navigate/sync`
237
+
238
+ **Arguments**
239
+ `nexo (NexoClient)`: The Nexo Instance
240
+
241
+ **Response**
242
+ `Promise<token: string>`: Promise with session token
243
+
244
+ **Example**
245
+ ```ts
246
+ syncPathname(nexo, pathname);
247
+ ```
248
+
249
+ ### getStoreInfo
250
+ To request information about current Store
251
+
252
+ **Action**: `app/store/info`
253
+
254
+ **Arguments**
255
+ `nexo (NexoClient)`: The Nexo Instance
256
+
257
+ **Response**
258
+ `Promise<StoreInfoResponse>`: Promise with store info
259
+
260
+ ```ts
261
+ StoreInfoResponse {
262
+ id: string;
263
+ name: string;
264
+ url: string;
265
+ country: string;
266
+ language: string;
267
+ currency: string;
268
+ }
269
+ ```
270
+
271
+ **Example**
272
+ ```ts
273
+ const storeInfo = await getStoreInfo(nexo);
274
+ ```
275
+
276
+
277
+ ### getIsMobileDevice
278
+ To check if the app is being loaded from the Mobile Device
279
+
280
+ **Action**: `app/device`
281
+
282
+ **Arguments**
283
+ `nexo (NexoClient)`: The Nexo Instance
284
+
285
+ **Response**
286
+ `Promise<boolean>`: True / False
287
+
288
+ **Example**
289
+ ```ts
290
+ const isMobileDevice = await getIsMobileDevice(nexo);
291
+ ```
292
+
293
+ ### goTo
294
+
295
+ To navigate to a specific route in Admin
296
+
297
+ **Action**: `app/navigate/goTo`
298
+
299
+ **Arguments**
300
+ `nexo (NexoClient)`: The Nexo Instance
301
+ `path (string)`: Specific path to navigate
302
+
303
+ **Response**
304
+ `void`
305
+
306
+ **Example**
307
+ ```ts
308
+ goTo(nexo, '/products');
309
+ ```
310
+
311
+ ### goToOldAdmin
312
+
313
+ To navigate to a specific route in Old Admin, only available Web mode (non mobile device)
314
+
315
+ **Action**: `app/navigate/goToOldAdmin`
316
+
317
+ **Arguments**
318
+ `nexo (NexoClient)`: The Nexo Instance
319
+ `path (string)`: Specific path to navigate
320
+
321
+ **Response**
322
+ `void`
323
+
324
+ **Example**
325
+ ```ts
326
+ goToOldAdmin(nexo, '/products');
327
+ ```
328
+
329
+ ### copyToClipboard
330
+
331
+ To copy the sent text to the device's clipboard
332
+
333
+ **Action**: `app/utils/copyToClipboard`
334
+
335
+ **Arguments**
336
+ `nexo (NexoClient)`: The Nexo Instance
337
+ `text (string)`: Text to copy
338
+
339
+ **Response**
340
+ `Promise<boolean>`: If copied successfully
341
+
342
+ **Example**
343
+ ```ts
344
+ copyToClipboard(nexo, 'text to copy');
345
+ ```
346
+
347
+
348
+ ### navigateHeader
349
+
350
+ To show the navigation action in the Header Top, only available Web mode (non mobile device)
351
+
352
+ **Action**: `app/utils/copyToClipboard`
353
+
354
+ **Arguments**
355
+ `nexo (NexoClient)`: The Nexo Instance
356
+ `config (NavigateHeaderRequest)`: Config to navegate header
357
+
358
+ ```ts
359
+ NavigateHeaderRequest {
360
+ goTo: "back" | string;
361
+ text: string;
362
+ };
363
+ ```
364
+
365
+ **Response**
366
+ `void`
367
+
368
+ **Example**
369
+ ```ts
370
+ navigateHeader(nexo, { goTo: '/', text: 'Product List' });
371
+ //or
372
+ navigateHeader(nexo, { goTo: 'back', text: 'Back' });
373
+ ```
374
+
375
+
376
+ ### navigateHeaderRemove
377
+
378
+ Remove the action of Header Top, only available Web mode (non mobile device)
379
+
380
+ **Action**: `app/utils/copyToClipboard`
381
+
382
+ **Arguments**
383
+ `nexo (NexoClient)`: The Nexo Instance
384
+
385
+ **Response**
386
+ `void`
387
+
388
+ **Example**
389
+ ```ts
390
+ navigateHeaderRemove(nexo);
391
+ ```
392
+
393
+
394
+
395
+
@@ -45,7 +45,7 @@ export declare type NavigateGoToOldAdminRequest = {
45
45
  };
46
46
  export declare const ACTION_NAVIGATE_HEADER = "app/navigate/header";
47
47
  export declare type NavigateHeaderRequest = {
48
- goTo?: "back" | string;
48
+ goTo?: 'back' | string;
49
49
  goToAdmin?: string;
50
50
  text?: string;
51
51
  remove?: boolean;
@@ -1,16 +1,16 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ACTION_NAVIGATE_HEADER = exports.ACTION_NAVIGATE_GOTO_OLD_ADMIN = exports.ACTION_UTILS_COPY_TO_CLIPBOARD = exports.ACTION_STORE_INFO = exports.ACTION_DEVICE = exports.ACTION_AUTH_SESSION_TOKEN = exports.ACTION_NAVIGATE_SYNC = exports.ACTION_NAVIGATE_PATHNAME = exports.ACTION_NAVIGATE_GOTO = exports.ACTION_NAVIGATE_BACK = exports.ACTION_NAVIGATE_EXIT = exports.ACTION_CONNECTED = exports.ACTION_READY = void 0;
4
- exports.ACTION_READY = "app/ready";
5
- exports.ACTION_CONNECTED = "app/connected";
6
- exports.ACTION_NAVIGATE_EXIT = "app/navigate/exit";
7
- exports.ACTION_NAVIGATE_BACK = "app/navigate/back";
8
- exports.ACTION_NAVIGATE_GOTO = "app/navigate/goTo";
9
- exports.ACTION_NAVIGATE_PATHNAME = "app/navigate/pathname";
10
- exports.ACTION_NAVIGATE_SYNC = "app/navigate/sync";
11
- exports.ACTION_AUTH_SESSION_TOKEN = "app/auth/sessionToken";
4
+ exports.ACTION_READY = 'app/ready';
5
+ exports.ACTION_CONNECTED = 'app/connected';
6
+ exports.ACTION_NAVIGATE_EXIT = 'app/navigate/exit';
7
+ exports.ACTION_NAVIGATE_BACK = 'app/navigate/back';
8
+ exports.ACTION_NAVIGATE_GOTO = 'app/navigate/goTo';
9
+ exports.ACTION_NAVIGATE_PATHNAME = 'app/navigate/pathname';
10
+ exports.ACTION_NAVIGATE_SYNC = 'app/navigate/sync';
11
+ exports.ACTION_AUTH_SESSION_TOKEN = 'app/auth/sessionToken';
12
12
  exports.ACTION_DEVICE = 'app/device';
13
- exports.ACTION_STORE_INFO = "app/store/info";
14
- exports.ACTION_UTILS_COPY_TO_CLIPBOARD = "app/utils/copyToClipboard";
15
- exports.ACTION_NAVIGATE_GOTO_OLD_ADMIN = "app/navigate/goToOldAdmin";
16
- exports.ACTION_NAVIGATE_HEADER = "app/navigate/header";
13
+ exports.ACTION_STORE_INFO = 'app/store/info';
14
+ exports.ACTION_UTILS_COPY_TO_CLIPBOARD = 'app/utils/copyToClipboard';
15
+ exports.ACTION_NAVIGATE_GOTO_OLD_ADMIN = 'app/navigate/goToOldAdmin';
16
+ exports.ACTION_NAVIGATE_HEADER = 'app/navigate/header';
@@ -1 +1 @@
1
- export * from "./actions";
1
+ export * from './actions';
@@ -1,4 +1,4 @@
1
- import { Dispatch, Suscribe } from "./transporter";
1
+ import { Dispatch, Suscribe } from './transporter';
2
2
  declare type OnReady = (callback: () => void) => void;
3
3
  export interface NexoClient {
4
4
  clientId: string;
@@ -9,7 +9,7 @@ var create = function (_a) {
9
9
  var _c = (0, transporter_1.registerIframe)(log), dispatch = _c.dispatch, suscribe = _c.suscribe;
10
10
  var onReady = function (callback) {
11
11
  if (isReadyMutable) {
12
- throw new Error("onReady should be run only once");
12
+ throw new Error('onReady should be run only once');
13
13
  }
14
14
  var readyUnsuscribe = suscribe(actions_1.ACTION_CONNECTED, function () {
15
15
  callback();
@@ -5,16 +5,16 @@ var dispatchMessage = function (message) {
5
5
  if (window.parent === window) {
6
6
  return;
7
7
  }
8
- if (!("postMessage" in window.parent)) {
9
- console.error("can not send a event", message);
8
+ if (!('postMessage' in window.parent)) {
9
+ console.error('can not send a event', message);
10
10
  }
11
- logger("dispatched", message.type, message.payload);
12
- window.parent.postMessage(message, "*");
11
+ logger('dispatched', message.type, message.payload);
12
+ window.parent.postMessage(message, '*');
13
13
  };
14
14
  var createHandler = function (type, callback) {
15
15
  return function (message) {
16
16
  if (message.type === type) {
17
- logger("received", message.type, message.payload);
17
+ logger('received', message.type, message.payload);
18
18
  callback(message.payload);
19
19
  }
20
20
  };
@@ -22,11 +22,11 @@ var createHandler = function (type, callback) {
22
22
  exports.createHandler = createHandler;
23
23
  var logger = function (from, type, payload) {
24
24
  if (isLogged) {
25
- var color = from === "dispatched" ? "#f5ec7f" : "#00cc35";
26
- console.group("%c " + from, "color: " + color);
27
- console.log("👉 ", type);
25
+ var color = from === 'dispatched' ? '#f5ec7f' : '#00cc35';
26
+ console.group('%c ' + from, 'color: ' + color);
27
+ console.log('👉 ', type);
28
28
  var stringPayload = JSON.stringify(payload);
29
- stringPayload && console.log("📦 " + stringPayload);
29
+ stringPayload && console.log('📦 ' + stringPayload);
30
30
  console.groupEnd();
31
31
  }
32
32
  };
@@ -42,7 +42,7 @@ var registerIframe = function (log) {
42
42
  if (log === void 0) { log = false; }
43
43
  isLogged = log;
44
44
  var handlers = [];
45
- window.addEventListener("message", function (event) {
45
+ window.addEventListener('message', function (event) {
46
46
  handlers.forEach(function (handler) { return handler(event.data); });
47
47
  });
48
48
  return {
package/core/utils.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { NexoClient } from "./NexoClient";
2
- import { Message } from "./transporter";
1
+ import { NexoClient } from './NexoClient';
2
+ import { Message } from './transporter';
3
3
  export declare const message: <TPayload = unknown>(type: string, payload?: TPayload | undefined) => Message;
4
4
  export declare const asyncAction: <TResponse, TRequest = undefined>(nexo: NexoClient, action: string, payload?: TRequest | undefined) => Promise<TResponse>;
@@ -1,5 +1,5 @@
1
- import { StoreInfoResponse, NavigateHeaderRequest } from "../actions/actions";
2
- import { NexoClient } from "../core/nexoClient";
1
+ import { StoreInfoResponse, NavigateHeaderRequest } from '../actions/actions';
2
+ import { NexoClient } from '../core/nexoClient';
3
3
  export declare const connect: (nexo: NexoClient, ttl?: number) => Promise<void>;
4
4
  export declare const iAmReady: (nexo: NexoClient) => void;
5
5
  export declare const navigateExit: (nexo: NexoClient) => void;
@@ -10,6 +10,7 @@ export declare const syncPathname: (nexo: NexoClient, pathname: string) => void;
10
10
  export declare const getStoreInfo: (nexo: NexoClient) => Promise<StoreInfoResponse>;
11
11
  export declare const getIsMobileDevice: (nexo: NexoClient) => Promise<boolean>;
12
12
  export declare const goTo: (nexo: NexoClient, pathname: string) => void;
13
+ export declare const goToOldAdmin: (nexo: NexoClient, pathToOldAdmin: string) => void;
13
14
  export declare const copyToClipboard: (nexo: NexoClient, text: string) => Promise<boolean>;
14
15
  export declare const navigateHeader: (nexo: NexoClient, config: NavigateHeaderRequest) => void;
15
16
  export declare const navigateHeaderRemove: (nexo: NexoClient) => void;
@@ -36,14 +36,14 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
36
  }
37
37
  };
38
38
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.navigateHeaderRemove = exports.navigateHeader = exports.copyToClipboard = exports.goTo = exports.getIsMobileDevice = exports.getStoreInfo = exports.syncPathname = exports.getCurrentPathname = exports.getSessionToken = exports.navigateBack = exports.navigateExit = exports.iAmReady = exports.connect = void 0;
39
+ exports.navigateHeaderRemove = exports.navigateHeader = exports.copyToClipboard = exports.goToOldAdmin = exports.goTo = exports.getIsMobileDevice = exports.getStoreInfo = exports.syncPathname = exports.getCurrentPathname = exports.getSessionToken = exports.navigateBack = exports.navigateExit = exports.iAmReady = exports.connect = void 0;
40
40
  var actions_1 = require("../actions/actions");
41
41
  var utils_1 = require("../core/utils");
42
42
  var connect = function (nexo, ttl) {
43
43
  if (ttl === void 0) { ttl = 3000; }
44
44
  return new Promise(function (resolve, reject) {
45
45
  var timeOut = setTimeout(function () {
46
- reject(new Error("Timeout"));
46
+ reject(new Error('Timeout'));
47
47
  }, ttl);
48
48
  nexo.onReady(function () {
49
49
  resolve();
@@ -117,6 +117,10 @@ var goTo = function (nexo, pathname) {
117
117
  nexo.dispatch((0, utils_1.message)(actions_1.ACTION_NAVIGATE_GOTO, { pathname: pathname }));
118
118
  };
119
119
  exports.goTo = goTo;
120
+ var goToOldAdmin = function (nexo, pathToOldAdmin) {
121
+ nexo.dispatch((0, utils_1.message)(actions_1.ACTION_NAVIGATE_GOTO_OLD_ADMIN, { pathToOldAdmin: pathToOldAdmin }));
122
+ };
123
+ exports.goToOldAdmin = goToOldAdmin;
120
124
  var copyToClipboard = function (nexo, text) { return __awaiter(void 0, void 0, void 0, function () {
121
125
  var success;
122
126
  return __generator(this, function (_a) {
@@ -1 +1 @@
1
- export * from "./helpers";
1
+ export * from './helpers';
package/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { NexoClient } from "./core/nexoClient";
1
+ export { NexoClient } from './core/nexoClient';
2
2
  declare const nexo: {
3
3
  create: ({ clientId, log, }: {
4
4
  clientId: string;
package/package.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "name": "@tiendanube/nexo",
3
- "version": "0.1.5",
3
+ "version": "0.1.8",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",
7
7
  "scripts": {
8
8
  "build": "tsc",
9
- "test": "echo \"Error: no test specified\" && exit 1"
9
+ "test": "echo \"Error: no test specified\" && exit 1",
10
+ "lint": "eslint .",
11
+ "lint:fix": "eslint --fix",
12
+ "format": "prettier --write './**/*.{js,jsx,ts,tsx,css,md,json}' --config ./.prettierrc"
10
13
  },
11
14
  "repository": {
12
15
  "type": "git",
@@ -19,8 +22,13 @@
19
22
  },
20
23
  "homepage": "https://github.com/TiendaNube/cumulus#readme",
21
24
  "devDependencies": {
22
- "@types/react": "^17.0.1",
23
- "typescript": "4.7.4",
24
- "react": "^17.0.1"
25
+ "@typescript-eslint/eslint-plugin": "5.36.1",
26
+ "@typescript-eslint/parser": "5.36.1",
27
+ "eslint": "8.23.0",
28
+ "eslint-config-prettier": "8.5.0",
29
+ "eslint-plugin-prettier": "4.2.1",
30
+ "eslint-plugin-react": "7.31.1",
31
+ "prettier": "2.7.1",
32
+ "typescript": "4.8.2"
25
33
  }
26
34
  }
package/tsconfig.json CHANGED
@@ -1,23 +1,13 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "target": "es5",
4
- "lib": [
5
- "dom",
6
- "dom.iterable",
7
- "esnext"
8
- ],
4
+ "lib": ["dom", "dom.iterable", "esnext"],
9
5
  "module": "commonjs",
10
6
  "declaration": true,
11
7
  "outDir": ".",
12
8
  "strict": true,
13
- "jsx": "react-jsx",
14
- "esModuleInterop": true,
9
+ "esModuleInterop": true
15
10
  },
16
- "include": [
17
- "src"
18
- ],
19
- "exclude": [
20
- "node_modules",
21
- "**/__tests__/*"
22
- ]
23
- }
11
+ "include": ["src"],
12
+ "exclude": ["node_modules", "**/__tests__/*"]
13
+ }
package/react/index.d.ts DELETED
@@ -1 +0,0 @@
1
- export * from "./react";
package/react/index.js DELETED
@@ -1,17 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./react"), exports);
package/react/react.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import { NexoClient } from "../core/nexoClient";
2
- export declare function useNexoConnect(nexo: NexoClient): boolean;
package/react/react.js DELETED
@@ -1,66 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __generator = (this && this.__generator) || function (thisArg, body) {
12
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
- function verb(n) { return function (v) { return step([n, v]); }; }
15
- function step(op) {
16
- if (f) throw new TypeError("Generator is already executing.");
17
- while (_) try {
18
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
- if (y = 0, t) op = [op[0] & 2, t.value];
20
- switch (op[0]) {
21
- case 0: case 1: t = op; break;
22
- case 4: _.label++; return { value: op[1], done: false };
23
- case 5: _.label++; y = op[1]; op = [0]; continue;
24
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
- default:
26
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
- if (t[2]) _.ops.pop();
31
- _.trys.pop(); continue;
32
- }
33
- op = body.call(thisArg, _);
34
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
- }
37
- };
38
- Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.useNexoConnect = void 0;
40
- var react_1 = require("react");
41
- var helpers_1 = require("../helpers");
42
- function useNexoConnect(nexo) {
43
- var _this = this;
44
- var _a = (0, react_1.useState)(false), isConnect = _a[0], setIsConnect = _a[1];
45
- (0, react_1.useEffect)(function () {
46
- (0, helpers_1.connect)(nexo).then(function () { return __awaiter(_this, void 0, void 0, function () {
47
- var pathname;
48
- return __generator(this, function (_a) {
49
- switch (_a.label) {
50
- case 0: return [4 /*yield*/, (0, helpers_1.getCurrentPathname)(nexo)];
51
- case 1:
52
- pathname = _a.sent();
53
- if (pathname && pathname !== window.location.pathname) {
54
- window.location.replace(window.location.origin + pathname);
55
- return [2 /*return*/];
56
- }
57
- setIsConnect(true);
58
- (0, helpers_1.iAmReady)(nexo);
59
- return [2 /*return*/];
60
- }
61
- });
62
- }); });
63
- }, [nexo]);
64
- return isConnect;
65
- }
66
- exports.useNexoConnect = useNexoConnect;