@memberstack/dom 1.0.0-beta.23 → 1.0.0-beta.24

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.
@@ -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://dev-ui-parent.vercel.app",
6
- loaderScript: "https://dev-ui-parent.vercel.app/loader.cjs.production.min.js",
5
+ parentOrigin: "https://ui.memberstack.com",
6
+ loaderScript: "https://ui.memberstack.com/loader.cjs.production.min.js",
7
7
  };
@@ -1,3 +1,4 @@
1
1
  export declare const Window: {
2
- MEMBERSTACK: string;
2
+ MSDOM: string;
3
+ APP_ID: string;
3
4
  };
@@ -2,5 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Window = void 0;
4
4
  exports.Window = {
5
- MEMBERSTACK: "memberstack",
5
+ MSDOM: "__MSDOM",
6
+ APP_ID: "__MS-APPID",
6
7
  };
package/lib/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- declare const _default: {
2
- init: (props: import("./methods").DOMConfig) => any;
3
- };
4
- export default _default;
1
+ export { Persistence } from "./auth/persistence";
2
+ import { Methods } from "./methods";
3
+ export default Methods;
package/lib/index.js CHANGED
@@ -1,4 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Persistence = void 0;
4
+ var persistence_1 = require("./auth/persistence");
5
+ Object.defineProperty(exports, "Persistence", { enumerable: true, get: function () { return persistence_1.Persistence; } });
3
6
  var methods_1 = require("./methods");
4
- exports.default = { init: methods_1.init };
7
+ exports.default = methods_1.Methods;
@@ -1,5 +1,9 @@
1
- import msClient from "@memberstack/client";
2
- export declare type ClientConfig = Parameters<typeof msClient["init"]>[0];
1
+ export interface ClientConfig {
2
+ publicKey: string;
3
+ useCookie?: boolean;
4
+ token?: string;
5
+ apiVersion?: "2021-01-07";
6
+ }
3
7
  export declare const initClient: (props: ClientConfig) => {
4
8
  getApp(): Promise<import("@memberstack/client/lib/types/payloads").AppPayload>;
5
9
  getAuthProviders(): Promise<import("@memberstack/client/lib/types/payloads").AppPayload>;
@@ -29,7 +33,7 @@ export declare const initClient: (props: ClientConfig) => {
29
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>;
30
34
  verifyToken({ token }: {
31
35
  token: string;
32
- }): Promise<Pick<import("jose/types").JWTPayload, "iat" | "exp"> & {
36
+ }): Promise<Pick<import("jose").JWTPayload, "iat" | "exp"> & {
33
37
  id: string;
34
38
  type: "member";
35
39
  }>;
@@ -1,31 +1,17 @@
1
1
  import type { DOMConfig } from "..";
2
- declare type ActionParams = {
3
- onCompleted?: (x: any) => any;
4
- onError?: (x: any) => any;
5
- };
6
- export declare type OpenModalParams = ActionParams & ({
7
- type: "LOGIN";
2
+ export declare type OpenModalParams = {
3
+ type: "LOGIN" | "SIGNUP" | "FORGOT_PASSWORD";
8
4
  params?: {
9
5
  planId?: string;
10
- priceId?: string;
11
- };
12
- } | {
13
- type: "SIGNUP";
14
- params: {
15
- planId: string;
16
- priceId?: string;
6
+ planPaymentOptionId?: string;
17
7
  };
18
- } | {
19
- type: "FORGOT_PASSWORD";
20
- params: {};
21
- });
22
- export declare const initDOM: (props: {
23
- publicKey: string;
24
- } & DOMConfig) => {
25
- openModal: (openModalProps: OpenModalParams) => void;
26
- hideModal: any;
27
- onAuthChange: (cb: any) => {
28
- unsubscribe: () => boolean;
8
+ options?: {
9
+ onCompleted?: (x: any) => any;
10
+ onError?: (x: any) => any;
29
11
  };
30
12
  };
31
- export {};
13
+ export declare const load: (props: {
14
+ publicKey: string;
15
+ }) => void;
16
+ export declare const openModal: (props: OpenModalParams & DOMConfig) => void;
17
+ export declare const hideModal: () => void;
@@ -1,48 +1,64 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
15
- };
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.initDOM = void 0;
3
+ exports.hideModal = exports.openModal = exports.load = void 0;
4
+ var window_1 = require("../../constants/window");
18
5
  var endpoint_1 = require("../../constants/endpoint");
19
6
  var cookies_1 = require("../../utils/cookies");
20
7
  var persistence_1 = require("../../auth/persistence");
21
- var ui_1 = __importDefault(require("@memberstack/ui"));
22
- var initDOM = function (props) {
23
- var methods = ui_1.default.init({ publicKey: props.publicKey });
24
- return {
25
- openModal: function (openModalProps) { return openModal(methods, __assign(__assign({}, props), openModalProps)); },
26
- hideModal: methods.hide,
27
- onAuthChange: persistence_1.onAuthChange
28
- };
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;
29
17
  };
30
- exports.initDOM = initDOM;
31
- var openModal = function (methods, props) {
32
- methods.show(props.type, props.params);
33
- window.addEventListener("message", function (e) {
34
- var _a, _b, _c, _d, _e, _f, _g, _h;
35
- if (e.origin === endpoint_1.endpoints.parentOrigin) {
36
- if (e.data.type === "CLOSE") {
37
- return methods.hide();
38
- }
39
- if ((_b = (_a = e.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.member) {
40
- (0, persistence_1.setPersistedMember)((_c = e.data) === null || _c === void 0 ? void 0 : _c.data.member, props.persistence);
41
- }
42
- 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)) {
43
- (0, cookies_1.setMemberCookie)(e.data.data.tokens.accessToken);
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 (0, 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
+ (0, 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
+ (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);
44
53
  }
45
- (_g = props.onCompleted) === null || _g === void 0 ? void 0 : _g.call(props, (_h = e.data) === null || _h === void 0 ? void 0 : _h.data);
46
- }
47
- });
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
+ }
48
63
  };
64
+ exports.hideModal = hideModal;
@@ -1 +1,3 @@
1
- export declare function appendScript(): Promise<any>;
1
+ export declare function initialize(props: {
2
+ publicKey: string;
3
+ }): Promise<any>;
@@ -1,36 +1,80 @@
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
- exports.appendScript = void 0;
39
+ exports.initialize = void 0;
4
40
  var endpoint_1 = require("../../constants/endpoint");
5
41
  var window_1 = require("../../constants/window");
42
+ var isBrowser = typeof window !== "undefined";
6
43
  var SCRIPT_URL = endpoint_1.endpoints.loaderScript;
7
44
  var SCRIPT_URL_REGEX = new RegExp(SCRIPT_URL);
8
- var injectScript = function () {
9
- var existingScript = document.querySelector("script[src^=\"".concat(SCRIPT_URL, "\"]"));
10
- if (existingScript && SCRIPT_URL_REGEX.test(existingScript.src) && window[window_1.Window.MEMBERSTACK]) {
11
- return Promise.resolve(window[window_1.Window.MEMBERSTACK]);
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;
12
49
  }
13
50
  var script = document.createElement("script");
14
- script.type = "text/javascript";
15
51
  script.src = SCRIPT_URL;
16
52
  script.defer = true;
17
53
  script.crossOrigin = "true";
54
+ if (!document.body) {
55
+ throw new Error("Memberstack requires a <body> element.");
56
+ }
18
57
  document.body.appendChild(script);
19
- return new Promise(function (res, rej) {
20
- script.addEventListener("load", function () {
21
- if (window[window_1.Window.MEMBERSTACK]) {
22
- return res(window[window_1.Window.MEMBERSTACK]);
23
- }
24
- else {
25
- return rej("Could not initialize Memberstack.");
26
- }
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*/];
27
77
  });
28
78
  });
29
- };
30
- function appendScript() {
31
- if (typeof window === "undefined" || !(document === null || document === void 0 ? void 0 : document.body)) {
32
- throw new Error("Memberstack requires a <body> element.");
33
- }
34
- return injectScript();
35
79
  }
36
- exports.appendScript = appendScript;
80
+ exports.initialize = initialize;
@@ -1,12 +1,25 @@
1
1
  import { Persistence } from "../auth/persistence";
2
- import { ClientConfig } from "./client";
2
+ import * as DOM from "./dom/methods";
3
+ import { initClient, ClientConfig } from "./client";
3
4
  declare global {
4
5
  interface Window {
5
- memberstack: any;
6
+ __MSDOM: any;
7
+ APP_ID: string;
6
8
  }
7
9
  }
8
10
  export declare type DOMConfig = ClientConfig & {
9
11
  persistence?: Persistence;
10
- useCookie?: boolean;
11
12
  };
12
- export declare const init: (props: DOMConfig) => any;
13
+ declare const DOMMethods: ({ useCookie, persistence, ...props }: DOMConfig) => {
14
+ load: () => void;
15
+ hideModal: () => void;
16
+ onAuthChange: (cb: any) => {
17
+ unsubscribe: () => boolean;
18
+ };
19
+ openModal: (type: DOM.OpenModalParams["type"], params?: DOM.OpenModalParams["params"], options?: DOM.OpenModalParams["options"]) => void;
20
+ };
21
+ export declare const init: (props: DOMConfig) => ReturnType<typeof initClient> & ReturnType<typeof DOMMethods>;
22
+ export declare const Methods: {
23
+ init: (props: DOMConfig) => ReturnType<typeof initClient> & ReturnType<typeof DOMMethods>;
24
+ };
25
+ export {};
@@ -10,18 +10,67 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
14
+ if (k2 === undefined) k2 = k;
15
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
16
+ }) : (function(o, m, k, k2) {
17
+ if (k2 === undefined) k2 = k;
18
+ o[k2] = m[k];
19
+ }));
20
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
21
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
22
+ }) : function(o, v) {
23
+ o["default"] = v;
24
+ });
25
+ var __importStar = (this && this.__importStar) || function (mod) {
26
+ if (mod && mod.__esModule) return mod;
27
+ var result = {};
28
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
29
+ __setModuleDefault(result, mod);
30
+ return result;
31
+ };
32
+ var __rest = (this && this.__rest) || function (s, e) {
33
+ var t = {};
34
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
35
+ t[p] = s[p];
36
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
37
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
38
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
39
+ t[p[i]] = s[p[i]];
40
+ }
41
+ return t;
42
+ };
13
43
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
44
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
45
  };
16
46
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.init = void 0;
47
+ exports.Methods = exports.init = void 0;
48
+ var persistence_1 = require("../auth/persistence");
18
49
  var proxy_1 = __importDefault(require("../utils/proxy"));
19
- var dom_1 = require("./dom");
50
+ var DOM = __importStar(require("./dom/methods"));
51
+ var script_1 = require("./dom/script");
20
52
  var client_1 = require("./client");
21
53
  var interceptor_1 = require("../utils/interceptor");
22
- var init = function (props) {
23
- 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);
24
- var ui = (0, dom_1.initDOM)({ publicKey: props.publicKey });
25
- return Object.assign(client, ui);
54
+ var DOMMethods = function (_a) {
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
+ return ({
57
+ load: function () { return DOM.load({ publicKey: props.publicKey }); },
58
+ hideModal: DOM.hideModal,
59
+ onAuthChange: persistence_1.onAuthChange,
60
+ openModal: function (type, params, options) { return DOM.openModal(__assign({ type: type, params: params, options: options, useCookie: useCookie, persistence: persistence }, props)); },
61
+ });
62
+ };
63
+ var withScript = function (fn) {
64
+ return function (props) {
65
+ var config = __assign({ persistence: persistence_1.Persistence.LOCAL, useCookie: true }, props);
66
+ (0, script_1.initialize)({ publicKey: props.publicKey });
67
+ (0, interceptor_1.initializeInterceptors)({ persistence: config.persistence });
68
+ return fn(config);
69
+ };
26
70
  };
27
- exports.init = init;
71
+ exports.init = withScript(function (props) {
72
+ var client = (0, proxy_1.default)((0, client_1.initClient)(props), props);
73
+ var methods = DOMMethods(props);
74
+ return Object.assign(client, methods);
75
+ });
76
+ exports.Methods = { init: exports.init };
@@ -1,2 +1,2 @@
1
1
  export declare const setMemberCookie: (token: any, expires?: number) => void;
2
- export declare const getMemberCookie: () => any;
2
+ export declare const getMemberCookie: () => string;
@@ -1,4 +1,3 @@
1
- export declare const handleMemberToken: ({ persistence, token }: {
1
+ export declare const initializeInterceptors: ({ persistence }: {
2
2
  persistence: any;
3
- token: any;
4
3
  }) => void;
@@ -1,18 +1,28 @@
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
- exports.handleMemberToken = void 0;
6
+ exports.initializeInterceptors = void 0;
7
+ var node_request_interceptor_1 = require("node-request-interceptor");
8
+ var default_1 = __importDefault(require("node-request-interceptor/lib/presets/default"));
4
9
  var cookies_1 = require("./cookies");
5
10
  var persistence_1 = require("../auth/persistence");
6
- var handleMemberToken = function (_a) {
7
- var persistence = _a.persistence, token = _a.token;
8
- if (token === "null") {
9
- (0, cookies_1.setMemberCookie)("", -1);
10
- if ((0, persistence_1.getPersistedMember)(persistence)) {
11
- (0, persistence_1.unsetPersistedMember)(persistence);
11
+ var interceptor = new node_request_interceptor_1.RequestInterceptor(default_1.default);
12
+ var initializeInterceptors = function (_a) {
13
+ var persistence = _a.persistence;
14
+ interceptor.on("response", function (req, response) {
15
+ if (response === null || response === void 0 ? void 0 : response.headers["ms-mid"]) {
16
+ if ((response === null || response === void 0 ? void 0 : response.headers["ms-mid"]) === "null") {
17
+ (0, cookies_1.setMemberCookie)("", -1);
18
+ if ((0, persistence_1.getPersistedMember)(persistence)) {
19
+ (0, persistence_1.unsetPersistedMember)(persistence);
20
+ }
21
+ }
22
+ else {
23
+ (0, cookies_1.setMemberCookie)(response.headers["ms-mid"]);
24
+ }
12
25
  }
13
- }
14
- else {
15
- (0, cookies_1.setMemberCookie)(token);
16
- }
26
+ });
17
27
  };
18
- exports.handleMemberToken = handleMemberToken;
28
+ exports.initializeInterceptors = initializeInterceptors;
@@ -1,4 +1,40 @@
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
  var __read = (this && this.__read) || function (o, n) {
3
39
  var m = typeof Symbol === "function" && o[Symbol.iterator];
4
40
  if (!m) return o;
@@ -50,10 +86,13 @@ var handleResponse = function (fn, props) {
50
86
  };
51
87
  var handler = function (props) { return ({
52
88
  get: function (target, prop, receiver) {
89
+ var _this = this;
53
90
  if (prop === "getCurrentMember") {
54
91
  var persistedMember_1 = (0, persistence_1.getPersistedMember)(props.persistence);
55
92
  if (persistedMember_1) {
56
- return function () { return ({ data: persistedMember_1 }); };
93
+ return function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
94
+ return [2 /*return*/, ({ data: persistedMember_1 })];
95
+ }); }); };
57
96
  }
58
97
  }
59
98
  return handleResponse(Reflect.get(target, prop, receiver), props);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@memberstack/dom",
3
- "version": "1.0.0-beta.23",
3
+ "version": "1.0.0-beta.24",
4
4
  "main": "./lib/index.js",
5
5
  "files": [
6
6
  "lib/**/*"
@@ -8,15 +8,13 @@
8
8
  "author": "Lydia Hallie",
9
9
  "license": "MIT",
10
10
  "dependencies": {
11
- "@memberstack/client": "^1.0.1-beta.7",
12
- "@memberstack/ui": "^0.0.2-2",
13
- "axios": "^0.24.0",
14
- "js-cookie": "^3.0.1"
11
+ "@memberstack/client": "^1.0.1-beta.8",
12
+ "js-cookie": "^3.0.1",
13
+ "node-request-interceptor": "^0.6.3"
15
14
  },
16
15
  "scripts": {
17
- "prepublishOnly": "tsc"
18
- },
19
- "devDependencies": {
20
- "typescript": "^4.5.2"
16
+ "prepublishOnly": "npx tsc",
17
+ "watch": "npx tsc -w",
18
+ "clean": "rm -rf node_modules"
21
19
  }
22
20
  }
@@ -1,26 +0,0 @@
1
- import type { DOMConfig } from ".";
2
- declare type ActionParams = {
3
- onCompleted?: (x: any) => any;
4
- onError?: (x: any) => any;
5
- };
6
- export declare type OpenModalParams = ActionParams & ({
7
- type: "LOGIN";
8
- planId?: string;
9
- priceId?: string;
10
- } | {
11
- type: "SIGNUP";
12
- planId: string;
13
- priceId?: string;
14
- } | {
15
- type: "FORGOT_PASSWORD";
16
- });
17
- export declare const initDOM: (props: {
18
- publicKey: string;
19
- } & DOMConfig) => {
20
- openModal: (openModalProps: OpenModalParams) => void;
21
- hideModal: any;
22
- onAuthChange: (cb: any) => {
23
- unsubscribe: () => boolean;
24
- };
25
- };
26
- export {};
@@ -1,48 +0,0 @@
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.initDOM = void 0;
18
- var ui_1 = __importDefault(require("@memberstack/ui"));
19
- var endpoint_1 = require("../constants/endpoint");
20
- var cookies_1 = require("../utils/cookies");
21
- var persistence_1 = require("../auth/persistence");
22
- var initDOM = function (props) {
23
- var methods = ui_1.default.init({ publicKey: props.publicKey });
24
- return {
25
- openModal: function (openModalProps) { return openModal(methods, __assign(__assign({}, props), openModalProps)); },
26
- hideModal: methods.hide,
27
- onAuthChange: persistence_1.onAuthChange
28
- };
29
- };
30
- exports.initDOM = initDOM;
31
- var openModal = function (methods, props) {
32
- methods.show(props.type, __assign(__assign({}, ((props.type !== "FORGOT_PASSWORD" && props.planId) && { planId: props.planId })), ((props.type !== "FORGOT_PASSWORD" && props.priceId) && { priceId: props.priceId })));
33
- window.addEventListener("message", function (e) {
34
- var _a, _b, _c, _d, _e, _f, _g, _h;
35
- if (e.origin === endpoint_1.endpoints.parentOrigin) {
36
- if (e.data.type === "CLOSE") {
37
- return methods.hide();
38
- }
39
- if ((_b = (_a = e.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.member) {
40
- (0, persistence_1.setPersistedMember)((_c = e.data) === null || _c === void 0 ? void 0 : _c.data.member, props.persistence);
41
- }
42
- 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)) {
43
- (0, cookies_1.setMemberCookie)(e.data.data.tokens.accessToken);
44
- }
45
- (_g = props.onCompleted) === null || _g === void 0 ? void 0 : _g.call(props, (_h = e.data) === null || _h === void 0 ? void 0 : _h.data);
46
- }
47
- });
48
- };