@memberstack/dom 1.9.0 → 1.9.1

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<unknown>;
56
+ }) => Promise<HTMLIFrameElement>;
57
57
  };
58
58
  };
59
59
  export default _default;
@@ -16,6 +16,5 @@ 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 handleRedirect: (redirect: any, redirectOverride: any) => any;
20
- export declare const openModal: (props: OpenModalParams & DOMConfig) => Promise<unknown>;
19
+ export declare const openModal: (props: OpenModalParams & DOMConfig) => Promise<HTMLIFrameElement>;
21
20
  export declare const hideModal: () => void;
@@ -1,22 +1,14 @@
1
1
  "use strict";
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;
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);
20
12
  };
21
13
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
14
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -54,12 +46,30 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
54
46
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
55
47
  }
56
48
  };
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
+ };
57
65
  Object.defineProperty(exports, "__esModule", { value: true });
58
- exports.hideModal = exports.openModal = exports.handleRedirect = exports.hideLoader = exports.showLoader = exports.showMessage = exports.load = void 0;
66
+ exports.hideModal = exports.openModal = exports.hideLoader = exports.showLoader = exports.showMessage = exports.load = void 0;
59
67
  var window_1 = require("../../constants/window");
60
68
  var endpoint_1 = require("../../constants/endpoint");
69
+ var cookies_1 = require("../../utils/cookies");
70
+ var persistence_1 = require("../../auth/persistence");
61
71
  var logger_1 = require("../../utils/logger");
62
- var Modal = function () { return Promise.resolve().then(function () { return __importStar(require("../../../../prebuilt-uis/public/build/main-dom.js")); }); };
72
+ var cookies_2 = require("../../utils/cookies");
63
73
  var isBrowser = typeof window !== "undefined";
64
74
  var isInitialized = function () {
65
75
  if (!isBrowser)
@@ -174,35 +184,65 @@ var hideLoader = function (element) {
174
184
  (_a = document.querySelector("[data-ms-loader]")) === null || _a === void 0 ? void 0 : _a.remove();
175
185
  };
176
186
  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;
184
187
  var openModal = function (props) { return __awaiter(void 0, void 0, void 0, function () {
185
- var params, resolveModal, modalPromise, component;
186
- return __generator(this, function (_a) {
187
- switch (_a.label) {
188
+ var appId, page, token, link, div, iframe, iframestyles;
189
+ var _a, _b;
190
+ return __generator(this, function (_c) {
191
+ switch (_c.label) {
188
192
  case 0:
189
193
  (0, logger_1.log)("call openModal()");
190
- params = props.params || {};
191
- modalPromise = new Promise(function (resolve) {
192
- resolveModal = resolve;
193
- });
194
- return [4 /*yield*/, Modal()];
194
+ (0, exports.showLoader)();
195
+ return [4 /*yield*/, getAppId(props.publicKey)];
195
196
  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,
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)();
226
+ });
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);
203
243
  }
204
244
  });
205
- return [2 /*return*/, modalPromise];
245
+ return [2 /*return*/, iframe];
206
246
  }
207
247
  });
208
248
  }); };
@@ -210,7 +250,7 @@ exports.openModal = openModal;
210
250
  var hideModal = function () {
211
251
  var _a;
212
252
  (0, logger_1.log)("call hideModal()");
213
- (_a = document.querySelector("#msOverlay")) === null || _a === void 0 ? void 0 : _a.remove();
253
+ (_a = document.querySelector("[data-ms-iframe]")) === null || _a === void 0 ? void 0 : _a.remove();
214
254
  (0, exports.hideLoader)();
215
255
  };
216
256
  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<unknown>;
71
+ }) => Promise<HTMLIFrameElement>;
72
72
  };
73
73
  };
74
74
  export default _default;
@@ -72,9 +72,6 @@ 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
- var dom = Object.assign(client, methods);
76
- //@ts-ignore
77
- window.$memberstackDom = dom;
78
- return dom;
75
+ return Object.assign(client, methods);
79
76
  }
80
77
  exports.default = { init: function (props) { return init(props); } };
@@ -0,0 +1,12 @@
1
+ export { Main as default };
2
+ declare class Main extends SvelteComponent {
3
+ constructor(options: any);
4
+ }
5
+ /**
6
+ * Base class for Svelte components. Used when dev=false.
7
+ */
8
+ declare class SvelteComponent {
9
+ $destroy(): void;
10
+ $on(type: any, callback: any): () => void;
11
+ $set($$props: any): void;
12
+ }