@meshconnect/web-link-sdk 2.0.4 → 2.0.6

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/Link.js CHANGED
@@ -49,12 +49,27 @@ import { addPopup, iframeId, removePopup } from './utils/popup';
49
49
  import { isLinkEventTypeKey } from './utils/event-types';
50
50
  import { sdkSpecs } from './utils/sdk-specs';
51
51
  var currentOptions;
52
- var iframeUrlObject;
52
+ var possibleOrigins = new Set([
53
+ 'https://web.meshconnect.com',
54
+ 'https://web.getfront.com'
55
+ ]);
53
56
  var iframeElement = function () {
54
57
  return document.getElementById(iframeId);
55
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
+ }
56
71
  function eventsListener(event) {
57
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
72
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
58
73
  switch (event.data.type) {
59
74
  case 'brokerageAccountAccessToken': {
60
75
  var payload = {
@@ -106,25 +121,28 @@ function eventsListener(event) {
106
121
  break;
107
122
  }
108
123
  case 'loaded': {
109
- (_k = iframeElement().contentWindow) === null || _k === void 0 ? void 0 : _k.postMessage({
124
+ sendMessageToIframe({
110
125
  type: 'meshSDKSpecs',
111
126
  payload: __assign({}, sdkSpecs)
112
- }, (iframeUrlObject === null || iframeUrlObject === void 0 ? void 0 : iframeUrlObject.origin) || 'https://web.meshconnect.com');
127
+ });
113
128
  if (currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.accessTokens) {
114
- (_l = iframeElement().contentWindow) === null || _l === void 0 ? void 0 : _l.postMessage({ type: 'frontAccessTokens', payload: currentOptions.accessTokens }, (iframeUrlObject === null || iframeUrlObject === void 0 ? void 0 : iframeUrlObject.origin) || 'https://web.meshconnect.com');
129
+ sendMessageToIframe({
130
+ type: 'frontAccessTokens',
131
+ payload: currentOptions.accessTokens
132
+ });
115
133
  }
116
134
  if (currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.transferDestinationTokens) {
117
- (_m = iframeElement().contentWindow) === null || _m === void 0 ? void 0 : _m.postMessage({
135
+ sendMessageToIframe({
118
136
  type: 'frontTransferDestinationTokens',
119
137
  payload: currentOptions.transferDestinationTokens
120
- }, (iframeUrlObject === null || iframeUrlObject === void 0 ? void 0 : iframeUrlObject.origin) || 'https://web.meshconnect.com');
138
+ });
121
139
  }
122
- (_o = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onEvent) === null || _o === void 0 ? void 0 : _o.call(currentOptions, { type: 'pageLoaded' });
140
+ (_k = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onEvent) === null || _k === void 0 ? void 0 : _k.call(currentOptions, { type: 'pageLoaded' });
123
141
  break;
124
142
  }
125
143
  default: {
126
144
  if (isLinkEventTypeKey(event.data.type)) {
127
- (_p = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onEvent) === null || _p === void 0 ? void 0 : _p.call(currentOptions, event.data);
145
+ (_l = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onEvent) === null || _l === void 0 ? void 0 : _l.call(currentOptions, event.data);
128
146
  }
129
147
  break;
130
148
  }
@@ -132,7 +150,7 @@ function eventsListener(event) {
132
150
  }
133
151
  export var createLink = function (options) {
134
152
  var openLink = function (linkToken) { return __awaiter(void 0, void 0, void 0, function () {
135
- var linkUrl;
153
+ var linkUrl, iframeUrlObject;
136
154
  var _a;
137
155
  return __generator(this, function (_b) {
138
156
  if (!linkToken) {
@@ -142,6 +160,9 @@ export var createLink = function (options) {
142
160
  currentOptions = options;
143
161
  linkUrl = window.atob(linkToken);
144
162
  iframeUrlObject = new URL(linkUrl);
163
+ if (iframeUrlObject.origin) {
164
+ possibleOrigins.add(iframeUrlObject.origin);
165
+ }
145
166
  window.removeEventListener('message', eventsListener);
146
167
  addPopup(linkUrl);
147
168
  window.addEventListener('message', eventsListener);
package/cjs/Link.js CHANGED
@@ -52,12 +52,27 @@ var popup_1 = require("./utils/popup");
52
52
  var event_types_1 = require("./utils/event-types");
53
53
  var sdk_specs_1 = require("./utils/sdk-specs");
54
54
  var currentOptions;
55
- var iframeUrlObject;
55
+ var possibleOrigins = new Set([
56
+ 'https://web.meshconnect.com',
57
+ 'https://web.getfront.com'
58
+ ]);
56
59
  var iframeElement = function () {
57
60
  return document.getElementById(popup_1.iframeId);
58
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
+ }
59
74
  function eventsListener(event) {
60
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
75
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
61
76
  switch (event.data.type) {
62
77
  case 'brokerageAccountAccessToken': {
63
78
  var payload = {
@@ -109,25 +124,28 @@ function eventsListener(event) {
109
124
  break;
110
125
  }
111
126
  case 'loaded': {
112
- (_k = iframeElement().contentWindow) === null || _k === void 0 ? void 0 : _k.postMessage({
127
+ sendMessageToIframe({
113
128
  type: 'meshSDKSpecs',
114
129
  payload: __assign({}, sdk_specs_1.sdkSpecs)
115
- }, (iframeUrlObject === null || iframeUrlObject === void 0 ? void 0 : iframeUrlObject.origin) || 'https://web.meshconnect.com');
130
+ });
116
131
  if (currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.accessTokens) {
117
- (_l = iframeElement().contentWindow) === null || _l === void 0 ? void 0 : _l.postMessage({ type: 'frontAccessTokens', payload: currentOptions.accessTokens }, (iframeUrlObject === null || iframeUrlObject === void 0 ? void 0 : iframeUrlObject.origin) || 'https://web.meshconnect.com');
132
+ sendMessageToIframe({
133
+ type: 'frontAccessTokens',
134
+ payload: currentOptions.accessTokens
135
+ });
118
136
  }
119
137
  if (currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.transferDestinationTokens) {
120
- (_m = iframeElement().contentWindow) === null || _m === void 0 ? void 0 : _m.postMessage({
138
+ sendMessageToIframe({
121
139
  type: 'frontTransferDestinationTokens',
122
140
  payload: currentOptions.transferDestinationTokens
123
- }, (iframeUrlObject === null || iframeUrlObject === void 0 ? void 0 : iframeUrlObject.origin) || 'https://web.meshconnect.com');
141
+ });
124
142
  }
125
- (_o = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onEvent) === null || _o === void 0 ? void 0 : _o.call(currentOptions, { type: 'pageLoaded' });
143
+ (_k = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onEvent) === null || _k === void 0 ? void 0 : _k.call(currentOptions, { type: 'pageLoaded' });
126
144
  break;
127
145
  }
128
146
  default: {
129
147
  if ((0, event_types_1.isLinkEventTypeKey)(event.data.type)) {
130
- (_p = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onEvent) === null || _p === void 0 ? void 0 : _p.call(currentOptions, event.data);
148
+ (_l = currentOptions === null || currentOptions === void 0 ? void 0 : currentOptions.onEvent) === null || _l === void 0 ? void 0 : _l.call(currentOptions, event.data);
131
149
  }
132
150
  break;
133
151
  }
@@ -135,7 +153,7 @@ function eventsListener(event) {
135
153
  }
136
154
  var createLink = function (options) {
137
155
  var openLink = function (linkToken) { return __awaiter(void 0, void 0, void 0, function () {
138
- var linkUrl;
156
+ var linkUrl, iframeUrlObject;
139
157
  var _a;
140
158
  return __generator(this, function (_b) {
141
159
  if (!linkToken) {
@@ -145,6 +163,9 @@ var createLink = function (options) {
145
163
  currentOptions = options;
146
164
  linkUrl = window.atob(linkToken);
147
165
  iframeUrlObject = new URL(linkUrl);
166
+ if (iframeUrlObject.origin) {
167
+ possibleOrigins.add(iframeUrlObject.origin);
168
+ }
148
169
  window.removeEventListener('message', eventsListener);
149
170
  (0, popup_1.addPopup)(linkUrl);
150
171
  window.addEventListener('message', eventsListener);
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.sdkVersion = void 0;
4
- exports.sdkVersion = '2.0.4';
4
+ exports.sdkVersion = '2.0.6';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meshconnect/web-link-sdk",
3
- "version": "2.0.4",
3
+ "version": "2.0.6",
4
4
  "description": "A client-side JS library for integrating with Mesh Connect",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/FrontFin/mesh-web-sdk.git",
@@ -20,7 +20,7 @@
20
20
  "jest-environment-jsdom": "^29.7.0"
21
21
  },
22
22
  "dependencies": {
23
- "@meshconnect/node-api": "^2.0.4"
23
+ "@meshconnect/node-api": "^2.0.5"
24
24
  },
25
25
  "jest": {
26
26
  "preset": "ts-jest",
@@ -1 +1 @@
1
- export declare const sdkVersion = "2.0.4";
1
+ export declare const sdkVersion = "2.0.6";
package/utils/version.js CHANGED
@@ -1 +1 @@
1
- export var sdkVersion = '2.0.4';
1
+ export var sdkVersion = '2.0.6';