@memberstack/dom 1.8.0 → 1.9.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/lib/index.d.ts CHANGED
@@ -53,7 +53,7 @@ declare const _default: {
53
53
  }, options?: {
54
54
  onCompleted?: (x: any) => any;
55
55
  onError?: (x: any) => any;
56
- }) => Promise<HTMLIFrameElement>;
56
+ }) => Promise<unknown>;
57
57
  };
58
58
  };
59
59
  export default _default;
@@ -16,5 +16,6 @@ export declare const load: (props: {
16
16
  export declare const showMessage: (msg: any, isError: any) => void;
17
17
  export declare const showLoader: (element?: any) => void;
18
18
  export declare const hideLoader: (element?: any) => void;
19
- export declare const openModal: (props: OpenModalParams & DOMConfig) => Promise<HTMLIFrameElement>;
19
+ export declare const handleRedirect: (redirect: any, redirectOverride: any) => any;
20
+ export declare const openModal: (props: OpenModalParams & DOMConfig) => Promise<unknown>;
20
21
  export declare const hideModal: () => void;
@@ -1,14 +1,22 @@
1
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);
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
12
20
  };
13
21
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
22
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -46,30 +54,12 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
46
54
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
55
  }
48
56
  };
49
- var __read = (this && this.__read) || function (o, n) {
50
- var m = typeof Symbol === "function" && o[Symbol.iterator];
51
- if (!m) return o;
52
- var i = m.call(o), r, ar = [], e;
53
- try {
54
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
55
- }
56
- catch (error) { e = { error: error }; }
57
- finally {
58
- try {
59
- if (r && !r.done && (m = i["return"])) m.call(i);
60
- }
61
- finally { if (e) throw e.error; }
62
- }
63
- return ar;
64
- };
65
57
  Object.defineProperty(exports, "__esModule", { value: true });
66
- exports.hideModal = exports.openModal = exports.hideLoader = exports.showLoader = exports.showMessage = exports.load = void 0;
58
+ exports.hideModal = exports.openModal = exports.handleRedirect = exports.hideLoader = exports.showLoader = exports.showMessage = exports.load = void 0;
67
59
  var window_1 = require("../../constants/window");
68
60
  var endpoint_1 = require("../../constants/endpoint");
69
- var cookies_1 = require("../../utils/cookies");
70
- var persistence_1 = require("../../auth/persistence");
71
61
  var logger_1 = require("../../utils/logger");
72
- var cookies_2 = require("../../utils/cookies");
62
+ var Modal = function () { return Promise.resolve().then(function () { return __importStar(require("../../../../prebuilt-uis/public/build/main-dom.js")); }); };
73
63
  var isBrowser = typeof window !== "undefined";
74
64
  var isInitialized = function () {
75
65
  if (!isBrowser)
@@ -184,65 +174,35 @@ var hideLoader = function (element) {
184
174
  (_a = document.querySelector("[data-ms-loader]")) === null || _a === void 0 ? void 0 : _a.remove();
185
175
  };
186
176
  exports.hideLoader = hideLoader;
177
+ var handleRedirect = function (redirect, redirectOverride) {
178
+ if (redirectOverride)
179
+ return window.location.href = redirectOverride;
180
+ if (redirect && (window.location.pathname !== redirect))
181
+ return window.location.href = redirect;
182
+ };
183
+ exports.handleRedirect = handleRedirect;
187
184
  var openModal = function (props) { return __awaiter(void 0, void 0, void 0, function () {
188
- var appId, page, token, link, div, iframe, iframestyles;
189
- var _a, _b;
190
- return __generator(this, function (_c) {
191
- switch (_c.label) {
185
+ var params, resolveModal, modalPromise, component;
186
+ return __generator(this, function (_a) {
187
+ switch (_a.label) {
192
188
  case 0:
193
189
  (0, logger_1.log)("call openModal()");
194
- (0, exports.showLoader)();
195
- return [4 /*yield*/, getAppId(props.publicKey)];
196
- case 1:
197
- appId = _c.sent();
198
- page = TYPE_PARAMS[props.type];
199
- if (props.type === "PROFILE") {
200
- token = (0, cookies_2.getMemberCookie)();
201
- }
202
- link = createLink(__assign({ pk: props.publicKey, planId: (_a = props.params) === null || _a === void 0 ? void 0 : _a.planId, priceId: (_b = props.params) === null || _b === void 0 ? void 0 : _b.priceId, appId: appId, page: page }, (token ? { token: token } : {})));
203
- div = document.createElement("div");
204
- div.setAttribute("data-ms-iframe", "true");
205
- div.style["position"] = "fixed";
206
- div.style["top"] = "0";
207
- div.style["left"] = "0";
208
- div.style["zIndex"] = "10000000";
209
- iframe = document.createElement("iframe");
210
- iframestyles = {
211
- height: "100vh",
212
- width: "100vw",
213
- position: "absolute",
214
- top: 0,
215
- bottom: 0,
216
- border: "none",
217
- zIndex: "2000000",
218
- };
219
- Object.entries(iframestyles).map(function (_a) {
220
- var _b = __read(_a, 2), attr = _b[0], value = _b[1];
221
- iframe.style[attr] = value;
222
- });
223
- iframe.setAttribute("src", link);
224
- iframe.addEventListener("load", function () {
225
- (0, exports.hideLoader)();
190
+ params = props.params || {};
191
+ modalPromise = new Promise(function (resolve) {
192
+ resolveModal = resolve;
226
193
  });
227
- div.append(iframe);
228
- document.body.appendChild(div);
229
- window.addEventListener("message", function (e) {
230
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
231
- if (e.data.type === "CLOSE") {
232
- return (0, exports.hideModal)();
233
- }
234
- if ((_b = (_a = e.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.member) {
235
- (0, persistence_1.setPersistedMember)((_c = e.data) === null || _c === void 0 ? void 0 : _c.data.member, props.persistence);
236
- }
237
- if (props.useCookie && ((_f = (_e = (_d = e.data) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.tokens) === null || _f === void 0 ? void 0 : _f.accessToken)) {
238
- (0, cookies_1.setMemberCookie)(e.data.data.tokens.accessToken);
239
- }
240
- // added to prevent non memberstack messages being sent from window
241
- if (e.origin === endpoint_1.endpoints.hostedUI && ((_g = e.data) === null || _g === void 0 ? void 0 : _g.data)) {
242
- (_j = (_h = props.options) === null || _h === void 0 ? void 0 : _h.onCompleted) === null || _j === void 0 ? void 0 : _j.call(_h, (_k = e.data) === null || _k === void 0 ? void 0 : _k.data);
194
+ return [4 /*yield*/, Modal()];
195
+ case 1:
196
+ component = (_a.sent()).default;
197
+ new component({
198
+ target: document.body,
199
+ props: {
200
+ display: props.type.toLowerCase(),
201
+ params: params,
202
+ onSuccess: resolveModal,
243
203
  }
244
204
  });
245
- return [2 /*return*/, iframe];
205
+ return [2 /*return*/, modalPromise];
246
206
  }
247
207
  });
248
208
  }); };
@@ -250,7 +210,7 @@ exports.openModal = openModal;
250
210
  var hideModal = function () {
251
211
  var _a;
252
212
  (0, logger_1.log)("call hideModal()");
253
- (_a = document.querySelector("[data-ms-iframe]")) === null || _a === void 0 ? void 0 : _a.remove();
213
+ (_a = document.querySelector("#msOverlay")) === null || _a === void 0 ? void 0 : _a.remove();
254
214
  (0, exports.hideLoader)();
255
215
  };
256
216
  exports.hideModal = hideModal;
@@ -68,7 +68,7 @@ declare const _default: {
68
68
  }, options?: {
69
69
  onCompleted?: (x: any) => any;
70
70
  onError?: (x: any) => any;
71
- }) => Promise<HTMLIFrameElement>;
71
+ }) => Promise<unknown>;
72
72
  };
73
73
  };
74
74
  export default _default;
@@ -72,6 +72,9 @@ function init(props) {
72
72
  }
73
73
  var client = (0, proxy_1.default)((0, client_1.initClient)(__assign(__assign({}, props), { onMemberToken: function (token) { return (0, interceptor_1.handleMemberToken)({ persistence: props.persistence, token: token }); } })), props);
74
74
  var methods = DOMMethods(props);
75
- return Object.assign(client, methods);
75
+ var dom = Object.assign(client, methods);
76
+ //@ts-ignore
77
+ window.$memberstackDom = dom;
78
+ return dom;
76
79
  }
77
80
  exports.default = { init: function (props) { return init(props); } };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memberstack/dom",
3
- "version": "1.8.0",
3
+ "version": "1.9.0",
4
4
  "main": "./lib/index.js",
5
5
  "files": [
6
6
  "lib/**/*"
@@ -8,11 +8,11 @@
8
8
  "author": "Lydia Hallie",
9
9
  "license": "MIT",
10
10
  "dependencies": {
11
- "@memberstack/client": "^1.8.0",
11
+ "@memberstack/client": "^1.9.0",
12
12
  "js-cookie": "^3.0.1"
13
13
  },
14
14
  "scripts": {
15
- "prepublishOnly": "npx tsc",
15
+ "prepublishOnly": "yarn workspace prebuilt-uis build && npx tsc",
16
16
  "watch": "tsc-watch",
17
17
  "watch:dev": "tsc-watch --onSuccess 'yarn replace:vars:local'",
18
18
  "clean": "rm -rf node_modules",