@memberstack/dom 1.9.27 → 1.9.29
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/index.d.mts +9 -0
- package/lib/auth/index.d.ts +7 -5
- package/lib/auth/index.js +131 -75
- package/lib/auth/index.mjs +104 -0
- package/lib/constants/endpoints.d.mts +5 -0
- package/lib/constants/endpoints.d.ts +3 -1
- package/lib/constants/endpoints.js +30 -5
- package/lib/constants/endpoints.mjs +7 -0
- package/lib/index.d.mts +74 -0
- package/lib/index.d.ts +59 -34
- package/lib/index.js +14863 -6
- package/lib/index.mjs +14835 -0
- package/lib/methods/dom/index.d.mts +2 -0
- package/lib/methods/dom/index.d.ts +2 -0
- package/lib/methods/dom/index.mjs +0 -0
- package/lib/methods/dom/main-dom.d.mts +14 -0
- package/lib/methods/dom/main-dom.d.ts +4 -2
- package/lib/methods/dom/main-dom.js +13249 -12459
- package/lib/methods/dom/main-dom.mjs +13749 -0
- package/lib/methods/dom/methods.d.mts +12 -0
- package/lib/methods/dom/methods.d.ts +10 -8
- package/lib/methods/dom/methods.js +13943 -130
- package/lib/methods/dom/methods.mjs +13943 -0
- package/lib/methods/index.d.mts +79 -0
- package/lib/methods/index.d.ts +58 -35
- package/lib/methods/index.js +14855 -90
- package/lib/methods/index.mjs +14832 -0
- package/lib/methods/requests/index.d.mts +72 -0
- package/lib/methods/requests/index.d.ts +60 -40
- package/lib/methods/requests/index.js +899 -693
- package/lib/methods/requests/index.mjs +878 -0
- package/lib/methods/requests/requests.d.mts +31 -0
- package/lib/methods/requests/requests.d.ts +8 -4
- package/lib/methods/requests/requests.js +168 -117
- package/lib/methods/requests/requests.mjs +140 -0
- package/lib/types/index.d.mts +3 -0
- package/lib/types/index.d.ts +3 -2
- package/lib/types/index.js +16 -17
- package/lib/types/index.mjs +0 -0
- package/lib/types/params.d.mts +206 -0
- package/lib/types/params.d.ts +78 -33
- package/lib/types/params.js +17 -2
- package/lib/types/params.mjs +0 -0
- package/lib/types/payloads.d.mts +64 -0
- package/lib/types/payloads.d.ts +51 -43
- package/lib/types/payloads.js +17 -2
- package/lib/types/payloads.mjs +0 -0
- package/lib/types/utils/payloads.d.mts +296 -0
- package/lib/types/utils/payloads.d.ts +42 -5
- package/lib/types/utils/payloads.js +17 -3
- package/lib/types/utils/payloads.mjs +0 -0
- package/lib/utils/cookies.d.mts +7 -0
- package/lib/utils/cookies.d.ts +7 -5
- package/lib/utils/cookies.js +109 -55
- package/lib/utils/cookies.mjs +85 -0
- package/lib/utils/defaultMessageBox.d.mts +5 -0
- package/lib/utils/defaultMessageBox.d.ts +5 -3
- package/lib/utils/defaultMessageBox.js +113 -36
- package/lib/utils/defaultMessageBox.mjs +93 -0
- package/package.json +16 -10
- package/lib/utils/fileInput.d.ts +0 -1
- package/lib/utils/fileInput.js +0 -16
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
declare enum HttpMethod {
|
|
2
|
+
POST = "POST",
|
|
3
|
+
GET = "GET",
|
|
4
|
+
PATCH = "PATCH",
|
|
5
|
+
DELETE = "DELETE"
|
|
6
|
+
}
|
|
7
|
+
declare enum HttpHeaders {
|
|
8
|
+
AUTHORIZATION = "Authorization",
|
|
9
|
+
API_KEY = "X-API-Key",
|
|
10
|
+
APP_ID = "X-APP-ID",
|
|
11
|
+
API_VERSION = "X-API-Version",
|
|
12
|
+
USER_AGENT = "X-User-Agent"
|
|
13
|
+
}
|
|
14
|
+
declare const createRequestHandler: ({ publicKey, appId, token, customEndpoint, }: {
|
|
15
|
+
publicKey: any;
|
|
16
|
+
appId: any;
|
|
17
|
+
token: any;
|
|
18
|
+
customEndpoint: any;
|
|
19
|
+
}) => {
|
|
20
|
+
sendRequest: (data: {
|
|
21
|
+
method: HttpMethod;
|
|
22
|
+
url: string;
|
|
23
|
+
data?: object;
|
|
24
|
+
headers?: object;
|
|
25
|
+
contentType?: string;
|
|
26
|
+
}, options?: {
|
|
27
|
+
token?: string;
|
|
28
|
+
}) => Promise<any>;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export { HttpHeaders, HttpMethod, createRequestHandler };
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
|
|
1
|
+
declare enum HttpMethod {
|
|
2
2
|
POST = "POST",
|
|
3
|
-
GET = "GET"
|
|
3
|
+
GET = "GET",
|
|
4
|
+
PATCH = "PATCH",
|
|
5
|
+
DELETE = "DELETE"
|
|
4
6
|
}
|
|
5
|
-
|
|
7
|
+
declare enum HttpHeaders {
|
|
6
8
|
AUTHORIZATION = "Authorization",
|
|
7
9
|
API_KEY = "X-API-Key",
|
|
8
10
|
APP_ID = "X-APP-ID",
|
|
9
11
|
API_VERSION = "X-API-Version",
|
|
10
12
|
USER_AGENT = "X-User-Agent"
|
|
11
13
|
}
|
|
12
|
-
|
|
14
|
+
declare const createRequestHandler: ({ publicKey, appId, token, customEndpoint, }: {
|
|
13
15
|
publicKey: any;
|
|
14
16
|
appId: any;
|
|
15
17
|
token: any;
|
|
@@ -25,3 +27,5 @@ export declare const createRequestHandler: ({ publicKey, appId, token, customEnd
|
|
|
25
27
|
token?: string;
|
|
26
28
|
}) => Promise<any>;
|
|
27
29
|
};
|
|
30
|
+
|
|
31
|
+
export { HttpHeaders, HttpMethod, createRequestHandler };
|
|
@@ -1,122 +1,173 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
});
|
|
21
|
-
};
|
|
22
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
-
function step(op) {
|
|
27
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
-
while (_) try {
|
|
29
|
-
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;
|
|
30
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
-
switch (op[0]) {
|
|
32
|
-
case 0: case 1: t = op; break;
|
|
33
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
-
default:
|
|
37
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
-
if (t[2]) _.ops.pop();
|
|
42
|
-
_.trys.pop(); continue;
|
|
43
|
-
}
|
|
44
|
-
op = body.call(thisArg, _);
|
|
45
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __defProps = Object.defineProperties;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
9
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
12
|
+
var __spreadValues = (a, b) => {
|
|
13
|
+
for (var prop in b || (b = {}))
|
|
14
|
+
if (__hasOwnProp.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
if (__getOwnPropSymbols)
|
|
17
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
18
|
+
if (__propIsEnum.call(b, prop))
|
|
19
|
+
__defNormalProp(a, prop, b[prop]);
|
|
47
20
|
}
|
|
21
|
+
return a;
|
|
22
|
+
};
|
|
23
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
24
|
+
var __export = (target, all) => {
|
|
25
|
+
for (var name in all)
|
|
26
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
48
27
|
};
|
|
49
|
-
var
|
|
50
|
-
|
|
28
|
+
var __copyProps = (to, from, except, desc) => {
|
|
29
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
30
|
+
for (let key of __getOwnPropNames(from))
|
|
31
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
32
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
33
|
+
}
|
|
34
|
+
return to;
|
|
51
35
|
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
}
|
|
70
|
-
var
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
var _d, _e, _f, _g, _h, _j, _k, _l;
|
|
77
|
-
return __generator(this, function (_m) {
|
|
78
|
-
switch (_m.label) {
|
|
79
|
-
case 0:
|
|
80
|
-
_m.trys.push([0, 2, , 3]);
|
|
81
|
-
url = data.url;
|
|
82
|
-
memberToken = (0, cookies_1.getMemberToken)();
|
|
83
|
-
authHeader = [
|
|
84
|
-
(_e = (_d = data.headers) === null || _d === void 0 ? void 0 : _d["Authorization"]) === null || _e === void 0 ? void 0 : _e.replace("Bearer ", ""),
|
|
85
|
-
memberToken,
|
|
86
|
-
options === null || options === void 0 ? void 0 : options.token,
|
|
87
|
-
].find(function (x) { return x; });
|
|
88
|
-
formattedUrl = "".concat(customEndpoint || endpoints_1.endpoints.API).concat(url);
|
|
89
|
-
return [4 /*yield*/, (0, axios_1.default)({
|
|
90
|
-
method: data.method,
|
|
91
|
-
data: data.data,
|
|
92
|
-
url: formattedUrl,
|
|
93
|
-
headers: __assign(__assign(__assign(__assign(__assign({}, (authHeader && { authorization: "Bearer ".concat(authHeader) })), (publicKey && (_a = {}, _a[HttpHeaders.API_KEY] = publicKey, _a))), (appId && (_b = {}, _b[HttpHeaders.APP_ID] = appId, _b))), (_c = {}, _c[HttpHeaders.USER_AGENT] = "@memberstack/client@1.2.0", _c)), (data.contentType && { "Content-Type": data.contentType })),
|
|
94
|
-
withCredentials: true,
|
|
95
|
-
})];
|
|
96
|
-
case 1:
|
|
97
|
-
res = _m.sent();
|
|
98
|
-
if ((_f = res === null || res === void 0 ? void 0 : res.headers) === null || _f === void 0 ? void 0 : _f["ms-mid"]) {
|
|
99
|
-
token = res.headers["ms-mid"];
|
|
100
|
-
}
|
|
101
|
-
if ((_g = res === null || res === void 0 ? void 0 : res.data) === null || _g === void 0 ? void 0 : _g.error) {
|
|
102
|
-
if (res.data.error.name === "JsonWebTokenError") {
|
|
103
|
-
throw {
|
|
104
|
-
code: "client/invalid-token",
|
|
105
|
-
message: "An invalid token has been provided. Please make sure the token is valid.",
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
throw (_h = res.data) === null || _h === void 0 ? void 0 : _h.error;
|
|
109
|
-
}
|
|
110
|
-
return [2 /*return*/, res === null || res === void 0 ? void 0 : res.data];
|
|
111
|
-
case 2:
|
|
112
|
-
e_1 = _m.sent();
|
|
113
|
-
if (!e_1.response)
|
|
114
|
-
throw e_1;
|
|
115
|
-
throw ((_k = (_j = e_1.response) === null || _j === void 0 ? void 0 : _j.data) === null || _k === void 0 ? void 0 : _k.error) || ((_l = e_1.response) === null || _l === void 0 ? void 0 : _l.data);
|
|
116
|
-
case 3: return [2 /*return*/];
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
|
-
}); },
|
|
36
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
37
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
38
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
39
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
40
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
41
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
42
|
+
mod
|
|
43
|
+
));
|
|
44
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
45
|
+
var __async = (__this, __arguments, generator) => {
|
|
46
|
+
return new Promise((resolve, reject) => {
|
|
47
|
+
var fulfilled = (value) => {
|
|
48
|
+
try {
|
|
49
|
+
step(generator.next(value));
|
|
50
|
+
} catch (e) {
|
|
51
|
+
reject(e);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
var rejected = (value) => {
|
|
55
|
+
try {
|
|
56
|
+
step(generator.throw(value));
|
|
57
|
+
} catch (e) {
|
|
58
|
+
reject(e);
|
|
59
|
+
}
|
|
120
60
|
};
|
|
61
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
62
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
63
|
+
});
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
// src/methods/requests/requests.ts
|
|
67
|
+
var requests_exports = {};
|
|
68
|
+
__export(requests_exports, {
|
|
69
|
+
HttpHeaders: () => HttpHeaders,
|
|
70
|
+
HttpMethod: () => HttpMethod,
|
|
71
|
+
createRequestHandler: () => createRequestHandler
|
|
72
|
+
});
|
|
73
|
+
module.exports = __toCommonJS(requests_exports);
|
|
74
|
+
var import_axios = __toESM(require("axios"));
|
|
75
|
+
|
|
76
|
+
// src/constants/endpoints.ts
|
|
77
|
+
var endpoints = {
|
|
78
|
+
API: process.env.API_ENDPOINT
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
// src/utils/cookies.ts
|
|
82
|
+
var import_js_cookie = __toESM(require("js-cookie"));
|
|
83
|
+
var memberAuthTokenName = "_ms-mid";
|
|
84
|
+
function isLocalStorageAvailable() {
|
|
85
|
+
try {
|
|
86
|
+
localStorage.setItem("test", "test");
|
|
87
|
+
localStorage.removeItem("test");
|
|
88
|
+
return true;
|
|
89
|
+
} catch (e) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
var localStorageAvailable = isLocalStorageAvailable();
|
|
94
|
+
var useCookies = false;
|
|
95
|
+
var getMemberToken = () => {
|
|
96
|
+
if (localStorageAvailable && !useCookies) {
|
|
97
|
+
const memAuthToken = localStorage.getItem(memberAuthTokenName);
|
|
98
|
+
if (memAuthToken)
|
|
99
|
+
return memAuthToken;
|
|
100
|
+
}
|
|
101
|
+
return import_js_cookie.default.get(memberAuthTokenName);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
// src/methods/requests/requests.ts
|
|
105
|
+
var HttpMethod = /* @__PURE__ */ ((HttpMethod2) => {
|
|
106
|
+
HttpMethod2["POST"] = "POST";
|
|
107
|
+
HttpMethod2["GET"] = "GET";
|
|
108
|
+
HttpMethod2["PATCH"] = "PATCH";
|
|
109
|
+
HttpMethod2["DELETE"] = "DELETE";
|
|
110
|
+
return HttpMethod2;
|
|
111
|
+
})(HttpMethod || {});
|
|
112
|
+
var HttpHeaders = /* @__PURE__ */ ((HttpHeaders2) => {
|
|
113
|
+
HttpHeaders2["AUTHORIZATION"] = "Authorization";
|
|
114
|
+
HttpHeaders2["API_KEY"] = "X-API-Key";
|
|
115
|
+
HttpHeaders2["APP_ID"] = "X-APP-ID";
|
|
116
|
+
HttpHeaders2["API_VERSION"] = "X-API-Version";
|
|
117
|
+
HttpHeaders2["USER_AGENT"] = "X-User-Agent";
|
|
118
|
+
return HttpHeaders2;
|
|
119
|
+
})(HttpHeaders || {});
|
|
120
|
+
var createRequestHandler = ({
|
|
121
|
+
publicKey,
|
|
122
|
+
appId,
|
|
123
|
+
token,
|
|
124
|
+
customEndpoint
|
|
125
|
+
}) => {
|
|
126
|
+
return {
|
|
127
|
+
sendRequest: (data, options) => __async(void 0, null, function* () {
|
|
128
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
129
|
+
try {
|
|
130
|
+
const { url } = data;
|
|
131
|
+
const memberToken = getMemberToken();
|
|
132
|
+
const authHeader = [
|
|
133
|
+
(_b = (_a = data.headers) == null ? void 0 : _a["Authorization"]) == null ? void 0 : _b.replace("Bearer ", ""),
|
|
134
|
+
memberToken,
|
|
135
|
+
options == null ? void 0 : options.token
|
|
136
|
+
].find((x) => x);
|
|
137
|
+
const formattedUrl = `${customEndpoint || endpoints.API}${url}`;
|
|
138
|
+
const res = yield (0, import_axios.default)({
|
|
139
|
+
method: data.method,
|
|
140
|
+
data: data.data,
|
|
141
|
+
url: formattedUrl,
|
|
142
|
+
headers: __spreadValues(__spreadProps(__spreadValues(__spreadValues(__spreadValues({}, authHeader && { authorization: `Bearer ${authHeader}` }), publicKey && { ["X-API-Key" /* API_KEY */]: publicKey }), appId && { ["X-APP-ID" /* APP_ID */]: appId }), {
|
|
143
|
+
["X-User-Agent" /* USER_AGENT */]: "@memberstack/client@1.2.0"
|
|
144
|
+
}), data.contentType && { "Content-Type": data.contentType }),
|
|
145
|
+
withCredentials: true
|
|
146
|
+
});
|
|
147
|
+
if ((_c = res == null ? void 0 : res.headers) == null ? void 0 : _c["ms-mid"]) {
|
|
148
|
+
token = res.headers["ms-mid"];
|
|
149
|
+
}
|
|
150
|
+
if ((_d = res == null ? void 0 : res.data) == null ? void 0 : _d.error) {
|
|
151
|
+
if (res.data.error.name === "JsonWebTokenError") {
|
|
152
|
+
throw {
|
|
153
|
+
code: "client/invalid-token",
|
|
154
|
+
message: "An invalid token has been provided. Please make sure the token is valid."
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
throw (_e = res.data) == null ? void 0 : _e.error;
|
|
158
|
+
}
|
|
159
|
+
return res == null ? void 0 : res.data;
|
|
160
|
+
} catch (e) {
|
|
161
|
+
if (!e.response)
|
|
162
|
+
throw e;
|
|
163
|
+
throw ((_g = (_f = e.response) == null ? void 0 : _f.data) == null ? void 0 : _g.error) || ((_h = e.response) == null ? void 0 : _h.data);
|
|
164
|
+
}
|
|
165
|
+
})
|
|
166
|
+
};
|
|
121
167
|
};
|
|
122
|
-
|
|
168
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
169
|
+
0 && (module.exports = {
|
|
170
|
+
HttpHeaders,
|
|
171
|
+
HttpMethod,
|
|
172
|
+
createRequestHandler
|
|
173
|
+
});
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __async = (__this, __arguments, generator) => {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
var fulfilled = (value) => {
|
|
23
|
+
try {
|
|
24
|
+
step(generator.next(value));
|
|
25
|
+
} catch (e) {
|
|
26
|
+
reject(e);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var rejected = (value) => {
|
|
30
|
+
try {
|
|
31
|
+
step(generator.throw(value));
|
|
32
|
+
} catch (e) {
|
|
33
|
+
reject(e);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
// src/methods/requests/requests.ts
|
|
42
|
+
import axios from "axios";
|
|
43
|
+
|
|
44
|
+
// src/constants/endpoints.ts
|
|
45
|
+
var endpoints = {
|
|
46
|
+
API: process.env.API_ENDPOINT
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
// src/utils/cookies.ts
|
|
50
|
+
import Cookie from "js-cookie";
|
|
51
|
+
var memberAuthTokenName = "_ms-mid";
|
|
52
|
+
function isLocalStorageAvailable() {
|
|
53
|
+
try {
|
|
54
|
+
localStorage.setItem("test", "test");
|
|
55
|
+
localStorage.removeItem("test");
|
|
56
|
+
return true;
|
|
57
|
+
} catch (e) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
var localStorageAvailable = isLocalStorageAvailable();
|
|
62
|
+
var useCookies = false;
|
|
63
|
+
var getMemberToken = () => {
|
|
64
|
+
if (localStorageAvailable && !useCookies) {
|
|
65
|
+
const memAuthToken = localStorage.getItem(memberAuthTokenName);
|
|
66
|
+
if (memAuthToken)
|
|
67
|
+
return memAuthToken;
|
|
68
|
+
}
|
|
69
|
+
return Cookie.get(memberAuthTokenName);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// src/methods/requests/requests.ts
|
|
73
|
+
var HttpMethod = /* @__PURE__ */ ((HttpMethod2) => {
|
|
74
|
+
HttpMethod2["POST"] = "POST";
|
|
75
|
+
HttpMethod2["GET"] = "GET";
|
|
76
|
+
HttpMethod2["PATCH"] = "PATCH";
|
|
77
|
+
HttpMethod2["DELETE"] = "DELETE";
|
|
78
|
+
return HttpMethod2;
|
|
79
|
+
})(HttpMethod || {});
|
|
80
|
+
var HttpHeaders = /* @__PURE__ */ ((HttpHeaders2) => {
|
|
81
|
+
HttpHeaders2["AUTHORIZATION"] = "Authorization";
|
|
82
|
+
HttpHeaders2["API_KEY"] = "X-API-Key";
|
|
83
|
+
HttpHeaders2["APP_ID"] = "X-APP-ID";
|
|
84
|
+
HttpHeaders2["API_VERSION"] = "X-API-Version";
|
|
85
|
+
HttpHeaders2["USER_AGENT"] = "X-User-Agent";
|
|
86
|
+
return HttpHeaders2;
|
|
87
|
+
})(HttpHeaders || {});
|
|
88
|
+
var createRequestHandler = ({
|
|
89
|
+
publicKey,
|
|
90
|
+
appId,
|
|
91
|
+
token,
|
|
92
|
+
customEndpoint
|
|
93
|
+
}) => {
|
|
94
|
+
return {
|
|
95
|
+
sendRequest: (data, options) => __async(void 0, null, function* () {
|
|
96
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
97
|
+
try {
|
|
98
|
+
const { url } = data;
|
|
99
|
+
const memberToken = getMemberToken();
|
|
100
|
+
const authHeader = [
|
|
101
|
+
(_b = (_a = data.headers) == null ? void 0 : _a["Authorization"]) == null ? void 0 : _b.replace("Bearer ", ""),
|
|
102
|
+
memberToken,
|
|
103
|
+
options == null ? void 0 : options.token
|
|
104
|
+
].find((x) => x);
|
|
105
|
+
const formattedUrl = `${customEndpoint || endpoints.API}${url}`;
|
|
106
|
+
const res = yield axios({
|
|
107
|
+
method: data.method,
|
|
108
|
+
data: data.data,
|
|
109
|
+
url: formattedUrl,
|
|
110
|
+
headers: __spreadValues(__spreadProps(__spreadValues(__spreadValues(__spreadValues({}, authHeader && { authorization: `Bearer ${authHeader}` }), publicKey && { ["X-API-Key" /* API_KEY */]: publicKey }), appId && { ["X-APP-ID" /* APP_ID */]: appId }), {
|
|
111
|
+
["X-User-Agent" /* USER_AGENT */]: "@memberstack/client@1.2.0"
|
|
112
|
+
}), data.contentType && { "Content-Type": data.contentType }),
|
|
113
|
+
withCredentials: true
|
|
114
|
+
});
|
|
115
|
+
if ((_c = res == null ? void 0 : res.headers) == null ? void 0 : _c["ms-mid"]) {
|
|
116
|
+
token = res.headers["ms-mid"];
|
|
117
|
+
}
|
|
118
|
+
if ((_d = res == null ? void 0 : res.data) == null ? void 0 : _d.error) {
|
|
119
|
+
if (res.data.error.name === "JsonWebTokenError") {
|
|
120
|
+
throw {
|
|
121
|
+
code: "client/invalid-token",
|
|
122
|
+
message: "An invalid token has been provided. Please make sure the token is valid."
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
throw (_e = res.data) == null ? void 0 : _e.error;
|
|
126
|
+
}
|
|
127
|
+
return res == null ? void 0 : res.data;
|
|
128
|
+
} catch (e) {
|
|
129
|
+
if (!e.response)
|
|
130
|
+
throw e;
|
|
131
|
+
throw ((_g = (_f = e.response) == null ? void 0 : _f.data) == null ? void 0 : _g.error) || ((_h = e.response) == null ? void 0 : _h.data);
|
|
132
|
+
}
|
|
133
|
+
})
|
|
134
|
+
};
|
|
135
|
+
};
|
|
136
|
+
export {
|
|
137
|
+
HttpHeaders,
|
|
138
|
+
HttpMethod,
|
|
139
|
+
createRequestHandler
|
|
140
|
+
};
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { AddMemberCardParams, AddPlanParams, CancelPlanParams, CreatePostParams, CreateThreadParams, DeletePostParams, DeleteThreadParams, GetAuthenticationClientSecretParams, GetMemberInvoicesParams, GetMemberPurchasesParams, GetMemberReceiptsParams, GetPlanParams, GetPlansParams, GetPostsParams, GetSecureContentParams, GetThreadsParams, GetTotalCheckoutAmountParams, LaunchStripeCustomerPortalParams, LoginMemberEmailPasswordParams, LoginMemberPasswordlessParams, LoginWithProviderParams, OpenStripeCustomerPortalParams, PostVoteParams, PurchasePlansParams, PurchasePlansWithCheckoutParams, RemovePlanParams, ReplacePlanParams, ResetMemberPasswordParams, SendMemberLoginPasswordlessEmailParams, SendMemberResetPasswordEmailParams, SetPasswordParams, SignupMemberAuthProviderParams, SignupMemberEmailPasswordParams, SignupWithProviderParams, ThreadVoteParams, UpdateDefaultCardParams, UpdateMemberAuthParams, UpdateMemberJSONParams, UpdateMemberParams, UpdateMemberProfileImageParams, UpdatePlanPaymentParams, UpdatePostParams, UpdateThreadParams } from './params.mjs';
|
|
2
|
+
export { AddMemberCardPayload, AddPlanPayload, AppPayload, CancelPlanPayload, ConnectProviderPayload, CreatePostPayload, CreateThreadPayload, GetAppAndMemberPayload, GetAuthProvidersPayload, GetAuthenticationClientSecretPayload, GetCurrentMemberPayload, GetMemberCardsPayload, GetMemberInvoicesPayload, GetMemberJSONPayload, GetMemberReceiptsPayload, GetPlanPayload, GetPlansPayload, GetPostsPayload, GetRestrictedUrlGroupsPayload, GetSecureContentPayload, GetThreadsPayload, GetTotalCheckoutAmountPayload, LaunchStripeCustomerPortalPayload, LoginMemberEmailPasswordPayload, LogoutMemberPayload, OpenStripeCustomerPortalPayload, PurchasePlansPayload, PurchasePlansWithCheckoutPayload, RefreshMemberTokensPayload, RemovePlanPayload, ReplacePlanPayload, ResetMemberPassworPayload, SendMemberLoginPasswordlessEmailPayload, SendMemberResetPasswordEmailPayload, SendMemberVerificationEmailPayload, SetPasswordPayload, SignupMemberAuthProviderPayload, SignupMemberEmailPasswordPayload, UpdateDefaultCardPayload, UpdateMemberAuthPayload, UpdateMemberPayload, UpdateMemberProfileImagePayload, UpdatePlanPaymentPayload, UpdatePostPayload, UpdateThreadPayload } from './payloads.mjs';
|
|
3
|
+
import './utils/payloads.mjs';
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
1
|
+
export { AddMemberCardParams, AddPlanParams, CancelPlanParams, CreatePostParams, CreateThreadParams, DeletePostParams, DeleteThreadParams, GetAuthenticationClientSecretParams, GetMemberInvoicesParams, GetMemberPurchasesParams, GetMemberReceiptsParams, GetPlanParams, GetPlansParams, GetPostsParams, GetSecureContentParams, GetThreadsParams, GetTotalCheckoutAmountParams, LaunchStripeCustomerPortalParams, LoginMemberEmailPasswordParams, LoginMemberPasswordlessParams, LoginWithProviderParams, OpenStripeCustomerPortalParams, PostVoteParams, PurchasePlansParams, PurchasePlansWithCheckoutParams, RemovePlanParams, ReplacePlanParams, ResetMemberPasswordParams, SendMemberLoginPasswordlessEmailParams, SendMemberResetPasswordEmailParams, SetPasswordParams, SignupMemberAuthProviderParams, SignupMemberEmailPasswordParams, SignupWithProviderParams, ThreadVoteParams, UpdateDefaultCardParams, UpdateMemberAuthParams, UpdateMemberJSONParams, UpdateMemberParams, UpdateMemberProfileImageParams, UpdatePlanPaymentParams, UpdatePostParams, UpdateThreadParams } from './params.js';
|
|
2
|
+
export { AddMemberCardPayload, AddPlanPayload, AppPayload, CancelPlanPayload, ConnectProviderPayload, CreatePostPayload, CreateThreadPayload, GetAppAndMemberPayload, GetAuthProvidersPayload, GetAuthenticationClientSecretPayload, GetCurrentMemberPayload, GetMemberCardsPayload, GetMemberInvoicesPayload, GetMemberJSONPayload, GetMemberReceiptsPayload, GetPlanPayload, GetPlansPayload, GetPostsPayload, GetRestrictedUrlGroupsPayload, GetSecureContentPayload, GetThreadsPayload, GetTotalCheckoutAmountPayload, LaunchStripeCustomerPortalPayload, LoginMemberEmailPasswordPayload, LogoutMemberPayload, OpenStripeCustomerPortalPayload, PurchasePlansPayload, PurchasePlansWithCheckoutPayload, RefreshMemberTokensPayload, RemovePlanPayload, ReplacePlanPayload, ResetMemberPassworPayload, SendMemberLoginPasswordlessEmailPayload, SendMemberResetPasswordEmailPayload, SendMemberVerificationEmailPayload, SetPasswordPayload, SignupMemberAuthProviderPayload, SignupMemberEmailPasswordPayload, UpdateDefaultCardPayload, UpdateMemberAuthPayload, UpdateMemberPayload, UpdateMemberProfileImagePayload, UpdatePlanPaymentPayload, UpdatePostPayload, UpdateThreadPayload } from './payloads.js';
|
|
3
|
+
import './utils/payloads.js';
|
package/lib/types/index.js
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
15
12
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
|
|
15
|
+
// src/types/index.ts
|
|
16
|
+
var types_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(types_exports);
|
|
File without changes
|