@memberstack/dom 1.1.0 → 1.2.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/constants/endpoint.d.ts +2 -2
- package/lib/constants/endpoint.js +2 -4
- package/lib/methods/dom/methods.d.ts +1 -1
- package/lib/methods/dom/methods.js +134 -39
- package/lib/methods/dom/script.d.ts +0 -8
- package/lib/methods/dom/script.js +1 -67
- package/lib/methods/index.d.ts +1 -0
- package/lib/methods/index.js +1 -2
- package/package.json +5 -4
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.endpoints = void 0;
|
|
4
4
|
exports.endpoints = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
// parentOrigin: "http://localhost:3000",
|
|
8
|
-
// loaderScript: "http://localhost:3000/loader.cjs.production.min.js",
|
|
5
|
+
clientEndpoint: "http://dev-api.memberstack.com/new-client",
|
|
6
|
+
hostedUI: "https://ui-20210107.vercel.app"
|
|
9
7
|
};
|
|
@@ -13,5 +13,5 @@ export declare type OpenModalParams = {
|
|
|
13
13
|
export declare const load: (props: {
|
|
14
14
|
publicKey: string;
|
|
15
15
|
}) => void;
|
|
16
|
-
export declare const openModal: (props: OpenModalParams & DOMConfig) => Promise<
|
|
16
|
+
export declare const openModal: (props: OpenModalParams & DOMConfig) => Promise<HTMLIFrameElement>;
|
|
17
17
|
export declare const hideModal: () => void;
|
|
@@ -35,6 +35,22 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
35
35
|
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
39
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
40
|
+
if (!m) return o;
|
|
41
|
+
var i = m.call(o), r, ar = [], e;
|
|
42
|
+
try {
|
|
43
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
44
|
+
}
|
|
45
|
+
catch (error) { e = { error: error }; }
|
|
46
|
+
finally {
|
|
47
|
+
try {
|
|
48
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
49
|
+
}
|
|
50
|
+
finally { if (e) throw e.error; }
|
|
51
|
+
}
|
|
52
|
+
return ar;
|
|
53
|
+
};
|
|
38
54
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
55
|
exports.hideModal = exports.openModal = exports.load = void 0;
|
|
40
56
|
var window_1 = require("../../constants/window");
|
|
@@ -42,7 +58,6 @@ var endpoint_1 = require("../../constants/endpoint");
|
|
|
42
58
|
var cookies_1 = require("../../utils/cookies");
|
|
43
59
|
var persistence_1 = require("../../auth/persistence");
|
|
44
60
|
var logger_1 = require("../../utils/logger");
|
|
45
|
-
var script_1 = require("./script");
|
|
46
61
|
var isBrowser = typeof window !== "undefined";
|
|
47
62
|
var isInitialized = function () {
|
|
48
63
|
if (!isBrowser)
|
|
@@ -53,17 +68,6 @@ var isInitialized = function () {
|
|
|
53
68
|
}
|
|
54
69
|
return true;
|
|
55
70
|
};
|
|
56
|
-
var hasIFrame = function () {
|
|
57
|
-
var initialized = isInitialized();
|
|
58
|
-
if (!initialized)
|
|
59
|
-
return false;
|
|
60
|
-
var iframe = document.querySelector("iframe[id=\"_ms-iframe\"]");
|
|
61
|
-
if (!iframe) {
|
|
62
|
-
console.warn("iFrame has not been loaded yet.");
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
return true;
|
|
66
|
-
};
|
|
67
71
|
var load = function (props) {
|
|
68
72
|
var _a;
|
|
69
73
|
if (isInitialized()) {
|
|
@@ -71,34 +75,126 @@ var load = function (props) {
|
|
|
71
75
|
}
|
|
72
76
|
};
|
|
73
77
|
exports.load = load;
|
|
74
|
-
var
|
|
78
|
+
var getAppId = function (publicKey) { return __awaiter(void 0, void 0, void 0, function () {
|
|
79
|
+
var res, json, e_1;
|
|
80
|
+
var _a, _b;
|
|
81
|
+
return __generator(this, function (_c) {
|
|
82
|
+
switch (_c.label) {
|
|
83
|
+
case 0:
|
|
84
|
+
if (typeof window === "undefined")
|
|
85
|
+
return [2 /*return*/, null];
|
|
86
|
+
if (window === null || window === void 0 ? void 0 : window["__MS-APPID"]) {
|
|
87
|
+
return [2 /*return*/, window["__MS-APPID"]];
|
|
88
|
+
}
|
|
89
|
+
if (!publicKey)
|
|
90
|
+
return [2 /*return*/, null];
|
|
91
|
+
_c.label = 1;
|
|
92
|
+
case 1:
|
|
93
|
+
_c.trys.push([1, 4, , 5]);
|
|
94
|
+
return [4 /*yield*/, fetch(endpoint_1.endpoints.clientEndpoint + "/app", {
|
|
95
|
+
headers: {
|
|
96
|
+
"x-api-key": publicKey,
|
|
97
|
+
},
|
|
98
|
+
})];
|
|
99
|
+
case 2:
|
|
100
|
+
res = _c.sent();
|
|
101
|
+
return [4 /*yield*/, res.json()];
|
|
102
|
+
case 3:
|
|
103
|
+
json = _c.sent();
|
|
104
|
+
if (json.code)
|
|
105
|
+
throw json;
|
|
106
|
+
window["__MS-APPID"] = (_a = json.data) === null || _a === void 0 ? void 0 : _a.id;
|
|
107
|
+
return [2 /*return*/, (_b = json.data) === null || _b === void 0 ? void 0 : _b.id];
|
|
108
|
+
case 4:
|
|
109
|
+
e_1 = _c.sent();
|
|
110
|
+
throw e_1;
|
|
111
|
+
case 5: return [2 /*return*/];
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}); };
|
|
115
|
+
var TYPE_PARAMS = {
|
|
116
|
+
LOGIN: "login",
|
|
117
|
+
SIGNUP: "signup",
|
|
118
|
+
FORGOT_PASSWORD: "sendResetEmail",
|
|
119
|
+
};
|
|
120
|
+
var createLink = function (query) {
|
|
121
|
+
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;
|
|
122
|
+
var queryParams = Object.keys({ priceId: priceId, pk: pk, hideNav: hideNav })
|
|
123
|
+
.map(function (key) { return query[key] && encodeURIComponent(key) + "=" + encodeURIComponent(query[key]); })
|
|
124
|
+
.filter(function (x) { return x; })
|
|
125
|
+
.join("&");
|
|
126
|
+
var baseUrl = endpoint_1.endpoints.hostedUI + "/" + (appId || "") + (page ? "/" + page : "") + (planId ? (page === "signup" ? "/" + planId : "?planId=" + planId) : "");
|
|
127
|
+
return "" + baseUrl + (baseUrl.includes("?planId") ? "&" : "?") + queryParams;
|
|
128
|
+
};
|
|
129
|
+
var showLoader = function () {
|
|
130
|
+
var cssEl = document.createElement("style");
|
|
131
|
+
var css = ".ms__loader { width: 100%; height: 100%; overflow: hidden; position: absolute; top: 0; left: 0; display: flex; justify-content: center; align-items: center; } #msLoader path { fill: #007ace; }";
|
|
132
|
+
cssEl.appendChild(document.createTextNode(css));
|
|
133
|
+
document.head.appendChild(cssEl);
|
|
134
|
+
var loaderHTML = '<?xml version="1.0"?><div class="ms__loader"><svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" id="msLoader" x="0px" y="0px" width="40px" height="40px" viewBox="0 0 50 50" style="enable-background: new 0 0 50 50;" xml:space="preserve"><path fill="#000" d="M43.935,25.145c0-10.318-8.364-18.683-18.683-18.683c-10.318,0-18.683,8.365-18.683,18.683h4.068c0-8.071,6.543-14.615,14.615-14.615c8.072,0,14.615,6.543,14.615,14.615H43.935z"><animateTransform attributeType="xml" attributeName="transform" type="rotate" from="0 25 25" to="360 25 25" dur="0.6s" repeatCount="indefinite"/></path></svg></div>';
|
|
135
|
+
var div = document.createElement("div");
|
|
136
|
+
div.setAttribute("data-ms-loader", "true");
|
|
137
|
+
div.innerHTML = loaderHTML;
|
|
138
|
+
document.body.appendChild(div);
|
|
139
|
+
};
|
|
140
|
+
var hideLoader = function () {
|
|
75
141
|
var _a;
|
|
76
|
-
|
|
77
|
-
|
|
142
|
+
(_a = document.querySelector("[data-ms-loader]")) === null || _a === void 0 ? void 0 : _a.remove();
|
|
143
|
+
};
|
|
144
|
+
var openModal = function (props) { return __awaiter(void 0, void 0, void 0, function () {
|
|
145
|
+
var appId, page, link, div, iframe, iframestyles;
|
|
146
|
+
var _a, _b;
|
|
147
|
+
return __generator(this, function (_c) {
|
|
148
|
+
switch (_c.label) {
|
|
78
149
|
case 0:
|
|
79
150
|
(0, logger_1.log)("call openModal()");
|
|
80
|
-
|
|
151
|
+
showLoader();
|
|
152
|
+
return [4 /*yield*/, getAppId(props.publicKey)];
|
|
81
153
|
case 1:
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
154
|
+
appId = _c.sent();
|
|
155
|
+
page = TYPE_PARAMS[props.type];
|
|
156
|
+
link = createLink({
|
|
157
|
+
pk: props.publicKey,
|
|
158
|
+
planId: (_a = props.params) === null || _a === void 0 ? void 0 : _a.planId,
|
|
159
|
+
priceId: (_b = props.params) === null || _b === void 0 ? void 0 : _b.priceId,
|
|
160
|
+
appId: appId,
|
|
161
|
+
page: page,
|
|
162
|
+
});
|
|
163
|
+
div = document.createElement("div");
|
|
164
|
+
div.setAttribute("data-ms-iframe", "true");
|
|
165
|
+
iframe = document.createElement("iframe");
|
|
166
|
+
iframestyles = {
|
|
167
|
+
height: "100vh",
|
|
168
|
+
width: "100vw",
|
|
169
|
+
position: "absolute",
|
|
170
|
+
top: 0,
|
|
171
|
+
bottom: 0,
|
|
172
|
+
border: "none",
|
|
173
|
+
};
|
|
174
|
+
Object.entries(iframestyles).map(function (_a) {
|
|
175
|
+
var _b = __read(_a, 2), attr = _b[0], value = _b[1];
|
|
176
|
+
iframe.style[attr] = value;
|
|
177
|
+
});
|
|
178
|
+
iframe.setAttribute("src", link);
|
|
179
|
+
iframe.addEventListener("load", function () {
|
|
180
|
+
hideLoader();
|
|
181
|
+
});
|
|
182
|
+
div.append(iframe);
|
|
183
|
+
document.body.appendChild(div);
|
|
184
|
+
window.addEventListener("message", function (e) {
|
|
185
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
186
|
+
if (e.data.type === "CLOSE") {
|
|
187
|
+
return (0, exports.hideModal)();
|
|
188
|
+
}
|
|
189
|
+
if ((_b = (_a = e.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.member) {
|
|
190
|
+
(0, persistence_1.setPersistedMember)((_c = e.data) === null || _c === void 0 ? void 0 : _c.data.member, props.persistence);
|
|
191
|
+
}
|
|
192
|
+
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)) {
|
|
193
|
+
(0, cookies_1.setMemberCookie)(e.data.data.tokens.accessToken);
|
|
194
|
+
}
|
|
195
|
+
(_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);
|
|
196
|
+
});
|
|
197
|
+
return [2 /*return*/, iframe];
|
|
102
198
|
}
|
|
103
199
|
});
|
|
104
200
|
}); };
|
|
@@ -106,8 +202,7 @@ exports.openModal = openModal;
|
|
|
106
202
|
var hideModal = function () {
|
|
107
203
|
var _a;
|
|
108
204
|
(0, logger_1.log)("call hideModal()");
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
205
|
+
(_a = document.querySelector("[data-ms-iframe]")) === null || _a === void 0 ? void 0 : _a.remove();
|
|
206
|
+
hideLoader();
|
|
112
207
|
};
|
|
113
208
|
exports.hideModal = hideModal;
|
|
@@ -1,11 +1,3 @@
|
|
|
1
1
|
export declare function initialize(props: {
|
|
2
2
|
publicKey: string;
|
|
3
3
|
}): Promise<any>;
|
|
4
|
-
export declare class HostedUI {
|
|
5
|
-
private __globalResolver;
|
|
6
|
-
private __isReady;
|
|
7
|
-
constructor();
|
|
8
|
-
get isReady(): Promise<void>;
|
|
9
|
-
resolve(): void;
|
|
10
|
-
}
|
|
11
|
-
export declare const hostedUIReady: HostedUI;
|
|
@@ -36,81 +36,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.
|
|
40
|
-
var endpoint_1 = require("../../constants/endpoint");
|
|
41
|
-
var window_1 = require("../../constants/window");
|
|
42
|
-
var logger_1 = require("../../utils/logger");
|
|
39
|
+
exports.initialize = void 0;
|
|
43
40
|
var isBrowser = typeof window !== "undefined";
|
|
44
|
-
var SCRIPT_URL = endpoint_1.endpoints.loaderScript;
|
|
45
|
-
var SCRIPT_URL_REGEX = new RegExp(SCRIPT_URL);
|
|
46
|
-
var getScript = function () {
|
|
47
|
-
var existingScript = document.querySelector("script[src^=\"" + SCRIPT_URL + "\"]");
|
|
48
|
-
if (existingScript && SCRIPT_URL_REGEX.test(existingScript.src)) {
|
|
49
|
-
return existingScript;
|
|
50
|
-
}
|
|
51
|
-
var script = document.createElement("script");
|
|
52
|
-
script.src = SCRIPT_URL;
|
|
53
|
-
script.defer = true;
|
|
54
|
-
script.crossOrigin = "true";
|
|
55
|
-
if (!document.body) {
|
|
56
|
-
throw new Error("Memberstack requires a <body> element.");
|
|
57
|
-
}
|
|
58
|
-
document.body.appendChild(script);
|
|
59
|
-
(0, logger_1.log)("Appending script to load parent hosted UI");
|
|
60
|
-
return script;
|
|
61
|
-
};
|
|
62
41
|
function initialize(props) {
|
|
63
42
|
return __awaiter(this, void 0, void 0, function () {
|
|
64
|
-
var script;
|
|
65
|
-
var _this = this;
|
|
66
43
|
return __generator(this, function (_a) {
|
|
67
44
|
if (!isBrowser)
|
|
68
45
|
return [2 /*return*/, null];
|
|
69
|
-
script = getScript();
|
|
70
|
-
(0, logger_1.log)("Add script event listener for load");
|
|
71
|
-
script.addEventListener("load", function () { return __awaiter(_this, void 0, void 0, function () {
|
|
72
|
-
return __generator(this, function (_a) {
|
|
73
|
-
switch (_a.label) {
|
|
74
|
-
case 0:
|
|
75
|
-
(0, logger_1.log)("Hosted UI parent script loaded");
|
|
76
|
-
if (!window[window_1.Window.MSDOM]) return [3 /*break*/, 2];
|
|
77
|
-
(0, logger_1.log)("Call MSDOM load function, pass public key");
|
|
78
|
-
return [4 /*yield*/, window[window_1.Window.MSDOM].load({ publicKey: props.publicKey })];
|
|
79
|
-
case 1:
|
|
80
|
-
_a.sent();
|
|
81
|
-
exports.hostedUIReady.resolve();
|
|
82
|
-
console.info("\x1b[36m%s\x1b[0m", "Memberstack has been initialized");
|
|
83
|
-
return [3 /*break*/, 3];
|
|
84
|
-
case 2:
|
|
85
|
-
console.warn("Could not initialize Memberstack.");
|
|
86
|
-
_a.label = 3;
|
|
87
|
-
case 3: return [2 /*return*/];
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
}); });
|
|
91
46
|
return [2 /*return*/];
|
|
92
47
|
});
|
|
93
48
|
});
|
|
94
49
|
}
|
|
95
50
|
exports.initialize = initialize;
|
|
96
|
-
var HostedUI = /** @class */ (function () {
|
|
97
|
-
function HostedUI() {
|
|
98
|
-
var _this = this;
|
|
99
|
-
this.__isReady = new Promise(function (resolve) {
|
|
100
|
-
_this.__globalResolver = resolve;
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
Object.defineProperty(HostedUI.prototype, "isReady", {
|
|
104
|
-
get: function () {
|
|
105
|
-
return this.__isReady;
|
|
106
|
-
},
|
|
107
|
-
enumerable: false,
|
|
108
|
-
configurable: true
|
|
109
|
-
});
|
|
110
|
-
HostedUI.prototype.resolve = function () {
|
|
111
|
-
this.__globalResolver();
|
|
112
|
-
};
|
|
113
|
-
return HostedUI;
|
|
114
|
-
}());
|
|
115
|
-
exports.HostedUI = HostedUI;
|
|
116
|
-
exports.hostedUIReady = new HostedUI();
|
package/lib/methods/index.d.ts
CHANGED
package/lib/methods/index.js
CHANGED
|
@@ -47,7 +47,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
47
47
|
var persistence_1 = require("../auth/persistence");
|
|
48
48
|
var proxy_1 = __importDefault(require("../utils/proxy"));
|
|
49
49
|
var DOM = __importStar(require("./dom/methods"));
|
|
50
|
-
var script_1 = require("./dom/script");
|
|
51
50
|
var client_1 = require("./client");
|
|
52
51
|
var interceptor_1 = require("../utils/interceptor");
|
|
53
52
|
var logger_1 = require("../utils/logger");
|
|
@@ -64,7 +63,7 @@ var withScript = function (fn) {
|
|
|
64
63
|
return function (props) {
|
|
65
64
|
var config = __assign({ persistence: persistence_1.Persistence.LOCAL, useCookie: true }, props);
|
|
66
65
|
(0, logger_1.log)("Calling Function that initializes hosted UI script");
|
|
67
|
-
|
|
66
|
+
//initialize({ publicKey: props.publicKey });
|
|
68
67
|
return fn(config);
|
|
69
68
|
};
|
|
70
69
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberstack/dom",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"lib/**/*"
|
|
@@ -8,12 +8,13 @@
|
|
|
8
8
|
"author": "Lydia Hallie",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@memberstack/client": "^1.
|
|
11
|
+
"@memberstack/client": "^1.4.0",
|
|
12
12
|
"js-cookie": "^3.0.1"
|
|
13
13
|
},
|
|
14
14
|
"scripts": {
|
|
15
15
|
"prepublishOnly": "npx tsc",
|
|
16
|
-
"watch": "
|
|
17
|
-
"clean": "rm -rf node_modules"
|
|
16
|
+
"watch": "tsc-watch --onSuccess 'yarn replace:vars:local'",
|
|
17
|
+
"clean": "rm -rf node_modules",
|
|
18
|
+
"replace:vars:local": "ts-node utils/replaceDynamicVars -development"
|
|
18
19
|
}
|
|
19
20
|
}
|