@memberstack/dom 1.6.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 +3 -2
- package/lib/methods/client.d.ts +1 -1
- package/lib/methods/dom/methods.d.ts +2 -1
- package/lib/methods/dom/methods.js +44 -81
- package/lib/methods/index.d.ts +3 -2
- package/lib/methods/index.js +10 -1
- package/lib/utils/proxy.js +5 -1
- package/package.json +6 -5
package/lib/index.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ declare const _default: {
|
|
|
31
31
|
resetMemberPassword(params: import("@memberstack/client/lib/types/params").ResetMemberPasswordParams): Promise<import("@memberstack/client/lib/types/payloads").ResetMemberPasswordPayload>;
|
|
32
32
|
logout(options?: import("@memberstack/client/lib/methods").MemberstackOptions): Promise<import("@memberstack/client/lib/types/payloads").LogoutMemberPayload>;
|
|
33
33
|
replacePlan(params: import("@memberstack/client/lib/types/params").ReplacePlanParams, options?: import("@memberstack/client/lib/methods").MemberstackOptions): Promise<import("@memberstack/client/lib/types/payloads").ReplacePlanPayload>;
|
|
34
|
-
|
|
34
|
+
decodeToken({ token }: {
|
|
35
35
|
token: string;
|
|
36
36
|
}): Promise<Pick<import("jose").JWTPayload, "iat" | "exp"> & {
|
|
37
37
|
id: string;
|
|
@@ -43,6 +43,7 @@ declare const _default: {
|
|
|
43
43
|
onAuthChange: (cb: any) => {
|
|
44
44
|
unsubscribe: () => boolean;
|
|
45
45
|
};
|
|
46
|
+
getMemberCookie: () => string;
|
|
46
47
|
_showLoader: (element?: any) => void;
|
|
47
48
|
_hideLoader: (element?: any) => void;
|
|
48
49
|
_showMessage: (msg: any, isError: any) => void;
|
|
@@ -52,7 +53,7 @@ declare const _default: {
|
|
|
52
53
|
}, options?: {
|
|
53
54
|
onCompleted?: (x: any) => any;
|
|
54
55
|
onError?: (x: any) => any;
|
|
55
|
-
}) => Promise<
|
|
56
|
+
}) => Promise<unknown>;
|
|
56
57
|
};
|
|
57
58
|
};
|
|
58
59
|
export default _default;
|
package/lib/methods/client.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ export declare const initClient: ({ useCookie, ...props }: ClientConfig) => {
|
|
|
34
34
|
resetMemberPassword(params: import("@memberstack/client/lib/types/params").ResetMemberPasswordParams): Promise<import("@memberstack/client/lib/types/payloads").ResetMemberPasswordPayload>;
|
|
35
35
|
logout(options?: import("@memberstack/client/lib/methods").MemberstackOptions): Promise<import("@memberstack/client/lib/types/payloads").LogoutMemberPayload>;
|
|
36
36
|
replacePlan(params: import("@memberstack/client/lib/types/params").ReplacePlanParams, options?: import("@memberstack/client/lib/methods").MemberstackOptions): Promise<import("@memberstack/client/lib/types/payloads").ReplacePlanPayload>;
|
|
37
|
-
|
|
37
|
+
decodeToken({ token }: {
|
|
38
38
|
token: string;
|
|
39
39
|
}): Promise<Pick<import("jose").JWTPayload, "iat" | "exp"> & {
|
|
40
40
|
id: string;
|
|
@@ -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
|
|
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
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
};
|
|
11
|
-
|
|
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
|
|
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,62 +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
|
|
189
|
-
|
|
190
|
-
|
|
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
|
-
|
|
195
|
-
|
|
196
|
-
|
|
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
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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);
|
|
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,
|
|
239
203
|
}
|
|
240
|
-
(_h = (_g = props.options) === null || _g === void 0 ? void 0 : _g.onCompleted) === null || _h === void 0 ? void 0 : _h.call(_g, (_j = e.data) === null || _j === void 0 ? void 0 : _j.data);
|
|
241
204
|
});
|
|
242
|
-
return [2 /*return*/,
|
|
205
|
+
return [2 /*return*/, modalPromise];
|
|
243
206
|
}
|
|
244
207
|
});
|
|
245
208
|
}); };
|
|
@@ -247,7 +210,7 @@ exports.openModal = openModal;
|
|
|
247
210
|
var hideModal = function () {
|
|
248
211
|
var _a;
|
|
249
212
|
(0, logger_1.log)("call hideModal()");
|
|
250
|
-
(_a = document.querySelector("
|
|
213
|
+
(_a = document.querySelector("#msOverlay")) === null || _a === void 0 ? void 0 : _a.remove();
|
|
251
214
|
(0, exports.hideLoader)();
|
|
252
215
|
};
|
|
253
216
|
exports.hideModal = hideModal;
|
package/lib/methods/index.d.ts
CHANGED
|
@@ -46,7 +46,7 @@ declare const _default: {
|
|
|
46
46
|
resetMemberPassword(params: import("@memberstack/client/lib/types/params").ResetMemberPasswordParams): Promise<import("@memberstack/client/lib/types/payloads").ResetMemberPasswordPayload>;
|
|
47
47
|
logout(options?: import("@memberstack/client/lib/methods").MemberstackOptions): Promise<import("@memberstack/client/lib/types/payloads").LogoutMemberPayload>;
|
|
48
48
|
replacePlan(params: import("@memberstack/client/lib/types/params").ReplacePlanParams, options?: import("@memberstack/client/lib/methods").MemberstackOptions): Promise<import("@memberstack/client/lib/types/payloads").ReplacePlanPayload>;
|
|
49
|
-
|
|
49
|
+
decodeToken({ token }: {
|
|
50
50
|
token: string;
|
|
51
51
|
}): Promise<Pick<import("jose").JWTPayload, "iat" | "exp"> & {
|
|
52
52
|
id: string;
|
|
@@ -58,6 +58,7 @@ declare const _default: {
|
|
|
58
58
|
onAuthChange: (cb: any) => {
|
|
59
59
|
unsubscribe: () => boolean;
|
|
60
60
|
};
|
|
61
|
+
getMemberCookie: () => string;
|
|
61
62
|
_showLoader: (element?: any) => void;
|
|
62
63
|
_hideLoader: (element?: any) => void;
|
|
63
64
|
_showMessage: (msg: any, isError: any) => void;
|
|
@@ -67,7 +68,7 @@ declare const _default: {
|
|
|
67
68
|
}, options?: {
|
|
68
69
|
onCompleted?: (x: any) => any;
|
|
69
70
|
onError?: (x: any) => any;
|
|
70
|
-
}) => Promise<
|
|
71
|
+
}) => Promise<unknown>;
|
|
71
72
|
};
|
|
72
73
|
};
|
|
73
74
|
export default _default;
|
package/lib/methods/index.js
CHANGED
|
@@ -50,12 +50,14 @@ var DOM = __importStar(require("./dom/methods"));
|
|
|
50
50
|
var client_1 = require("./client");
|
|
51
51
|
var interceptor_1 = require("../utils/interceptor");
|
|
52
52
|
var logger_1 = require("../utils/logger");
|
|
53
|
+
var cookies_1 = require("../utils/cookies");
|
|
53
54
|
var DOMMethods = function (_a) {
|
|
54
55
|
var _b = _a.useCookie, useCookie = _b === void 0 ? true : _b, _c = _a.persistence, persistence = _c === void 0 ? persistence_1.Persistence.LOCAL : _c, props = __rest(_a, ["useCookie", "persistence"]);
|
|
55
56
|
return ({
|
|
56
57
|
load: function () { return DOM.load({ publicKey: props.publicKey }); },
|
|
57
58
|
hideModal: DOM.hideModal,
|
|
58
59
|
onAuthChange: persistence_1.onAuthChange,
|
|
60
|
+
getMemberCookie: function () { return (0, cookies_1.getMemberCookie)(); },
|
|
59
61
|
_showLoader: DOM.showLoader,
|
|
60
62
|
_hideLoader: DOM.hideLoader,
|
|
61
63
|
_showMessage: DOM.showMessage,
|
|
@@ -64,8 +66,15 @@ var DOMMethods = function (_a) {
|
|
|
64
66
|
};
|
|
65
67
|
function init(props) {
|
|
66
68
|
(0, logger_1.initializeLogger)(props.debug);
|
|
69
|
+
// added because default persistence is not being set in DOMMethods above
|
|
70
|
+
if (!props.persistence) {
|
|
71
|
+
props.persistence = persistence_1.Persistence.LOCAL;
|
|
72
|
+
}
|
|
67
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);
|
|
68
74
|
var methods = DOMMethods(props);
|
|
69
|
-
|
|
75
|
+
var dom = Object.assign(client, methods);
|
|
76
|
+
//@ts-ignore
|
|
77
|
+
window.$memberstackDom = dom;
|
|
78
|
+
return dom;
|
|
70
79
|
}
|
|
71
80
|
exports.default = { init: function (props) { return init(props); } };
|
package/lib/utils/proxy.js
CHANGED
|
@@ -71,11 +71,15 @@ var handleResponse = function (fn, props) {
|
|
|
71
71
|
var result = fn.apply(void 0, __spreadArray([], __read(args), false));
|
|
72
72
|
if (result === null || result === void 0 ? void 0 : result.then) {
|
|
73
73
|
return result.then(function (res) {
|
|
74
|
-
var _a, _b, _c, _d;
|
|
74
|
+
var _a, _b, _c, _d, _e;
|
|
75
75
|
if ((_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.member) {
|
|
76
76
|
(0, persistence_1.setPersistedMember)((_b = res.data) === null || _b === void 0 ? void 0 : _b.member, props.persistence);
|
|
77
77
|
}
|
|
78
78
|
if ((_d = (_c = res === null || res === void 0 ? void 0 : res.data) === null || _c === void 0 ? void 0 : _c.id) === null || _d === void 0 ? void 0 : _d.startsWith("mem_")) {
|
|
79
|
+
// added to prevent setting persisted member value with payload from logout response
|
|
80
|
+
if (!((_e = res === null || res === void 0 ? void 0 : res.data) === null || _e === void 0 ? void 0 : _e.member)) {
|
|
81
|
+
return res;
|
|
82
|
+
}
|
|
79
83
|
(0, persistence_1.setPersistedMember)(res.data, props.persistence);
|
|
80
84
|
}
|
|
81
85
|
return res;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberstack/dom",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"lib/**/*"
|
|
@@ -8,16 +8,17 @@
|
|
|
8
8
|
"author": "Lydia Hallie",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@memberstack/client": "^1.
|
|
11
|
+
"@memberstack/client": "^1.9.0",
|
|
12
12
|
"js-cookie": "^3.0.1"
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
15
|
-
"prepublishOnly": "npx tsc",
|
|
16
|
-
"watch": "tsc-watch
|
|
15
|
+
"prepublishOnly": "yarn workspace prebuilt-uis build && npx tsc",
|
|
16
|
+
"watch": "tsc-watch",
|
|
17
|
+
"watch:dev": "tsc-watch --onSuccess 'yarn replace:vars:local'",
|
|
17
18
|
"clean": "rm -rf node_modules",
|
|
18
19
|
"replace:vars:local": "ts-node utils/replaceDynamicVars -development",
|
|
19
20
|
"deploy:latest": "npx np --tag latest --no-tests --any-branch",
|
|
20
21
|
"deploy:next": "npx np --tag next --no-tests --any-branch",
|
|
21
22
|
"build:local": "npx tsc"
|
|
22
23
|
}
|
|
23
|
-
}
|
|
24
|
+
}
|