@meshconnect/web-link-sdk 2.1.0-rc.2 → 2.1.0-rc.3

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.
Files changed (45) hide show
  1. package/Link.d.ts +2 -0
  2. package/Link.js +182 -0
  3. package/cjs/Link.js +186 -0
  4. package/cjs/index.js +21 -0
  5. package/cjs/utils/event-types.js +31 -0
  6. package/cjs/utils/popup.js +39 -0
  7. package/cjs/utils/sdk-specs.js +8 -0
  8. package/cjs/utils/style.js +18 -0
  9. package/cjs/utils/types.js +2 -0
  10. package/cjs/utils/version.js +4 -0
  11. package/index.d.ts +3 -0
  12. package/index.js +3 -0
  13. package/package.json +14 -43
  14. package/utils/event-types.d.ts +152 -0
  15. package/utils/event-types.js +27 -0
  16. package/utils/popup.d.ts +3 -0
  17. package/utils/popup.js +34 -0
  18. package/utils/sdk-specs.d.ts +4 -0
  19. package/utils/sdk-specs.js +5 -0
  20. package/utils/style.d.ts +3 -0
  21. package/utils/style.js +13 -0
  22. package/utils/types.d.ts +103 -0
  23. package/utils/types.js +1 -0
  24. package/utils/version.d.ts +1 -0
  25. package/utils/version.js +1 -0
  26. package/jest.setup.ts +0 -4
  27. package/src/Link.test.ts +0 -395
  28. package/src/Link.ts +0 -350
  29. package/src/index.ts +0 -3
  30. package/src/utils/__snapshots__/popup.test.ts.snap +0 -90
  31. package/src/utils/event-types.test.ts +0 -24
  32. package/src/utils/event-types.ts +0 -226
  33. package/src/utils/popup.test.ts +0 -50
  34. package/src/utils/popup.ts +0 -132
  35. package/src/utils/sdk-specs.test.ts +0 -17
  36. package/src/utils/sdk-specs.ts +0 -6
  37. package/src/utils/style.test.ts +0 -33
  38. package/src/utils/style.ts +0 -15
  39. package/src/utils/types.ts +0 -156
  40. package/src/utils/version.ts +0 -1
  41. package/src/utils/wagmiCoreConnectorsUtils.ts +0 -332
  42. package/src/utils/wallet-browser-event-types.ts +0 -102
  43. package/tools/copy.js +0 -25
  44. package/tools/update-version.js +0 -10
  45. package/tsconfig.json +0 -14
package/Link.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ import { LinkOptions, Link } from './utils/types';
2
+ export declare const createLink: (options: LinkOptions) => Link;
package/Link.js ADDED
@@ -0,0 +1,182 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __generator = (this && this.__generator) || function (thisArg, body) {
22
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
+ function verb(n) { return function (v) { return step([n, v]); }; }
25
+ function step(op) {
26
+ if (f) throw new TypeError("Generator is already executing.");
27
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
28
+ 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;
29
+ if (y = 0, t) op = [op[0] & 2, t.value];
30
+ switch (op[0]) {
31
+ case 0: case 1: t = op; break;
32
+ case 4: _.label++; return { value: op[1], done: false };
33
+ case 5: _.label++; y = op[1]; op = [0]; continue;
34
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
+ default:
36
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
+ if (t[2]) _.ops.pop();
41
+ _.trys.pop(); continue;
42
+ }
43
+ op = body.call(thisArg, _);
44
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
+ }
47
+ };
48
+ import { addPopup, iframeId, removePopup } from './utils/popup';
49
+ import { isLinkEventTypeKey } from './utils/event-types';
50
+ import { sdkSpecs } from './utils/sdk-specs';
51
+ var currentOptions;
52
+ var possibleOrigins = new Set([
53
+ 'https://web.meshconnect.com',
54
+ 'https://web.getfront.com'
55
+ ]);
56
+ var iframeElement = function () {
57
+ return document.getElementById(iframeId);
58
+ };
59
+ function sendMessageToIframe(message) {
60
+ possibleOrigins.forEach(function (origin) {
61
+ var _a;
62
+ try {
63
+ (_a = iframeElement().contentWindow) === null || _a === void 0 ? void 0 : _a.postMessage(message, origin);
64
+ }
65
+ catch (e) {
66
+ console.error('Mesh SDK: Failed to deliver message to the iframe');
67
+ console.error(e);
68
+ }
69
+ });
70
+ }
71
+ function eventsListener(event) {
72
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
73
+ switch (event.data.type) {
74
+ case 'brokerageAccountAccessToken': {
75
+ var payload = {
76
+ accessToken: event.data.payload
77
+ };
78
+ (_a = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onEvent) === null || _a === void 0 ? void 0 : _a.call(currentOptions, {
79
+ type: 'integrationConnected',
80
+ payload: payload
81
+ });
82
+ (_b = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onIntegrationConnected) === null || _b === void 0 ? void 0 : _b.call(currentOptions, payload);
83
+ break;
84
+ }
85
+ case 'delayedAuthentication': {
86
+ var payload = {
87
+ delayedAuth: event.data.payload
88
+ };
89
+ (_c = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onEvent) === null || _c === void 0 ? void 0 : _c.call(currentOptions, {
90
+ type: 'integrationConnected',
91
+ payload: payload
92
+ });
93
+ (_d = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onIntegrationConnected) === null || _d === void 0 ? void 0 : _d.call(currentOptions, payload);
94
+ break;
95
+ }
96
+ case 'transferFinished': {
97
+ var payload = event.data.payload;
98
+ (_e = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onEvent) === null || _e === void 0 ? void 0 : _e.call(currentOptions, {
99
+ type: 'transferCompleted',
100
+ payload: payload
101
+ });
102
+ (_f = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onTransferFinished) === null || _f === void 0 ? void 0 : _f.call(currentOptions, payload);
103
+ break;
104
+ }
105
+ case 'close':
106
+ case 'done': {
107
+ var payload = (_g = event.data) === null || _g === void 0 ? void 0 : _g.payload;
108
+ (_h = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onExit) === null || _h === void 0 ? void 0 : _h.call(currentOptions, payload === null || payload === void 0 ? void 0 : payload.errorMessage, payload);
109
+ removePopup();
110
+ break;
111
+ }
112
+ case 'oauthLinkOpen': {
113
+ if (event.data.link) {
114
+ var w = 700;
115
+ var h = 800;
116
+ var left = screen.width / 2 - w / 2;
117
+ var top_1 = screen.height / 2 - h / 2;
118
+ (_j = window
119
+ .open(event.data.link, '_blank', "popup,noopener,noreferrer,resizable,scrollbars,width=".concat(w, ",height=").concat(h, ",top=").concat(top_1, ",left=").concat(left))) === null || _j === void 0 ? void 0 : _j.focus();
120
+ }
121
+ break;
122
+ }
123
+ case 'loaded': {
124
+ sendMessageToIframe({
125
+ type: 'meshSDKSpecs',
126
+ payload: __assign({}, sdkSpecs)
127
+ });
128
+ if (currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.accessTokens) {
129
+ sendMessageToIframe({
130
+ type: 'frontAccessTokens',
131
+ payload: currentOptions.accessTokens
132
+ });
133
+ }
134
+ if (currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.transferDestinationTokens) {
135
+ sendMessageToIframe({
136
+ type: 'frontTransferDestinationTokens',
137
+ payload: currentOptions.transferDestinationTokens
138
+ });
139
+ }
140
+ (_k = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onEvent) === null || _k === void 0 ? void 0 : _k.call(currentOptions, { type: 'pageLoaded' });
141
+ break;
142
+ }
143
+ default: {
144
+ if (isLinkEventTypeKey(event.data.type)) {
145
+ (_l = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onEvent) === null || _l === void 0 ? void 0 : _l.call(currentOptions, event.data);
146
+ }
147
+ break;
148
+ }
149
+ }
150
+ }
151
+ export var createLink = function (options) {
152
+ var openLink = function (linkToken) { return __awaiter(void 0, void 0, void 0, function () {
153
+ var linkUrl, iframeUrlObject;
154
+ var _a;
155
+ return __generator(this, function (_b) {
156
+ if (!linkToken) {
157
+ (_a = options === null || options === void 0 ? void 0 : options.onExit) === null || _a === void 0 ? void 0 : _a.call(options, 'Invalid link token!');
158
+ return [2 /*return*/];
159
+ }
160
+ currentOptions = options;
161
+ linkUrl = window.atob(linkToken);
162
+ iframeUrlObject = new URL(linkUrl);
163
+ if (iframeUrlObject.origin) {
164
+ possibleOrigins.add(iframeUrlObject.origin);
165
+ }
166
+ window.removeEventListener('message', eventsListener);
167
+ addPopup(linkUrl);
168
+ window.addEventListener('message', eventsListener);
169
+ return [2 /*return*/];
170
+ });
171
+ }); };
172
+ var closeLink = function () {
173
+ var _a;
174
+ removePopup();
175
+ window.removeEventListener('message', eventsListener);
176
+ (_a = options.onExit) === null || _a === void 0 ? void 0 : _a.call(options);
177
+ };
178
+ return {
179
+ openLink: openLink,
180
+ closeLink: closeLink
181
+ };
182
+ };
package/cjs/Link.js ADDED
@@ -0,0 +1,186 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ 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;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.createLink = void 0;
51
+ var popup_1 = require("./utils/popup");
52
+ var event_types_1 = require("./utils/event-types");
53
+ var sdk_specs_1 = require("./utils/sdk-specs");
54
+ var currentOptions;
55
+ var possibleOrigins = new Set([
56
+ 'https://web.meshconnect.com',
57
+ 'https://web.getfront.com'
58
+ ]);
59
+ var iframeElement = function () {
60
+ return document.getElementById(popup_1.iframeId);
61
+ };
62
+ function sendMessageToIframe(message) {
63
+ possibleOrigins.forEach(function (origin) {
64
+ var _a;
65
+ try {
66
+ (_a = iframeElement().contentWindow) === null || _a === void 0 ? void 0 : _a.postMessage(message, origin);
67
+ }
68
+ catch (e) {
69
+ console.error('Mesh SDK: Failed to deliver message to the iframe');
70
+ console.error(e);
71
+ }
72
+ });
73
+ }
74
+ function eventsListener(event) {
75
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
76
+ switch (event.data.type) {
77
+ case 'brokerageAccountAccessToken': {
78
+ var payload = {
79
+ accessToken: event.data.payload
80
+ };
81
+ (_a = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onEvent) === null || _a === void 0 ? void 0 : _a.call(currentOptions, {
82
+ type: 'integrationConnected',
83
+ payload: payload
84
+ });
85
+ (_b = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onIntegrationConnected) === null || _b === void 0 ? void 0 : _b.call(currentOptions, payload);
86
+ break;
87
+ }
88
+ case 'delayedAuthentication': {
89
+ var payload = {
90
+ delayedAuth: event.data.payload
91
+ };
92
+ (_c = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onEvent) === null || _c === void 0 ? void 0 : _c.call(currentOptions, {
93
+ type: 'integrationConnected',
94
+ payload: payload
95
+ });
96
+ (_d = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onIntegrationConnected) === null || _d === void 0 ? void 0 : _d.call(currentOptions, payload);
97
+ break;
98
+ }
99
+ case 'transferFinished': {
100
+ var payload = event.data.payload;
101
+ (_e = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onEvent) === null || _e === void 0 ? void 0 : _e.call(currentOptions, {
102
+ type: 'transferCompleted',
103
+ payload: payload
104
+ });
105
+ (_f = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onTransferFinished) === null || _f === void 0 ? void 0 : _f.call(currentOptions, payload);
106
+ break;
107
+ }
108
+ case 'close':
109
+ case 'done': {
110
+ var payload = (_g = event.data) === null || _g === void 0 ? void 0 : _g.payload;
111
+ (_h = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onExit) === null || _h === void 0 ? void 0 : _h.call(currentOptions, payload === null || payload === void 0 ? void 0 : payload.errorMessage, payload);
112
+ (0, popup_1.removePopup)();
113
+ break;
114
+ }
115
+ case 'oauthLinkOpen': {
116
+ if (event.data.link) {
117
+ var w = 700;
118
+ var h = 800;
119
+ var left = screen.width / 2 - w / 2;
120
+ var top_1 = screen.height / 2 - h / 2;
121
+ (_j = window
122
+ .open(event.data.link, '_blank', "popup,noopener,noreferrer,resizable,scrollbars,width=".concat(w, ",height=").concat(h, ",top=").concat(top_1, ",left=").concat(left))) === null || _j === void 0 ? void 0 : _j.focus();
123
+ }
124
+ break;
125
+ }
126
+ case 'loaded': {
127
+ sendMessageToIframe({
128
+ type: 'meshSDKSpecs',
129
+ payload: __assign({}, sdk_specs_1.sdkSpecs)
130
+ });
131
+ if (currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.accessTokens) {
132
+ sendMessageToIframe({
133
+ type: 'frontAccessTokens',
134
+ payload: currentOptions.accessTokens
135
+ });
136
+ }
137
+ if (currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.transferDestinationTokens) {
138
+ sendMessageToIframe({
139
+ type: 'frontTransferDestinationTokens',
140
+ payload: currentOptions.transferDestinationTokens
141
+ });
142
+ }
143
+ (_k = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onEvent) === null || _k === void 0 ? void 0 : _k.call(currentOptions, { type: 'pageLoaded' });
144
+ break;
145
+ }
146
+ default: {
147
+ if ((0, event_types_1.isLinkEventTypeKey)(event.data.type)) {
148
+ (_l = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onEvent) === null || _l === void 0 ? void 0 : _l.call(currentOptions, event.data);
149
+ }
150
+ break;
151
+ }
152
+ }
153
+ }
154
+ var createLink = function (options) {
155
+ var openLink = function (linkToken) { return __awaiter(void 0, void 0, void 0, function () {
156
+ var linkUrl, iframeUrlObject;
157
+ var _a;
158
+ return __generator(this, function (_b) {
159
+ if (!linkToken) {
160
+ (_a = options === null || options === void 0 ? void 0 : options.onExit) === null || _a === void 0 ? void 0 : _a.call(options, 'Invalid link token!');
161
+ return [2 /*return*/];
162
+ }
163
+ currentOptions = options;
164
+ linkUrl = window.atob(linkToken);
165
+ iframeUrlObject = new URL(linkUrl);
166
+ if (iframeUrlObject.origin) {
167
+ possibleOrigins.add(iframeUrlObject.origin);
168
+ }
169
+ window.removeEventListener('message', eventsListener);
170
+ (0, popup_1.addPopup)(linkUrl);
171
+ window.addEventListener('message', eventsListener);
172
+ return [2 /*return*/];
173
+ });
174
+ }); };
175
+ var closeLink = function () {
176
+ var _a;
177
+ (0, popup_1.removePopup)();
178
+ window.removeEventListener('message', eventsListener);
179
+ (_a = options.onExit) === null || _a === void 0 ? void 0 : _a.call(options);
180
+ };
181
+ return {
182
+ openLink: openLink,
183
+ closeLink: closeLink
184
+ };
185
+ };
186
+ exports.createLink = createLink;
package/cjs/index.js ADDED
@@ -0,0 +1,21 @@
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
+ exports.createLink = void 0;
18
+ __exportStar(require("./utils/types"), exports);
19
+ __exportStar(require("./utils/event-types"), exports);
20
+ var Link_1 = require("./Link");
21
+ Object.defineProperty(exports, "createLink", { enumerable: true, get: function () { return Link_1.createLink; } });
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isLinkEventTypeKey = void 0;
4
+ var LINK_EVENT_TYPE_KEYS = [
5
+ 'integrationConnected',
6
+ 'integrationConnectionError',
7
+ 'integrationMfaRequired',
8
+ 'integrationMfaEntered',
9
+ 'integrationOAuthStarted',
10
+ 'integrationAccountSelectionRequired',
11
+ 'transferCompleted',
12
+ 'integrationSelected',
13
+ 'credentialsEntered',
14
+ 'transferStarted',
15
+ 'transferPreviewed',
16
+ 'transferPreviewError',
17
+ 'transferExecutionError',
18
+ 'pageLoaded',
19
+ 'transferAssetSelected',
20
+ 'transferNetworkSelected',
21
+ 'transferAmountEntered',
22
+ 'transferMfaRequired',
23
+ 'transferMfaEntered',
24
+ 'transferKycRequired',
25
+ 'done',
26
+ 'close'
27
+ ];
28
+ function isLinkEventTypeKey(key) {
29
+ return LINK_EVENT_TYPE_KEYS.includes(key);
30
+ }
31
+ exports.isLinkEventTypeKey = isLinkEventTypeKey;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addPopup = exports.removePopup = exports.iframeId = void 0;
4
+ var style_1 = require("./style");
5
+ var popupId = 'mesh-link-popup';
6
+ var backdropId = 'mesh-link-popup__backdrop';
7
+ var popupContentId = 'mesh-link-popup__popup-content';
8
+ var stylesId = 'mesh-link-popup__styles';
9
+ exports.iframeId = 'mesh-link-popup__iframe';
10
+ var getPopupHtml = function (link) { return "\n<div id=\"".concat(popupId, "\">\n <div id=\"").concat(backdropId, "\"></div>\n <div id=\"").concat(popupContentId, "\">\n <iframe id=\"").concat(exports.iframeId, "\" src=\"").concat(link, "\" allow=\"clipboard-read *; clipboard-write *\" />\n </div>\n</div>\n"); };
11
+ var getStyles = function (style) { return "\n<style id=\"".concat(stylesId, "\">\n body {\n position: fixed;\n left: 0;\n top: 0;\n bottom: 0;\n right: 0;\n overflow: hidden;\n }\n\n #").concat(popupId, " {\n all: unset;\n position: fixed;\n left: 0;\n top: 0;\n bottom: 0;\n right: 0;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n z-index: 10000;\n }\n\n #").concat(backdropId, " {\n position: absolute;\n left: 0;\n top: 0;\n bottom: 0;\n right: 0;\n z-index: 10000;\n background: black;\n opacity: ").concat((0, style_1.getNumber)(0.6, style === null || style === void 0 ? void 0 : style.io), ";\n }\n\n #").concat(popupContentId, " {\n position: absolute;\n height: 80%;\n max-height: 710px;\n min-height: 685px;\n margin: auto;\n z-index: 10001;\n width: 30%;\n max-width: 430px;\n min-width: 380px;\n display: flex;\n flex-direction: column;\n border-radius: ").concat((0, style_1.getNumber)(24, style === null || style === void 0 ? void 0 : style.ir), "px;\n background: white;\n flex-grow: 1;\n }\n\n #").concat(popupContentId, " iframe {\n border: none;\n width: 100%;\n flex-grow: 1;\n border-radius: ").concat((0, style_1.getNumber)(24, style === null || style === void 0 ? void 0 : style.ir), "px;\n }\n\n @media only screen and (max-width: 768px) {\n #").concat(popupContentId, " {\n height: 100vh;\n width: 100vw;\n max-width: 100%;\n min-width: 100%;\n max-height: 100%;\n min-height: 100%;\n border-radius: 0px;\n }\n\n #").concat(popupContentId, " iframe {\n border-radius: 0px;\n }\n }\n\n @media only screen and (max-height: 710px) {\n #").concat(popupContentId, " {\n max-height: 100%;\n min-height: 100%;\n }\n }\n</style>\n"); };
12
+ function removePopup() {
13
+ var _a, _b;
14
+ var existingPopup = window.document.getElementById(popupId);
15
+ (_a = existingPopup === null || existingPopup === void 0 ? void 0 : existingPopup.parentElement) === null || _a === void 0 ? void 0 : _a.removeChild(existingPopup);
16
+ var existingStyles = window.document.getElementById(stylesId);
17
+ (_b = existingStyles === null || existingStyles === void 0 ? void 0 : existingStyles.parentElement) === null || _b === void 0 ? void 0 : _b.removeChild(existingStyles);
18
+ }
19
+ exports.removePopup = removePopup;
20
+ function addPopup(iframeLink) {
21
+ var style = (0, style_1.getLinkStyle)(iframeLink);
22
+ removePopup();
23
+ var popup = getPopupHtml(iframeLink);
24
+ var stylesElement = htmlToElement(getStyles(style));
25
+ if (stylesElement) {
26
+ window.document.head.appendChild(stylesElement);
27
+ }
28
+ var popupElement = htmlToElement(popup);
29
+ if (popupElement) {
30
+ window.document.body.appendChild(popupElement);
31
+ }
32
+ }
33
+ exports.addPopup = addPopup;
34
+ function htmlToElement(html) {
35
+ var template = document.createElement('template');
36
+ html = html.trim();
37
+ template.innerHTML = html;
38
+ return template.content.firstChild;
39
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sdkSpecs = void 0;
4
+ var version_1 = require("./version");
5
+ exports.sdkSpecs = {
6
+ platform: 'web',
7
+ version: version_1.sdkVersion
8
+ };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getNumber = exports.getLinkStyle = void 0;
4
+ function getLinkStyle(url) {
5
+ try {
6
+ var params = new URLSearchParams(new URL(url).search);
7
+ var style = params.get('link_style');
8
+ return style && JSON.parse(window.atob(style));
9
+ }
10
+ catch (e) {
11
+ return undefined;
12
+ }
13
+ }
14
+ exports.getLinkStyle = getLinkStyle;
15
+ function getNumber(def, value) {
16
+ return value !== undefined ? value : def;
17
+ }
18
+ exports.getNumber = getNumber;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sdkVersion = void 0;
4
+ exports.sdkVersion = '2.1.0-rc.3';
package/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './utils/types';
2
+ export * from './utils/event-types';
3
+ export { createLink } from './Link';
package/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from './utils/types';
2
+ export * from './utils/event-types';
3
+ export { createLink } from './Link';
package/package.json CHANGED
@@ -1,72 +1,43 @@
1
1
  {
2
2
  "name": "@meshconnect/web-link-sdk",
3
- "version": "2.1.0-rc.2",
3
+ "version": "2.1.0-rc.3",
4
4
  "description": "A client-side JS library for integrating with Mesh Connect",
5
- "main": "./src/index.ts",
6
- "module": "./src/index.ts",
7
- "types": "./src/index.ts",
8
- "type": "module",
9
5
  "license": "MIT",
10
6
  "repository": "https://github.com/FrontFin/mesh-web-sdk.git",
11
7
  "homepage": "https://github.com/FrontFin/mesh-web-sdk",
12
8
  "devDependencies": {
13
- "@types/jest": "^29.5.12",
9
+ "@typescript-eslint/eslint-plugin": "^4.21.0",
10
+ "@typescript-eslint/parser": "^4.21.0",
14
11
  "eslint": "^7.23.0",
15
12
  "eslint-config-prettier": "^8.1.0",
16
13
  "eslint-plugin-import": "^2.22.1",
17
14
  "eslint-plugin-prettier": "^3.4.0",
18
- "babel-jest": "^29.5.0",
19
- "@babel/preset-env": "^7.20.0",
20
- "@babel/preset-typescript": "^7.20.0",
21
- "jest": "^29.7.0",
22
- "jest-environment-jsdom": "^29.7.0",
23
15
  "prettier": "^2.2.1",
16
+ "typescript": "^4.6.4",
24
17
  "ts-jest": "^29.1.2",
25
- "util": "^0.12.4"
18
+ "jest": "^29.7.0",
19
+ "@types/jest": "^29.5.12",
20
+ "jest-environment-jsdom": "^29.7.0"
26
21
  },
27
22
  "dependencies": {
28
- "@meshconnect/node-api": "^2.0.5",
29
- "@wagmi/core": "^2.10.5",
30
- "viem": "^2.x",
31
- "@wagmi/connectors": "^5.0.7"
32
- },
33
- "scripts": {
34
- "build": "yarn updateVersion && rimraf dist && yarn build:esm && yarn build:cjs && yarn copy",
35
- "build:esm": "tsc --outDir dist",
36
- "build:cjs": "tsc --module commonjs --outDir dist/cjs",
37
- "typecheck": "tsc --noEmit --skipLibCheck",
38
- "lint": "eslint **/*.ts",
39
- "copy": "node ./tools/copy",
40
- "updateVersion": "node ./tools/update-version",
41
- "publish:npm": "yarn build && cd dist && yarn publish --access public --tag rc",
42
- "test": "jest",
43
- "test:cov": "jest --ci --coverage"
23
+ "@meshconnect/node-api": "^2.0.5"
44
24
  },
45
25
  "jest": {
46
26
  "preset": "ts-jest",
47
27
  "testEnvironment": "jsdom",
48
- "setupFiles": ["./jest.setup.ts"],
49
28
  "testPathIgnorePatterns": [
50
29
  "/node_modules/",
51
30
  "/dist/"
52
31
  ],
53
32
  "coverageDirectory": "./coverage",
54
33
  "transform": {
55
- "^.+\\.[tj]sx?$": [
56
- "babel-jest",
57
- {
58
- "presets": [
59
- "@babel/preset-env",
60
- "@babel/preset-typescript"
61
- ]
62
- }
63
- ]
34
+ "\\.[jt]sx?$": "ts-jest"
64
35
  },
65
- "transformIgnorePatterns": [
66
- "/node_modules/(?!(@wagmi/core|@wagmi/connectors)).+\\.js$"
67
- ],
68
36
  "testEnvironmentOptions": {
69
37
  "url": "http://localhost/"
70
38
  }
71
- }
72
- }
39
+ },
40
+ "main": "./cjs/index.js",
41
+ "module": "./index.js",
42
+ "types": "./index.d.ts"
43
+ }