@tiendanube/nexo 0.0.0
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/README.md +1 -0
- package/actions/actions.d.ts +33 -0
- package/actions/actions.js +13 -0
- package/actions/index.d.ts +1 -0
- package/actions/index.js +17 -0
- package/core/nexoClient.d.ts +13 -0
- package/core/nexoClient.js +28 -0
- package/core/transporter.d.ts +21 -0
- package/core/transporter.js +56 -0
- package/core/utils.d.ts +4 -0
- package/core/utils.js +18 -0
- package/helpers/helpers.d.ts +12 -0
- package/helpers/helpers.js +119 -0
- package/helpers/index.d.ts +1 -0
- package/helpers/index.js +17 -0
- package/index.d.ts +8 -0
- package/index.js +7 -0
- package/package.json +26 -0
- package/react/index.d.ts +1 -0
- package/react/index.js +17 -0
- package/react/react.d.ts +2 -0
- package/react/react.js +66 -0
- package/tsconfig.json +23 -0
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# nexo
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export declare const ACTION_READY = "app/ready";
|
|
2
|
+
export declare const ACTION_CONNECTED = "app/connected";
|
|
3
|
+
export declare const ACTION_NAVEGATE_EXIT = "app/navigate/exit";
|
|
4
|
+
export declare const ACTION_NAVIGATE_BACK = "app/navigate/back";
|
|
5
|
+
export declare const ACTION_NAVIGATE_GOTO = "app/navigate/goTo";
|
|
6
|
+
export declare type NavegateGoToRequest = {
|
|
7
|
+
pathname: string;
|
|
8
|
+
};
|
|
9
|
+
export declare const ACTION_NAVIGATE_PATHNAME = "app/navigate/pathname";
|
|
10
|
+
export declare type NavegatePathnameReponse = {
|
|
11
|
+
pathname: string | null;
|
|
12
|
+
};
|
|
13
|
+
export declare const ACTION_NAVIGATE_SYNC = "app/navigate/sync";
|
|
14
|
+
export declare const ACTION_AUTH_SESSION_TOKEN = "app/auth/sessionToken";
|
|
15
|
+
export declare type AuthSessionTokenReponse = {
|
|
16
|
+
token: string;
|
|
17
|
+
};
|
|
18
|
+
export declare const ACTION_STORE_INFO = "app/store/info";
|
|
19
|
+
export declare type StoreInfoReponse = {
|
|
20
|
+
id: string;
|
|
21
|
+
name: string;
|
|
22
|
+
url: string;
|
|
23
|
+
country: string;
|
|
24
|
+
language: string;
|
|
25
|
+
currency: string;
|
|
26
|
+
};
|
|
27
|
+
export declare const ACTION_UTILS_COPY_TO_CLIPBOARD = "app/utils/copyToClipboard";
|
|
28
|
+
export declare type CopyToClipboardRequest = {
|
|
29
|
+
text: string;
|
|
30
|
+
};
|
|
31
|
+
export declare type CopyToClipboardReponse = {
|
|
32
|
+
success: boolean;
|
|
33
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ACTION_UTILS_COPY_TO_CLIPBOARD = exports.ACTION_STORE_INFO = exports.ACTION_AUTH_SESSION_TOKEN = exports.ACTION_NAVIGATE_SYNC = exports.ACTION_NAVIGATE_PATHNAME = exports.ACTION_NAVIGATE_GOTO = exports.ACTION_NAVIGATE_BACK = exports.ACTION_NAVEGATE_EXIT = exports.ACTION_CONNECTED = exports.ACTION_READY = void 0;
|
|
4
|
+
exports.ACTION_READY = "app/ready";
|
|
5
|
+
exports.ACTION_CONNECTED = "app/connected";
|
|
6
|
+
exports.ACTION_NAVEGATE_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
|
+
exports.ACTION_STORE_INFO = "app/store/info";
|
|
13
|
+
exports.ACTION_UTILS_COPY_TO_CLIPBOARD = "app/utils/copyToClipboard";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./actions";
|
package/actions/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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("./actions"), exports);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Dispatch, Suscribe } from "./transporter";
|
|
2
|
+
declare type OnReady = (callback: () => void) => void;
|
|
3
|
+
export interface NexoClient {
|
|
4
|
+
clientId: string;
|
|
5
|
+
dispatch: Dispatch;
|
|
6
|
+
suscribe: Suscribe;
|
|
7
|
+
onReady: OnReady;
|
|
8
|
+
}
|
|
9
|
+
export declare const create: ({ clientId, log, }: {
|
|
10
|
+
clientId: string;
|
|
11
|
+
log?: boolean | undefined;
|
|
12
|
+
}) => NexoClient;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.create = void 0;
|
|
4
|
+
var actions_1 = require("../actions/actions");
|
|
5
|
+
var transporter_1 = require("./transporter");
|
|
6
|
+
var create = function (_a) {
|
|
7
|
+
var clientId = _a.clientId, _b = _a.log, log = _b === void 0 ? false : _b;
|
|
8
|
+
var isReadyMutable = false;
|
|
9
|
+
var _c = (0, transporter_1.registerIframe)(log), dispatch = _c.dispatch, suscribe = _c.suscribe;
|
|
10
|
+
var onReady = function (callback) {
|
|
11
|
+
if (isReadyMutable) {
|
|
12
|
+
throw new Error("onReady should be run only once");
|
|
13
|
+
}
|
|
14
|
+
var readyUnsuscribe = suscribe(actions_1.ACTION_CONNECTED, function () {
|
|
15
|
+
callback();
|
|
16
|
+
readyUnsuscribe();
|
|
17
|
+
isReadyMutable = true;
|
|
18
|
+
});
|
|
19
|
+
dispatch({ type: actions_1.ACTION_CONNECTED });
|
|
20
|
+
};
|
|
21
|
+
return {
|
|
22
|
+
clientId: clientId,
|
|
23
|
+
dispatch: dispatch,
|
|
24
|
+
suscribe: suscribe,
|
|
25
|
+
onReady: onReady,
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
exports.create = create;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare type Dispatch = (event: Message) => void;
|
|
2
|
+
declare type Unsuscribe = () => void;
|
|
3
|
+
export declare type Suscribe = (type: string, callback: any) => Unsuscribe;
|
|
4
|
+
export declare type OnReady = () => void;
|
|
5
|
+
export interface Message<T = unknown> {
|
|
6
|
+
type: string;
|
|
7
|
+
payload?: T;
|
|
8
|
+
}
|
|
9
|
+
export interface MessageToSend extends Message {
|
|
10
|
+
source: {
|
|
11
|
+
host: string;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export declare type Handler = (message: Message) => void;
|
|
15
|
+
export declare const createHandler: (type: string, callback: (payload: unknown) => void) => Handler;
|
|
16
|
+
export declare const suscribeAndUnsuscribeHandlers: (handlers: Handler[], handler: Handler) => () => void;
|
|
17
|
+
export declare const registerIframe: (log?: boolean) => {
|
|
18
|
+
dispatch: Dispatch;
|
|
19
|
+
suscribe: Suscribe;
|
|
20
|
+
};
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.registerIframe = exports.suscribeAndUnsuscribeHandlers = exports.createHandler = void 0;
|
|
4
|
+
var dispatchMessage = function (message) {
|
|
5
|
+
if (window.parent === window) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
if (!("postMessage" in window.parent)) {
|
|
9
|
+
console.error("can not send a event", message);
|
|
10
|
+
}
|
|
11
|
+
logger("dispatched", message.type, message.payload);
|
|
12
|
+
window.parent.postMessage(message, "*");
|
|
13
|
+
};
|
|
14
|
+
var createHandler = function (type, callback) {
|
|
15
|
+
return function (message) {
|
|
16
|
+
if (message.type === type) {
|
|
17
|
+
logger("received", message.type, message.payload);
|
|
18
|
+
callback(message.payload);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
exports.createHandler = createHandler;
|
|
23
|
+
var logger = function (from, type, payload) {
|
|
24
|
+
if (isLogged) {
|
|
25
|
+
var color = from === "dispatched" ? "#f5ec7f" : "#00cc35";
|
|
26
|
+
console.group("%c " + from, "color: " + color);
|
|
27
|
+
console.log("👉 ", type);
|
|
28
|
+
var stringPayload = JSON.stringify(payload);
|
|
29
|
+
stringPayload && console.log("📦 " + stringPayload);
|
|
30
|
+
console.groupEnd();
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var suscribeAndUnsuscribeHandlers = function (handlers, handler) {
|
|
34
|
+
handlers.push(handler);
|
|
35
|
+
return function () {
|
|
36
|
+
handlers.splice(handlers.indexOf(handler), 1);
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
exports.suscribeAndUnsuscribeHandlers = suscribeAndUnsuscribeHandlers;
|
|
40
|
+
var isLogged = false;
|
|
41
|
+
var registerIframe = function (log) {
|
|
42
|
+
if (log === void 0) { log = false; }
|
|
43
|
+
isLogged = log;
|
|
44
|
+
var handlers = [];
|
|
45
|
+
window.addEventListener("message", function (event) {
|
|
46
|
+
handlers.forEach(function (handler) { return handler(event.data); });
|
|
47
|
+
});
|
|
48
|
+
return {
|
|
49
|
+
dispatch: dispatchMessage,
|
|
50
|
+
suscribe: function (type, callback) {
|
|
51
|
+
var handler = (0, exports.createHandler)(type, callback);
|
|
52
|
+
return (0, exports.suscribeAndUnsuscribeHandlers)(handlers, handler);
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
exports.registerIframe = registerIframe;
|
package/core/utils.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { NexoClient } from "./NexoClient";
|
|
2
|
+
import { Message } from "./transporter";
|
|
3
|
+
export declare const message: <TPayload = unknown>(type: string, payload?: TPayload | undefined) => Message;
|
|
4
|
+
export declare const asyncAction: <TResponse, TRequest = undefined>(nexo: NexoClient, action: string, payload?: TRequest | undefined) => Promise<TResponse>;
|
package/core/utils.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.asyncAction = exports.message = void 0;
|
|
4
|
+
var message = function (type, payload) { return ({
|
|
5
|
+
type: type,
|
|
6
|
+
payload: payload,
|
|
7
|
+
}); };
|
|
8
|
+
exports.message = message;
|
|
9
|
+
var asyncAction = function (nexo, action, payload) {
|
|
10
|
+
return new Promise(function (resolve) {
|
|
11
|
+
var unsuscribe = nexo.suscribe(action, function (response) {
|
|
12
|
+
resolve(response);
|
|
13
|
+
unsuscribe();
|
|
14
|
+
});
|
|
15
|
+
nexo.dispatch((0, exports.message)(action, payload));
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
exports.asyncAction = asyncAction;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { StoreInfoReponse } from "../actions/actions";
|
|
2
|
+
import { NexoClient } from "../core/nexoClient";
|
|
3
|
+
export declare const connect: (nexo: NexoClient, ttl?: number) => Promise<void>;
|
|
4
|
+
export declare const iAmReady: (nexo: NexoClient) => void;
|
|
5
|
+
export declare const navegateExit: (nexo: NexoClient) => void;
|
|
6
|
+
export declare const navegateBack: (nexo: NexoClient) => void;
|
|
7
|
+
export declare const getSessionToken: (nexo: NexoClient) => Promise<string>;
|
|
8
|
+
export declare const getCurrentPathname: (nexo: NexoClient) => Promise<string | null>;
|
|
9
|
+
export declare const syncPathname: (nexo: NexoClient, pathname: string) => void;
|
|
10
|
+
export declare const getStoreInfo: (nexo: NexoClient) => Promise<StoreInfoReponse>;
|
|
11
|
+
export declare const goTo: (nexo: NexoClient, pathname: string) => void;
|
|
12
|
+
export declare const copyToClipboard: (nexo: NexoClient, text: string) => Promise<boolean>;
|
|
@@ -0,0 +1,119 @@
|
|
|
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.copyToClipboard = exports.goTo = exports.getStoreInfo = exports.syncPathname = exports.getCurrentPathname = exports.getSessionToken = exports.navegateBack = exports.navegateExit = exports.iAmReady = exports.connect = void 0;
|
|
40
|
+
var actions_1 = require("../actions/actions");
|
|
41
|
+
var utils_1 = require("../core/utils");
|
|
42
|
+
var connect = function (nexo, ttl) {
|
|
43
|
+
if (ttl === void 0) { ttl = 3000; }
|
|
44
|
+
return new Promise(function (resolve, reject) {
|
|
45
|
+
var timeOut = setTimeout(function () {
|
|
46
|
+
reject(new Error("Timeout"));
|
|
47
|
+
}, ttl);
|
|
48
|
+
nexo.onReady(function () {
|
|
49
|
+
resolve();
|
|
50
|
+
clearTimeout(timeOut);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
};
|
|
54
|
+
exports.connect = connect;
|
|
55
|
+
var iAmReady = function (nexo) {
|
|
56
|
+
nexo.dispatch((0, utils_1.message)(actions_1.ACTION_READY));
|
|
57
|
+
};
|
|
58
|
+
exports.iAmReady = iAmReady;
|
|
59
|
+
var navegateExit = function (nexo) {
|
|
60
|
+
nexo.dispatch((0, utils_1.message)(actions_1.ACTION_NAVEGATE_EXIT));
|
|
61
|
+
};
|
|
62
|
+
exports.navegateExit = navegateExit;
|
|
63
|
+
var navegateBack = function (nexo) {
|
|
64
|
+
nexo.dispatch((0, utils_1.message)(actions_1.ACTION_NAVIGATE_BACK));
|
|
65
|
+
};
|
|
66
|
+
exports.navegateBack = navegateBack;
|
|
67
|
+
var getSessionToken = function (nexo) { return __awaiter(void 0, void 0, void 0, function () {
|
|
68
|
+
var token;
|
|
69
|
+
return __generator(this, function (_a) {
|
|
70
|
+
switch (_a.label) {
|
|
71
|
+
case 0: return [4 /*yield*/, (0, utils_1.asyncAction)(nexo, actions_1.ACTION_AUTH_SESSION_TOKEN)];
|
|
72
|
+
case 1:
|
|
73
|
+
token = (_a.sent()).token;
|
|
74
|
+
return [2 /*return*/, token];
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
}); };
|
|
78
|
+
exports.getSessionToken = getSessionToken;
|
|
79
|
+
var getCurrentPathname = function (nexo) { return __awaiter(void 0, void 0, void 0, function () {
|
|
80
|
+
var pathname;
|
|
81
|
+
return __generator(this, function (_a) {
|
|
82
|
+
switch (_a.label) {
|
|
83
|
+
case 0: return [4 /*yield*/, (0, utils_1.asyncAction)(nexo, actions_1.ACTION_NAVIGATE_PATHNAME)];
|
|
84
|
+
case 1:
|
|
85
|
+
pathname = (_a.sent()).pathname;
|
|
86
|
+
return [2 /*return*/, pathname];
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
}); };
|
|
90
|
+
exports.getCurrentPathname = getCurrentPathname;
|
|
91
|
+
var syncPathname = function (nexo, pathname) {
|
|
92
|
+
nexo.dispatch((0, utils_1.message)(actions_1.ACTION_NAVIGATE_SYNC, { pathname: pathname }));
|
|
93
|
+
};
|
|
94
|
+
exports.syncPathname = syncPathname;
|
|
95
|
+
var getStoreInfo = function (nexo) { return __awaiter(void 0, void 0, void 0, function () {
|
|
96
|
+
return __generator(this, function (_a) {
|
|
97
|
+
switch (_a.label) {
|
|
98
|
+
case 0: return [4 /*yield*/, (0, utils_1.asyncAction)(nexo, actions_1.ACTION_STORE_INFO)];
|
|
99
|
+
case 1: return [2 /*return*/, _a.sent()];
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
}); };
|
|
103
|
+
exports.getStoreInfo = getStoreInfo;
|
|
104
|
+
var goTo = function (nexo, pathname) {
|
|
105
|
+
nexo.dispatch((0, utils_1.message)(actions_1.ACTION_NAVIGATE_GOTO, { pathname: pathname }));
|
|
106
|
+
};
|
|
107
|
+
exports.goTo = goTo;
|
|
108
|
+
var copyToClipboard = function (nexo, text) { return __awaiter(void 0, void 0, void 0, function () {
|
|
109
|
+
var success;
|
|
110
|
+
return __generator(this, function (_a) {
|
|
111
|
+
switch (_a.label) {
|
|
112
|
+
case 0: return [4 /*yield*/, (0, utils_1.asyncAction)(nexo, actions_1.ACTION_UTILS_COPY_TO_CLIPBOARD, { text: text })];
|
|
113
|
+
case 1:
|
|
114
|
+
success = (_a.sent()).success;
|
|
115
|
+
return [2 /*return*/, success];
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
}); };
|
|
119
|
+
exports.copyToClipboard = copyToClipboard;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./helpers";
|
package/helpers/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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("./helpers"), exports);
|
package/index.d.ts
ADDED
package/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tiendanube/nexo",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"types": "index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc",
|
|
9
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
10
|
+
},
|
|
11
|
+
"repository": {
|
|
12
|
+
"type": "git",
|
|
13
|
+
"url": "git+https://github.com/TiendaNube/cumulus.git"
|
|
14
|
+
},
|
|
15
|
+
"author": "",
|
|
16
|
+
"license": "ISC",
|
|
17
|
+
"bugs": {
|
|
18
|
+
"url": "https://github.com/TiendaNube/cumulus/issues"
|
|
19
|
+
},
|
|
20
|
+
"homepage": "https://github.com/TiendaNube/cumulus#readme",
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/react": "^17.0.1",
|
|
23
|
+
"typescript": "4.7.4",
|
|
24
|
+
"react": "^17.0.1"
|
|
25
|
+
}
|
|
26
|
+
}
|
package/react/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./react";
|
package/react/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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
ADDED
package/react/react.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
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;
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es5",
|
|
4
|
+
"lib": [
|
|
5
|
+
"dom",
|
|
6
|
+
"dom.iterable",
|
|
7
|
+
"esnext"
|
|
8
|
+
],
|
|
9
|
+
"module": "commonjs",
|
|
10
|
+
"declaration": true,
|
|
11
|
+
"outDir": ".",
|
|
12
|
+
"strict": true,
|
|
13
|
+
"jsx": "react-jsx",
|
|
14
|
+
"esModuleInterop": true,
|
|
15
|
+
},
|
|
16
|
+
"include": [
|
|
17
|
+
"src"
|
|
18
|
+
],
|
|
19
|
+
"exclude": [
|
|
20
|
+
"node_modules",
|
|
21
|
+
"**/__tests__/*"
|
|
22
|
+
]
|
|
23
|
+
}
|