@memberstack/dom 1.0.0-beta.29 → 1.0.0-beta.32
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.js +2 -2
- package/lib/index.d.ts +4 -3
- package/lib/index.js +5 -5
- package/lib/methods/client.d.ts +5 -3
- package/lib/methods/client.js +14 -2
- package/lib/methods/dom/methods.d.ts +2 -2
- package/lib/methods/dom/methods.js +68 -19
- package/lib/methods/dom/script.d.ts +8 -0
- package/lib/methods/dom/script.js +47 -11
- package/lib/methods/index.d.ts +6 -14
- package/lib/methods/index.js +5 -4
- package/lib/utils/logger.d.ts +3 -0
- package/lib/utils/logger.js +51 -0
- package/package.json +3 -4
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.endpoints = void 0;
|
|
4
4
|
exports.endpoints = {
|
|
5
|
-
parentOrigin: "https://ui.
|
|
6
|
-
loaderScript: "https://ui.
|
|
5
|
+
parentOrigin: "https://ui-parent.vercel.app",
|
|
6
|
+
loaderScript: "https://ui-parent.vercel.app/loader.cjs.production.min.js",
|
|
7
7
|
};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
declare const _default: {
|
|
2
|
+
init: (props: import("./methods").DOMConfig) => any;
|
|
3
|
+
};
|
|
4
|
+
export default _default;
|
package/lib/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "Persistence", { enumerable: true, get: function () { return persistence_1.Persistence; } });
|
|
6
|
-
var methods_1 = require("./methods");
|
|
7
|
-
exports.default = methods_1.Methods;
|
|
6
|
+
var methods_1 = __importDefault(require("./methods"));
|
|
7
|
+
exports.default = { init: methods_1.default.init };
|
package/lib/methods/client.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import msClient from "@memberstack/client";
|
|
2
|
-
export declare type ClientConfig = Parameters<typeof msClient["init"]>[0]
|
|
3
|
-
|
|
2
|
+
export declare type ClientConfig = Parameters<typeof msClient["init"]>[0] & {
|
|
3
|
+
useCookie?: boolean;
|
|
4
|
+
};
|
|
5
|
+
export declare const initClient: ({ useCookie, ...props }: ClientConfig) => {
|
|
4
6
|
getApp(): Promise<import("@memberstack/client/lib/types/payloads").AppPayload>;
|
|
5
7
|
getAuthProviders(): Promise<import("@memberstack/client/lib/types/payloads").AppPayload>;
|
|
6
8
|
loginMemberEmailPassword(params: import("@memberstack/client/lib/types/params").LoginMemberEmailPasswordParams): Promise<import("@memberstack/client/lib/types/payloads").LoginMemberEmailPasswordPayload>;
|
|
@@ -13,7 +15,7 @@ export declare const initClient: (props: ClientConfig) => {
|
|
|
13
15
|
getMemberReceipts(params?: import("@memberstack/client/lib/types/params").GetMemberReceiptsParams, options?: import("@memberstack/client/lib/methods").MemberstackOptions): Promise<import("@memberstack/client/lib/types/payloads").GetMemberReceiptsPayload>;
|
|
14
16
|
getAuthenticationClientSecret(params: import("@memberstack/client/lib/types/params").GetAuthenticationClientSecretParams, options?: import("@memberstack/client/lib/methods").MemberstackOptions): Promise<import("@memberstack/client/lib/types/payloads").GetAuthenticationClientSecretPayload>;
|
|
15
17
|
getTotalCheckoutAmount(params: import("@memberstack/client/lib/types/params").GetTotalCheckoutAmountParams, options?: import("@memberstack/client/lib/methods").MemberstackOptions): Promise<import("@memberstack/client/lib/types/payloads").GetTotalCheckoutAmountPayload>;
|
|
16
|
-
|
|
18
|
+
purchasePlans(params: import("@memberstack/client/lib/types/params").PurchasePlansParams, options?: import("@memberstack/client/lib/methods").MemberstackOptions): Promise<import("@memberstack/client/lib/types/payloads").PurchasePlansPayload>;
|
|
17
19
|
cancelPlan(params: import("@memberstack/client/lib/types/params").CancelPlanParams, options?: import("@memberstack/client/lib/methods").MemberstackOptions): Promise<import("@memberstack/client/lib/types/payloads").CancelPlanPayload>;
|
|
18
20
|
updateMember(params: import("@memberstack/client/lib/types/params").UpdateMemberParams, options?: import("@memberstack/client/lib/methods").MemberstackOptions): Promise<import("@memberstack/client/lib/types/payloads").UpdateMemberPayload>;
|
|
19
21
|
updateMemberAuth(params: import("@memberstack/client/lib/types/params").UpdateMemberAuthParams, options?: import("@memberstack/client/lib/methods").MemberstackOptions): Promise<import("@memberstack/client/lib/types/payloads").UpdateMemberAuthPayload>;
|
package/lib/methods/client.js
CHANGED
|
@@ -10,6 +10,17 @@ var __assign = (this && this.__assign) || function () {
|
|
|
10
10
|
};
|
|
11
11
|
return __assign.apply(this, arguments);
|
|
12
12
|
};
|
|
13
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
14
|
+
var t = {};
|
|
15
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
16
|
+
t[p] = s[p];
|
|
17
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
18
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
19
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
20
|
+
t[p[i]] = s[p[i]];
|
|
21
|
+
}
|
|
22
|
+
return t;
|
|
23
|
+
};
|
|
13
24
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
25
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
26
|
};
|
|
@@ -17,7 +28,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
17
28
|
exports.initClient = void 0;
|
|
18
29
|
var client_1 = __importDefault(require("@memberstack/client"));
|
|
19
30
|
var cookies_1 = require("../utils/cookies");
|
|
20
|
-
var initClient = function (
|
|
21
|
-
|
|
31
|
+
var initClient = function (_a) {
|
|
32
|
+
var _b = _a.useCookie, useCookie = _b === void 0 ? true : _b, props = __rest(_a, ["useCookie"]);
|
|
33
|
+
return client_1.default.init(__assign(__assign(__assign({}, (props.token && { token: props.token })), (useCookie && { token: (0, cookies_1.getMemberCookie)() })), props));
|
|
22
34
|
};
|
|
23
35
|
exports.initClient = initClient;
|
|
@@ -3,7 +3,7 @@ export declare type OpenModalParams = {
|
|
|
3
3
|
type: "LOGIN" | "SIGNUP" | "FORGOT_PASSWORD";
|
|
4
4
|
params?: {
|
|
5
5
|
planId?: string;
|
|
6
|
-
|
|
6
|
+
priceId?: string;
|
|
7
7
|
};
|
|
8
8
|
options?: {
|
|
9
9
|
onCompleted?: (x: any) => any;
|
|
@@ -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) => void
|
|
16
|
+
export declare const openModal: (props: OpenModalParams & DOMConfig) => Promise<void>;
|
|
17
17
|
export declare const hideModal: () => void;
|
|
@@ -1,10 +1,48 @@
|
|
|
1
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
|
+
};
|
|
2
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
39
|
exports.hideModal = exports.openModal = exports.load = void 0;
|
|
4
40
|
var window_1 = require("../../constants/window");
|
|
5
41
|
var endpoint_1 = require("../../constants/endpoint");
|
|
6
42
|
var cookies_1 = require("../../utils/cookies");
|
|
7
43
|
var persistence_1 = require("../../auth/persistence");
|
|
44
|
+
var logger_1 = require("../../utils/logger");
|
|
45
|
+
var script_1 = require("./script");
|
|
8
46
|
var isBrowser = typeof window !== "undefined";
|
|
9
47
|
var isInitialized = function () {
|
|
10
48
|
if (!isBrowser)
|
|
@@ -33,30 +71,41 @@ var load = function (props) {
|
|
|
33
71
|
}
|
|
34
72
|
};
|
|
35
73
|
exports.load = load;
|
|
36
|
-
var openModal = function (props) {
|
|
74
|
+
var openModal = function (props) { return __awaiter(void 0, void 0, void 0, function () {
|
|
37
75
|
var _a;
|
|
38
|
-
|
|
39
|
-
(
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
76
|
+
return __generator(this, function (_b) {
|
|
77
|
+
switch (_b.label) {
|
|
78
|
+
case 0:
|
|
79
|
+
(0, logger_1.log)("call openModal()");
|
|
80
|
+
return [4 /*yield*/, script_1.hostedUIReady.isReady];
|
|
81
|
+
case 1:
|
|
82
|
+
_b.sent();
|
|
83
|
+
if (hasIFrame()) {
|
|
84
|
+
(_a = window[window_1.Window.MSDOM]) === null || _a === void 0 ? void 0 : _a.show(props.type, props.params);
|
|
85
|
+
window.addEventListener("message", function (e) {
|
|
86
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
87
|
+
if (e.origin === endpoint_1.endpoints.parentOrigin) {
|
|
88
|
+
if (e.data.type === "CLOSE") {
|
|
89
|
+
return (0, exports.hideModal)();
|
|
90
|
+
}
|
|
91
|
+
if ((_b = (_a = e.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.member) {
|
|
92
|
+
(0, persistence_1.setPersistedMember)((_c = e.data) === null || _c === void 0 ? void 0 : _c.data.member, props.persistence);
|
|
93
|
+
}
|
|
94
|
+
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)) {
|
|
95
|
+
(0, cookies_1.setMemberCookie)(e.data.data.tokens.accessToken);
|
|
96
|
+
}
|
|
97
|
+
(_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);
|
|
98
|
+
}
|
|
99
|
+
});
|
|
45
100
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
(0, 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
|
-
};
|
|
101
|
+
return [2 /*return*/];
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
}); };
|
|
57
105
|
exports.openModal = openModal;
|
|
58
106
|
var hideModal = function () {
|
|
59
107
|
var _a;
|
|
108
|
+
(0, logger_1.log)("call hideModal()");
|
|
60
109
|
if (hasIFrame()) {
|
|
61
110
|
(_a = window[window_1.Window.MSDOM]) === null || _a === void 0 ? void 0 : _a.hide();
|
|
62
111
|
}
|
|
@@ -1,3 +1,11 @@
|
|
|
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,14 +36,15 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
-
exports.initialize = void 0;
|
|
39
|
+
exports.hostedUIReady = exports.HostedUI = exports.initialize = void 0;
|
|
40
40
|
var endpoint_1 = require("../../constants/endpoint");
|
|
41
41
|
var window_1 = require("../../constants/window");
|
|
42
|
+
var logger_1 = require("../../utils/logger");
|
|
42
43
|
var isBrowser = typeof window !== "undefined";
|
|
43
44
|
var SCRIPT_URL = endpoint_1.endpoints.loaderScript;
|
|
44
45
|
var SCRIPT_URL_REGEX = new RegExp(SCRIPT_URL);
|
|
45
46
|
var getScript = function () {
|
|
46
|
-
var existingScript = document.querySelector("script[src^=\""
|
|
47
|
+
var existingScript = document.querySelector("script[src^=\"".concat(SCRIPT_URL, "\"]"));
|
|
47
48
|
if (existingScript && SCRIPT_URL_REGEX.test(existingScript.src)) {
|
|
48
49
|
return existingScript;
|
|
49
50
|
}
|
|
@@ -55,26 +56,61 @@ var getScript = function () {
|
|
|
55
56
|
throw new Error("Memberstack requires a <body> element.");
|
|
56
57
|
}
|
|
57
58
|
document.body.appendChild(script);
|
|
59
|
+
(0, logger_1.log)("Appending script to load parent hosted UI");
|
|
58
60
|
return script;
|
|
59
61
|
};
|
|
60
62
|
function initialize(props) {
|
|
61
63
|
return __awaiter(this, void 0, void 0, function () {
|
|
62
64
|
var script;
|
|
65
|
+
var _this = this;
|
|
63
66
|
return __generator(this, function (_a) {
|
|
64
67
|
if (!isBrowser)
|
|
65
68
|
return [2 /*return*/, null];
|
|
66
69
|
script = getScript();
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
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
|
+
}); });
|
|
76
91
|
return [2 /*return*/];
|
|
77
92
|
});
|
|
78
93
|
});
|
|
79
94
|
}
|
|
80
95
|
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
|
@@ -1,26 +1,18 @@
|
|
|
1
1
|
import { Persistence } from "../auth/persistence";
|
|
2
|
-
import
|
|
3
|
-
import { initClient, ClientConfig } from "./client";
|
|
2
|
+
import { ClientConfig } from "./client";
|
|
4
3
|
declare global {
|
|
5
4
|
interface Window {
|
|
6
5
|
__MSDOM: any;
|
|
6
|
+
__MSDOMREADY: any;
|
|
7
7
|
APP_ID: string;
|
|
8
8
|
}
|
|
9
9
|
}
|
|
10
10
|
export declare type DOMConfig = ClientConfig & {
|
|
11
11
|
persistence?: Persistence;
|
|
12
12
|
useCookie: boolean;
|
|
13
|
+
debug?: boolean;
|
|
13
14
|
};
|
|
14
|
-
declare const
|
|
15
|
-
|
|
16
|
-
hideModal: () => void;
|
|
17
|
-
onAuthChange: (cb: any) => {
|
|
18
|
-
unsubscribe: () => boolean;
|
|
19
|
-
};
|
|
20
|
-
openModal: (type: DOM.OpenModalParams["type"], params?: DOM.OpenModalParams["params"], options?: DOM.OpenModalParams["options"]) => void;
|
|
15
|
+
declare const _default: {
|
|
16
|
+
init: (props: DOMConfig) => any;
|
|
21
17
|
};
|
|
22
|
-
export
|
|
23
|
-
export declare const Methods: {
|
|
24
|
-
init: (props: DOMConfig) => ReturnType<typeof initClient> & ReturnType<typeof DOMMethods>;
|
|
25
|
-
};
|
|
26
|
-
export {};
|
|
18
|
+
export default _default;
|
package/lib/methods/index.js
CHANGED
|
@@ -44,13 +44,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
44
44
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
45
45
|
};
|
|
46
46
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
47
|
-
exports.Methods = exports.init = void 0;
|
|
48
47
|
var persistence_1 = require("../auth/persistence");
|
|
49
48
|
var proxy_1 = __importDefault(require("../utils/proxy"));
|
|
50
49
|
var DOM = __importStar(require("./dom/methods"));
|
|
51
50
|
var script_1 = require("./dom/script");
|
|
52
51
|
var client_1 = require("./client");
|
|
53
52
|
var interceptor_1 = require("../utils/interceptor");
|
|
53
|
+
var logger_1 = require("../utils/logger");
|
|
54
54
|
var DOMMethods = function (_a) {
|
|
55
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"]);
|
|
56
56
|
return ({
|
|
@@ -63,13 +63,14 @@ var DOMMethods = function (_a) {
|
|
|
63
63
|
var withScript = function (fn) {
|
|
64
64
|
return function (props) {
|
|
65
65
|
var config = __assign({ persistence: persistence_1.Persistence.LOCAL, useCookie: true }, props);
|
|
66
|
+
(0, logger_1.log)("Calling Function that initializes hosted UI script");
|
|
66
67
|
(0, script_1.initialize)({ publicKey: props.publicKey });
|
|
67
68
|
return fn(config);
|
|
68
69
|
};
|
|
69
70
|
};
|
|
70
|
-
|
|
71
|
+
var init = (0, logger_1.withLogger)(withScript(function (props) {
|
|
71
72
|
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);
|
|
72
73
|
var methods = DOMMethods(props);
|
|
73
74
|
return Object.assign(client, methods);
|
|
74
|
-
});
|
|
75
|
-
exports.
|
|
75
|
+
}));
|
|
76
|
+
exports.default = { init: function (props) { return init(props); } };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __read = (this && this.__read) || function (o, n) {
|
|
3
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
4
|
+
if (!m) return o;
|
|
5
|
+
var i = m.call(o), r, ar = [], e;
|
|
6
|
+
try {
|
|
7
|
+
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
|
8
|
+
}
|
|
9
|
+
catch (error) { e = { error: error }; }
|
|
10
|
+
finally {
|
|
11
|
+
try {
|
|
12
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
13
|
+
}
|
|
14
|
+
finally { if (e) throw e.error; }
|
|
15
|
+
}
|
|
16
|
+
return ar;
|
|
17
|
+
};
|
|
18
|
+
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
19
|
+
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
20
|
+
if (ar || !(i in from)) {
|
|
21
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
22
|
+
ar[i] = from[i];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
26
|
+
};
|
|
27
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
|
+
exports.withLogger = exports.log = exports.initializeLogger = void 0;
|
|
29
|
+
var debug;
|
|
30
|
+
var initializeLogger = function (debugFlag) {
|
|
31
|
+
debug = !!debugFlag;
|
|
32
|
+
};
|
|
33
|
+
exports.initializeLogger = initializeLogger;
|
|
34
|
+
var log = function () {
|
|
35
|
+
var msg = [];
|
|
36
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
37
|
+
msg[_i] = arguments[_i];
|
|
38
|
+
}
|
|
39
|
+
if (!debug)
|
|
40
|
+
return;
|
|
41
|
+
var timestamp = '[' + Date.now() + ']';
|
|
42
|
+
console.log.apply(console, __spreadArray(['\x1b[33m%s\x1b[0m', "@memberstack/dom ".concat(timestamp)], __read(msg), false));
|
|
43
|
+
};
|
|
44
|
+
exports.log = log;
|
|
45
|
+
var withLogger = function (fn) {
|
|
46
|
+
return function (props) {
|
|
47
|
+
(0, exports.initializeLogger)(props.debug);
|
|
48
|
+
return fn(props);
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
exports.withLogger = withLogger;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberstack/dom",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.32",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"lib/**/*"
|
|
@@ -8,9 +8,8 @@
|
|
|
8
8
|
"author": "Lydia Hallie",
|
|
9
9
|
"license": "MIT",
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@memberstack/client": "^1.0.1-beta.
|
|
12
|
-
"js-cookie": "^3.0.1"
|
|
13
|
-
"node-request-interceptor": "^0.6.3"
|
|
11
|
+
"@memberstack/client": "^1.0.1-beta.12",
|
|
12
|
+
"js-cookie": "^3.0.1"
|
|
14
13
|
},
|
|
15
14
|
"scripts": {
|
|
16
15
|
"prepublishOnly": "npx tsc",
|