@memberstack/dom 1.9.1 → 1.9.4
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/auth/index.d.ts +7 -0
- package/lib/auth/index.js +67 -0
- package/lib/constants/endpoints.d.ts +3 -0
- package/lib/constants/{endpoint.js → endpoints.js} +1 -2
- package/lib/index.d.ts +758 -48
- package/lib/methods/dom/index.d.ts +0 -2
- package/lib/methods/dom/index.js +0 -12
- package/lib/{uis → methods/dom}/main-dom.d.ts +0 -0
- package/lib/{uis → methods/dom}/main-dom.js +170 -300
- package/lib/methods/dom/methods.d.ts +3 -14
- package/lib/methods/dom/methods.js +35 -175
- package/lib/methods/index.d.ts +759 -61
- package/lib/methods/index.js +20 -69
- package/lib/methods/requests/index.d.ts +55 -0
- package/lib/methods/{client → requests}/index.js +228 -63
- package/lib/methods/{client/request.d.ts → requests/requests.d.ts} +11 -4
- package/lib/methods/{client/request.js → requests/requests.js} +31 -24
- package/lib/types/index.js +1 -1
- package/lib/types/params.d.ts +23 -0
- package/lib/types/payloads.d.ts +5 -0
- package/lib/types/utils/payloads.d.ts +19 -0
- package/lib/utils/cookies.d.ts +1 -1
- package/lib/utils/cookies.js +5 -7
- package/package.json +10 -4
- package/lib/auth/persistence/index.d.ts +0 -1
- package/lib/auth/persistence/index.js +0 -13
- package/lib/auth/persistence/local.d.ts +0 -5
- package/lib/auth/persistence/local.js +0 -20
- package/lib/auth/persistence/methods.d.ts +0 -13
- package/lib/auth/persistence/methods.js +0 -87
- package/lib/auth/persistence/session.d.ts +0 -5
- package/lib/auth/persistence/session.js +0 -20
- package/lib/constants/cookies.d.ts +0 -3
- package/lib/constants/cookies.js +0 -7
- package/lib/constants/endpoint.d.ts +0 -4
- package/lib/constants/request.d.ts +0 -10
- package/lib/constants/request.js +0 -15
- package/lib/constants/storage.d.ts +0 -1
- package/lib/constants/storage.js +0 -4
- package/lib/constants/window.d.ts +0 -4
- package/lib/constants/window.js +0 -7
- package/lib/methods/client/index.d.ts +0 -85
- package/lib/methods/client.d.ts +0 -43
- package/lib/methods/client.js +0 -35
- package/lib/methods/dom/script.d.ts +0 -3
- package/lib/methods/dom/script.js +0 -50
- package/lib/utils/interceptor.d.ts +0 -4
- package/lib/utils/interceptor.js +0 -18
- package/lib/utils/logger.d.ts +0 -3
- package/lib/utils/logger.js +0 -51
- package/lib/utils/proxy.d.ts +0 -2
- package/lib/utils/proxy.js +0 -105
|
@@ -1,20 +1,9 @@
|
|
|
1
|
-
import type { DOMConfig } from "..";
|
|
2
1
|
export declare type OpenModalParams = {
|
|
3
|
-
type: "LOGIN" | "SIGNUP" | "FORGOT_PASSWORD" | "
|
|
4
|
-
params?: {
|
|
5
|
-
planId?: string;
|
|
6
|
-
priceId?: string;
|
|
7
|
-
};
|
|
8
|
-
options?: {
|
|
9
|
-
onCompleted?: (x: any) => any;
|
|
10
|
-
onError?: (x: any) => any;
|
|
11
|
-
};
|
|
2
|
+
type: "LOGIN" | "SIGNUP" | "FORGOT_PASSWORD" | "RESET_PASSWORD";
|
|
12
3
|
};
|
|
13
|
-
export declare const load: (props: {
|
|
14
|
-
publicKey: string;
|
|
15
|
-
}) => void;
|
|
16
4
|
export declare const showMessage: (msg: any, isError: any) => void;
|
|
17
5
|
export declare const showLoader: (element?: any) => void;
|
|
18
6
|
export declare const hideLoader: (element?: any) => void;
|
|
19
|
-
export declare const
|
|
7
|
+
export declare const handleRedirect: (redirect: any, redirectOverride: any) => any;
|
|
8
|
+
export declare const openModal: (type: OpenModalParams["type"], params?: {}) => Promise<unknown>;
|
|
20
9
|
export declare const hideModal: () => void;
|
|
@@ -1,15 +1,4 @@
|
|
|
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);
|
|
12
|
-
};
|
|
13
2
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
3
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
4
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -46,101 +35,13 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
46
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
36
|
}
|
|
48
37
|
};
|
|
49
|
-
var
|
|
50
|
-
|
|
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;
|
|
38
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
39
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
64
40
|
};
|
|
65
41
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
66
|
-
exports.hideModal = exports.openModal = exports.
|
|
67
|
-
var
|
|
68
|
-
|
|
69
|
-
var cookies_1 = require("../../utils/cookies");
|
|
70
|
-
var persistence_1 = require("../../auth/persistence");
|
|
71
|
-
var logger_1 = require("../../utils/logger");
|
|
72
|
-
var cookies_2 = require("../../utils/cookies");
|
|
73
|
-
var isBrowser = typeof window !== "undefined";
|
|
74
|
-
var isInitialized = function () {
|
|
75
|
-
if (!isBrowser)
|
|
76
|
-
return;
|
|
77
|
-
if (!(window === null || window === void 0 ? void 0 : window[window_1.Window.MSDOM])) {
|
|
78
|
-
console.warn("Memberstack has not been initialized yet.");
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
return true;
|
|
82
|
-
};
|
|
83
|
-
var load = function (props) {
|
|
84
|
-
var _a;
|
|
85
|
-
if (isInitialized()) {
|
|
86
|
-
(_a = window[window_1.Window.MSDOM]) === null || _a === void 0 ? void 0 : _a.load({ publicKey: props.publicKey });
|
|
87
|
-
}
|
|
88
|
-
};
|
|
89
|
-
exports.load = load;
|
|
90
|
-
var getAppId = function (publicKey) { return __awaiter(void 0, void 0, void 0, function () {
|
|
91
|
-
var res, json, e_1;
|
|
92
|
-
var _a, _b;
|
|
93
|
-
return __generator(this, function (_c) {
|
|
94
|
-
switch (_c.label) {
|
|
95
|
-
case 0:
|
|
96
|
-
if (typeof window === "undefined")
|
|
97
|
-
return [2 /*return*/, null];
|
|
98
|
-
if (window === null || window === void 0 ? void 0 : window["__MS-APPID"]) {
|
|
99
|
-
return [2 /*return*/, window["__MS-APPID"]];
|
|
100
|
-
}
|
|
101
|
-
if (!publicKey)
|
|
102
|
-
return [2 /*return*/, null];
|
|
103
|
-
_c.label = 1;
|
|
104
|
-
case 1:
|
|
105
|
-
_c.trys.push([1, 4, , 5]);
|
|
106
|
-
return [4 /*yield*/, fetch(endpoint_1.endpoints.clientEndpoint + "/app", {
|
|
107
|
-
headers: {
|
|
108
|
-
"x-api-key": publicKey,
|
|
109
|
-
},
|
|
110
|
-
})];
|
|
111
|
-
case 2:
|
|
112
|
-
res = _c.sent();
|
|
113
|
-
return [4 /*yield*/, res.json()];
|
|
114
|
-
case 3:
|
|
115
|
-
json = _c.sent();
|
|
116
|
-
if (json.code)
|
|
117
|
-
throw json;
|
|
118
|
-
window["__MS-APPID"] = (_a = json.data) === null || _a === void 0 ? void 0 : _a.id;
|
|
119
|
-
return [2 /*return*/, (_b = json.data) === null || _b === void 0 ? void 0 : _b.id];
|
|
120
|
-
case 4:
|
|
121
|
-
e_1 = _c.sent();
|
|
122
|
-
throw e_1;
|
|
123
|
-
case 5: return [2 /*return*/];
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
}); };
|
|
127
|
-
var TYPE_PARAMS = {
|
|
128
|
-
LOGIN: "login",
|
|
129
|
-
SIGNUP: "signup",
|
|
130
|
-
FORGOT_PASSWORD: "sendResetEmail",
|
|
131
|
-
PROFILE: "profile",
|
|
132
|
-
};
|
|
133
|
-
var createLink = function (query) {
|
|
134
|
-
var _a = query.planId, planId = _a === void 0 ? "" : _a, _b = query.appId, appId = _b === void 0 ? "" : _b, _c = query.page, page = _c === void 0 ? "" : _c, _d = query.priceId, priceId = _d === void 0 ? "" : _d, _e = query.pk, pk = _e === void 0 ? "" : _e, _f = query.hideNav, hideNav = _f === void 0 ? "" : _f, _g = query.token, token = _g === void 0 ? "" : _g;
|
|
135
|
-
var queryParams = Object.keys({ priceId: priceId, pk: pk, hideNav: hideNav, token: token })
|
|
136
|
-
.map(function (key) { return query[key] && encodeURIComponent(key) + "=" + encodeURIComponent(query[key]); })
|
|
137
|
-
.filter(function (x) { return x; })
|
|
138
|
-
.join("&");
|
|
139
|
-
console.log("CREATE LINK", token);
|
|
140
|
-
var baseUrl = endpoint_1.endpoints.hostedUI + "/" + (appId || "") + (page ? "/" + page : "") + (planId ? (page === "signup" ? "/" + planId : "?planId=" + planId) : "");
|
|
141
|
-
return "" + baseUrl + (baseUrl.includes("?planId") ? "&" : "?") + queryParams;
|
|
142
|
-
};
|
|
143
|
-
var showMessage = function (msg, isError) {
|
|
42
|
+
exports.hideModal = exports.openModal = exports.handleRedirect = exports.hideLoader = exports.showLoader = exports.showMessage = void 0;
|
|
43
|
+
var main_dom_js_1 = __importDefault(require("./main-dom.js"));
|
|
44
|
+
exports.showMessage = function (msg, isError) {
|
|
144
45
|
var cssEl = document.createElement("style");
|
|
145
46
|
var css = ".ms-error-message { position: fixed; left: 5%; right: 5%; bottom: 3%; z-index: 10000000; display: block; margin-right: auto; margin-left: auto; padding-top: 1em; padding-right: 10px; padding-bottom: 1em; border-radius: 3px; background-color: #fd3a57; box-shadow: 0 0 0 2px #fff; color: #fff; font-size: 1.1em; line-height: 1.8em; font-weight: 700; text-align: center; }";
|
|
146
47
|
cssEl.setAttribute("data-ms-style", "");
|
|
@@ -158,8 +59,7 @@ var showMessage = function (msg, isError) {
|
|
|
158
59
|
(_b = document.querySelector("[data-ms-message]")) === null || _b === void 0 ? void 0 : _b.remove();
|
|
159
60
|
}, 4000);
|
|
160
61
|
};
|
|
161
|
-
exports.
|
|
162
|
-
var showLoader = function (element) {
|
|
62
|
+
exports.showLoader = function (element) {
|
|
163
63
|
if (element) {
|
|
164
64
|
element.style.display = "block";
|
|
165
65
|
return;
|
|
@@ -174,8 +74,7 @@ var showLoader = function (element) {
|
|
|
174
74
|
div.innerHTML = loaderHTML;
|
|
175
75
|
document.body.appendChild(div);
|
|
176
76
|
};
|
|
177
|
-
exports.
|
|
178
|
-
var hideLoader = function (element) {
|
|
77
|
+
exports.hideLoader = function (element) {
|
|
179
78
|
var _a;
|
|
180
79
|
if (element) {
|
|
181
80
|
element.style.display = "none";
|
|
@@ -183,74 +82,35 @@ var hideLoader = function (element) {
|
|
|
183
82
|
}
|
|
184
83
|
(_a = document.querySelector("[data-ms-loader]")) === null || _a === void 0 ? void 0 : _a.remove();
|
|
185
84
|
};
|
|
186
|
-
exports.
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
85
|
+
exports.handleRedirect = function (redirect, redirectOverride) {
|
|
86
|
+
if (redirectOverride)
|
|
87
|
+
return window.location.href = redirectOverride;
|
|
88
|
+
if (redirect && (window.location.pathname !== redirect))
|
|
89
|
+
return window.location.href = redirect;
|
|
90
|
+
};
|
|
91
|
+
exports.openModal = function (type, params) {
|
|
92
|
+
if (params === void 0) { params = {}; }
|
|
93
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
94
|
+
var resolveModal, modalPromise;
|
|
95
|
+
return __generator(this, function (_a) {
|
|
96
|
+
modalPromise = new Promise(function (resolve) {
|
|
97
|
+
resolveModal = resolve;
|
|
98
|
+
});
|
|
99
|
+
console.log(type);
|
|
100
|
+
new main_dom_js_1.default({
|
|
101
|
+
target: document.body,
|
|
102
|
+
props: {
|
|
103
|
+
display: type.toLowerCase(),
|
|
104
|
+
params: params,
|
|
105
|
+
onSuccess: resolveModal,
|
|
201
106
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
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);
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
return [2 /*return*/, iframe];
|
|
246
|
-
}
|
|
107
|
+
});
|
|
108
|
+
return [2 /*return*/, modalPromise];
|
|
109
|
+
});
|
|
247
110
|
});
|
|
248
|
-
}
|
|
249
|
-
exports.
|
|
250
|
-
var hideModal = function () {
|
|
111
|
+
};
|
|
112
|
+
exports.hideModal = function () {
|
|
251
113
|
var _a;
|
|
252
|
-
(
|
|
253
|
-
|
|
254
|
-
(0, exports.hideLoader)();
|
|
114
|
+
(_a = document.querySelector("#msOverlay")) === null || _a === void 0 ? void 0 : _a.remove();
|
|
115
|
+
exports.hideLoader();
|
|
255
116
|
};
|
|
256
|
-
exports.hideModal = hideModal;
|