@memberstack/dom 1.0.0-beta.1 → 1.0.0-beta.10
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/persistence/index.d.ts +0 -1
- package/lib/auth/persistence/index.js +0 -1
- package/lib/auth/persistence/local.d.ts +1 -1
- package/lib/auth/persistence/local.js +16 -21
- package/lib/auth/persistence/methods.js +2 -2
- package/lib/auth/persistence/session.d.ts +1 -1
- package/lib/auth/persistence/session.js +16 -21
- package/lib/constants/storage.d.ts +1 -0
- package/lib/constants/storage.js +4 -0
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/methods/client.d.ts +644 -0
- package/lib/methods/client.js +12 -0
- package/lib/methods/dom/index.d.ts +2 -0
- package/lib/methods/dom/index.js +9 -0
- package/lib/methods/dom/methods.d.ts +17 -0
- package/lib/methods/dom/methods.js +64 -0
- package/lib/methods/dom/script.d.ts +3 -0
- package/lib/methods/dom/script.js +80 -0
- package/lib/methods/index.d.ts +12 -1301
- package/lib/methods/index.js +23 -27
- package/lib/utils/cookies.d.ts +1 -2
- package/lib/utils/cookies.js +7 -11
- package/lib/utils/interceptor.d.ts +1 -0
- package/lib/utils/interceptor.js +21 -0
- package/lib/utils/localStorage.d.ts +6 -0
- package/lib/utils/localStorage.js +21 -0
- package/lib/utils/proxy.d.ts +2 -0
- package/lib/utils/proxy.js +96 -0
- package/package.json +2 -2
- package/lib/auth/persistence/interceptor.d.ts +0 -2
- package/lib/auth/persistence/interceptor.js +0 -43
- package/lib/methods/dom.d.ts +0 -10
- package/lib/methods/dom.js +0 -55
- package/lib/types/params.d.ts +0 -11
- package/lib/types/params.js +0 -2
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hideModal = exports.openModal = exports.load = void 0;
|
|
4
|
+
var window_1 = require("../../constants/window");
|
|
5
|
+
var endpoint_1 = require("../../constants/endpoint");
|
|
6
|
+
var cookies_1 = require("../../utils/cookies");
|
|
7
|
+
var persistence_1 = require("../../auth/persistence");
|
|
8
|
+
var isBrowser = typeof window !== "undefined";
|
|
9
|
+
var isInitialized = function () {
|
|
10
|
+
if (!isBrowser)
|
|
11
|
+
return;
|
|
12
|
+
if (!(window === null || window === void 0 ? void 0 : window[window_1.Window.MSDOM])) {
|
|
13
|
+
console.warn("Memberstack has not been initialized yet.");
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
return true;
|
|
17
|
+
};
|
|
18
|
+
var hasIFrame = function () {
|
|
19
|
+
var initialized = isInitialized();
|
|
20
|
+
if (!initialized)
|
|
21
|
+
return false;
|
|
22
|
+
var iframe = document.querySelector("iframe[id=\"_ms-iframe\"]");
|
|
23
|
+
if (!iframe) {
|
|
24
|
+
console.warn("iFrame has not been loaded yet.");
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
};
|
|
29
|
+
var load = function (props) {
|
|
30
|
+
var _a;
|
|
31
|
+
if (isInitialized()) {
|
|
32
|
+
(_a = window[window_1.Window.MSDOM]) === null || _a === void 0 ? void 0 : _a.load({ publicKey: props.publicKey });
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
exports.load = load;
|
|
36
|
+
var openModal = function (props) {
|
|
37
|
+
var _a;
|
|
38
|
+
if (hasIFrame()) {
|
|
39
|
+
(_a = window[window_1.Window.MSDOM]) === null || _a === void 0 ? void 0 : _a.show(props.type, props.params);
|
|
40
|
+
window.addEventListener("message", function (e) {
|
|
41
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
42
|
+
if (e.origin === endpoint_1.endpoints.parentOrigin) {
|
|
43
|
+
if (e.data.type === "CLOSE") {
|
|
44
|
+
return exports.hideModal();
|
|
45
|
+
}
|
|
46
|
+
if ((_b = (_a = e.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.member) {
|
|
47
|
+
persistence_1.setPersistedMember((_c = e.data) === null || _c === void 0 ? void 0 : _c.data.member, props.persistence);
|
|
48
|
+
}
|
|
49
|
+
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)) {
|
|
50
|
+
cookies_1.setMemberCookie(e.data.data.tokens.accessToken);
|
|
51
|
+
}
|
|
52
|
+
(_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);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
exports.openModal = openModal;
|
|
58
|
+
var hideModal = function () {
|
|
59
|
+
var _a;
|
|
60
|
+
if (hasIFrame()) {
|
|
61
|
+
(_a = window[window_1.Window.MSDOM]) === null || _a === void 0 ? void 0 : _a.hide();
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
exports.hideModal = hideModal;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
12
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
13
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
14
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
15
|
+
function step(op) {
|
|
16
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
17
|
+
while (_) try {
|
|
18
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
19
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
20
|
+
switch (op[0]) {
|
|
21
|
+
case 0: case 1: t = op; break;
|
|
22
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
23
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
24
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
25
|
+
default:
|
|
26
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
27
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
28
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
29
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
30
|
+
if (t[2]) _.ops.pop();
|
|
31
|
+
_.trys.pop(); continue;
|
|
32
|
+
}
|
|
33
|
+
op = body.call(thisArg, _);
|
|
34
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
35
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.initialize = void 0;
|
|
40
|
+
var endpoint_1 = require("../../constants/endpoint");
|
|
41
|
+
var window_1 = require("../../constants/window");
|
|
42
|
+
var isBrowser = typeof window !== "undefined";
|
|
43
|
+
var SCRIPT_URL = endpoint_1.endpoints.loaderScript;
|
|
44
|
+
var SCRIPT_URL_REGEX = new RegExp(SCRIPT_URL);
|
|
45
|
+
var getScript = function () {
|
|
46
|
+
var existingScript = document.querySelector("script[src^=\"" + SCRIPT_URL + "\"]");
|
|
47
|
+
if (existingScript && SCRIPT_URL_REGEX.test(existingScript.src)) {
|
|
48
|
+
return existingScript;
|
|
49
|
+
}
|
|
50
|
+
var script = document.createElement("script");
|
|
51
|
+
script.src = SCRIPT_URL;
|
|
52
|
+
script.defer = true;
|
|
53
|
+
script.crossOrigin = "true";
|
|
54
|
+
if (!document.body) {
|
|
55
|
+
throw new Error("Memberstack requires a <body> element.");
|
|
56
|
+
}
|
|
57
|
+
document.body.appendChild(script);
|
|
58
|
+
return script;
|
|
59
|
+
};
|
|
60
|
+
function initialize(props) {
|
|
61
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
62
|
+
var script;
|
|
63
|
+
return __generator(this, function (_a) {
|
|
64
|
+
if (!isBrowser)
|
|
65
|
+
return [2 /*return*/, null];
|
|
66
|
+
script = getScript();
|
|
67
|
+
script.addEventListener("load", function () {
|
|
68
|
+
if (window[window_1.Window.MSDOM]) {
|
|
69
|
+
window[window_1.Window.MSDOM].load({ publicKey: props.publicKey });
|
|
70
|
+
console.info("\x1b[36m%s\x1b[0m", "Memberstack has been initialized.");
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
console.warn("Could not initialize Memberstack.");
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
return [2 /*return*/];
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
exports.initialize = initialize;
|