@memberstack/dom 2.0.2-beta.0 → 2.0.2
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/index.d.mts +61 -26
- package/lib/index.d.ts +61 -26
- package/lib/index.js +793 -53
- package/lib/index.mjs +793 -53
- package/lib/{models-CTRKogoR.d.ts → models-CFT_ABd5.d.ts} +2 -2
- package/lib/testing/index.d.mts +25 -2
- package/lib/testing/index.d.ts +25 -2
- package/lib/testing/index.js +28 -6
- package/lib/testing/index.mjs +26 -5
- package/package.json +1 -1
- package/lib/auth/index.d.mts +0 -63
- package/lib/auth/index.d.ts +0 -63
- package/lib/auth/index.global.js +0 -244
- package/lib/auth/index.js +0 -161
- package/lib/auth/index.mjs +0 -123
- package/lib/constants/endpoints.d.mts +0 -5
- package/lib/constants/endpoints.d.ts +0 -5
- package/lib/constants/endpoints.global.js +0 -29
- package/lib/constants/endpoints.js +0 -32
- package/lib/constants/endpoints.mjs +0 -7
- package/lib/methods/dom/index.d.mts +0 -2
- package/lib/methods/dom/index.d.ts +0 -2
- package/lib/methods/dom/index.global.js +0 -2
- package/lib/methods/dom/index.js +0 -1
- package/lib/methods/dom/index.mjs +0 -0
- package/lib/methods/dom/main-dom.d.mts +0 -2
- package/lib/methods/dom/main-dom.d.ts +0 -2
- package/lib/methods/dom/main-dom.global.js +0 -30620
- package/lib/methods/dom/main-dom.js +0 -15611
- package/lib/methods/dom/main-dom.mjs +0 -15593
- package/lib/methods/dom/methods.d.mts +0 -100
- package/lib/methods/dom/methods.d.ts +0 -100
- package/lib/methods/dom/methods.global.js +0 -30827
- package/lib/methods/dom/methods.js +0 -335
- package/lib/methods/dom/methods.mjs +0 -302
- package/lib/methods/index.d.mts +0 -185
- package/lib/methods/index.d.ts +0 -185
- package/lib/methods/index.global.js +0 -46361
- package/lib/methods/index.js +0 -2530
- package/lib/methods/index.mjs +0 -2500
- package/lib/methods/requests/index.d.mts +0 -912
- package/lib/methods/requests/index.d.ts +0 -912
- package/lib/methods/requests/index.global.js +0 -15553
- package/lib/methods/requests/index.js +0 -2145
- package/lib/methods/requests/index.mjs +0 -2110
- package/lib/methods/requests/requests.d.mts +0 -43
- package/lib/methods/requests/requests.d.ts +0 -43
- package/lib/methods/requests/requests.global.js +0 -14528
- package/lib/methods/requests/requests.js +0 -244
- package/lib/methods/requests/requests.mjs +0 -210
- package/lib/models-BmZS-mc4.d.ts +0 -193
- package/lib/models-le7xaT4H.d.ts +0 -193
- package/lib/types/index.d.mts +0 -5
- package/lib/types/index.d.ts +0 -5
- package/lib/types/index.global.js +0 -19
- package/lib/types/index.js +0 -18
- package/lib/types/index.mjs +0 -0
- package/lib/types/params.d.mts +0 -946
- package/lib/types/params.d.ts +0 -946
- package/lib/types/params.global.js +0 -19
- package/lib/types/params.js +0 -18
- package/lib/types/params.mjs +0 -0
- package/lib/types/payloads.d.mts +0 -342
- package/lib/types/payloads.d.ts +0 -342
- package/lib/types/payloads.global.js +0 -19
- package/lib/types/payloads.js +0 -18
- package/lib/types/payloads.mjs +0 -0
- package/lib/types/translations.d.mts +0 -101
- package/lib/types/translations.d.ts +0 -101
- package/lib/types/translations.global.js +0 -19
- package/lib/types/translations.js +0 -18
- package/lib/types/translations.mjs +0 -0
- package/lib/types/utils/payloads.d.mts +0 -297
- package/lib/types/utils/payloads.d.ts +0 -297
- package/lib/types/utils/payloads.global.js +0 -19
- package/lib/types/utils/payloads.js +0 -18
- package/lib/types/utils/payloads.mjs +0 -0
- package/lib/utils/cookies.d.mts +0 -13
- package/lib/utils/cookies.d.ts +0 -13
- package/lib/utils/cookies.global.js +0 -261
- package/lib/utils/cookies.js +0 -190
- package/lib/utils/cookies.mjs +0 -148
- package/lib/utils/defaultMessageBox.d.mts +0 -5
- package/lib/utils/defaultMessageBox.d.ts +0 -5
- package/lib/utils/defaultMessageBox.global.js +0 -125
- package/lib/utils/defaultMessageBox.js +0 -130
- package/lib/utils/defaultMessageBox.mjs +0 -103
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __defProps = Object.defineProperties;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
-
var __spreadValues = (a, b) => {
|
|
14
|
-
for (var prop in b || (b = {}))
|
|
15
|
-
if (__hasOwnProp.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
if (__getOwnPropSymbols)
|
|
18
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
-
if (__propIsEnum.call(b, prop))
|
|
20
|
-
__defNormalProp(a, prop, b[prop]);
|
|
21
|
-
}
|
|
22
|
-
return a;
|
|
23
|
-
};
|
|
24
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
-
var __export = (target, all) => {
|
|
26
|
-
for (var name in all)
|
|
27
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
28
|
-
};
|
|
29
|
-
var __copyProps = (to, from, except, desc) => {
|
|
30
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
31
|
-
for (let key of __getOwnPropNames(from))
|
|
32
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
33
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
34
|
-
}
|
|
35
|
-
return to;
|
|
36
|
-
};
|
|
37
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
38
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
39
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
40
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
41
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
42
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
43
|
-
mod
|
|
44
|
-
));
|
|
45
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
46
|
-
var __async = (__this, __arguments, generator) => {
|
|
47
|
-
return new Promise((resolve, reject) => {
|
|
48
|
-
var fulfilled = (value) => {
|
|
49
|
-
try {
|
|
50
|
-
step(generator.next(value));
|
|
51
|
-
} catch (e) {
|
|
52
|
-
reject(e);
|
|
53
|
-
}
|
|
54
|
-
};
|
|
55
|
-
var rejected = (value) => {
|
|
56
|
-
try {
|
|
57
|
-
step(generator.throw(value));
|
|
58
|
-
} catch (e) {
|
|
59
|
-
reject(e);
|
|
60
|
-
}
|
|
61
|
-
};
|
|
62
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
63
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
64
|
-
});
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
// src/methods/requests/requests.ts
|
|
68
|
-
var requests_exports = {};
|
|
69
|
-
__export(requests_exports, {
|
|
70
|
-
HttpHeaders: () => HttpHeaders,
|
|
71
|
-
HttpMethod: () => HttpMethod,
|
|
72
|
-
createRequestHandler: () => createRequestHandler
|
|
73
|
-
});
|
|
74
|
-
module.exports = __toCommonJS(requests_exports);
|
|
75
|
-
var import_axios = __toESM(require("axios"));
|
|
76
|
-
|
|
77
|
-
// src/constants/endpoints.ts
|
|
78
|
-
var endpoints = {
|
|
79
|
-
API: "http://localhost:3005"
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
// src/utils/cookies.ts
|
|
83
|
-
var import_js_cookie = __toESM(require("js-cookie"));
|
|
84
|
-
var memberAuthTokenName = "_ms-mid";
|
|
85
|
-
function isLocalStorageAvailable() {
|
|
86
|
-
try {
|
|
87
|
-
localStorage.setItem("test", "test");
|
|
88
|
-
localStorage.removeItem("test");
|
|
89
|
-
return true;
|
|
90
|
-
} catch (e) {
|
|
91
|
-
return false;
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
var localStorageAvailable = isLocalStorageAvailable();
|
|
95
|
-
var getMemberToken = () => {
|
|
96
|
-
if (localStorageAvailable) {
|
|
97
|
-
const memAuthToken = localStorage.getItem(memberAuthTokenName);
|
|
98
|
-
if (memAuthToken)
|
|
99
|
-
return memAuthToken;
|
|
100
|
-
}
|
|
101
|
-
return import_js_cookie.default.get(memberAuthTokenName);
|
|
102
|
-
};
|
|
103
|
-
var getSessionId = () => {
|
|
104
|
-
if (typeof window === "undefined")
|
|
105
|
-
return null;
|
|
106
|
-
const sessionId = window.localStorage.getItem("ms_session_id");
|
|
107
|
-
if (!sessionId || sessionId.length > 26) {
|
|
108
|
-
window.localStorage.removeItem("ms_session_id");
|
|
109
|
-
return null;
|
|
110
|
-
}
|
|
111
|
-
return sessionId;
|
|
112
|
-
};
|
|
113
|
-
|
|
114
|
-
// src/methods/requests/requests.ts
|
|
115
|
-
var HttpMethod = /* @__PURE__ */ ((HttpMethod2) => {
|
|
116
|
-
HttpMethod2["POST"] = "POST";
|
|
117
|
-
HttpMethod2["GET"] = "GET";
|
|
118
|
-
HttpMethod2["PATCH"] = "PATCH";
|
|
119
|
-
HttpMethod2["PUT"] = "PUT";
|
|
120
|
-
HttpMethod2["DELETE"] = "DELETE";
|
|
121
|
-
return HttpMethod2;
|
|
122
|
-
})(HttpMethod || {});
|
|
123
|
-
var HttpHeaders = /* @__PURE__ */ ((HttpHeaders2) => {
|
|
124
|
-
HttpHeaders2["AUTHORIZATION"] = "Authorization";
|
|
125
|
-
HttpHeaders2["API_KEY"] = "X-API-Key";
|
|
126
|
-
HttpHeaders2["APP_ID"] = "X-APP-ID";
|
|
127
|
-
HttpHeaders2["API_VERSION"] = "X-API-Version";
|
|
128
|
-
HttpHeaders2["USER_AGENT"] = "X-User-Agent";
|
|
129
|
-
HttpHeaders2["SESSION_ID"] = "X-Session-ID";
|
|
130
|
-
return HttpHeaders2;
|
|
131
|
-
})(HttpHeaders || {});
|
|
132
|
-
var createRequestHandler = ({
|
|
133
|
-
publicKey,
|
|
134
|
-
appId,
|
|
135
|
-
token,
|
|
136
|
-
customEndpoint
|
|
137
|
-
}) => {
|
|
138
|
-
return {
|
|
139
|
-
sendRequest: (data, options) => __async(void 0, null, function* () {
|
|
140
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
141
|
-
try {
|
|
142
|
-
const { url } = data;
|
|
143
|
-
const memberToken = getMemberToken();
|
|
144
|
-
const sessionToken = getSessionId();
|
|
145
|
-
const authHeader = [
|
|
146
|
-
(_b = (_a = data.headers) == null ? void 0 : _a["Authorization"]) == null ? void 0 : _b.replace("Bearer ", ""),
|
|
147
|
-
memberToken,
|
|
148
|
-
options == null ? void 0 : options.token
|
|
149
|
-
].find((x) => x);
|
|
150
|
-
const formattedUrl = `${customEndpoint || endpoints.API}${url}`;
|
|
151
|
-
const res = yield (0, import_axios.default)({
|
|
152
|
-
method: data.method,
|
|
153
|
-
data: data.data,
|
|
154
|
-
url: formattedUrl,
|
|
155
|
-
headers: __spreadProps(__spreadValues(__spreadValues(__spreadProps(__spreadValues(__spreadValues(__spreadValues({}, authHeader && { authorization: `Bearer ${authHeader}` }), publicKey && { ["X-API-Key" /* API_KEY */]: publicKey }), appId && { ["X-APP-ID" /* APP_ID */]: appId }), {
|
|
156
|
-
["X-User-Agent" /* USER_AGENT */]: "@memberstack/client@1.2.0"
|
|
157
|
-
}), data.contentType && { "Content-Type": data.contentType }), sessionToken && {
|
|
158
|
-
["X-Session-ID" /* SESSION_ID */]: sessionToken
|
|
159
|
-
}), {
|
|
160
|
-
"referring-path": window.location.pathname
|
|
161
|
-
}),
|
|
162
|
-
withCredentials: true
|
|
163
|
-
});
|
|
164
|
-
if ((_c = res == null ? void 0 : res.headers) == null ? void 0 : _c["ms-mid"]) {
|
|
165
|
-
token = res.headers["ms-mid"];
|
|
166
|
-
}
|
|
167
|
-
if ((_d = res == null ? void 0 : res.data) == null ? void 0 : _d.error) {
|
|
168
|
-
if (res.data.error.name === "JsonWebTokenError") {
|
|
169
|
-
throw {
|
|
170
|
-
code: "client/invalid-token",
|
|
171
|
-
message: "An invalid token has been provided. Please make sure the token is valid."
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
throw (_e = res.data) == null ? void 0 : _e.error;
|
|
175
|
-
}
|
|
176
|
-
return res == null ? void 0 : res.data;
|
|
177
|
-
} catch (e) {
|
|
178
|
-
const error = e;
|
|
179
|
-
if (!error.response)
|
|
180
|
-
throw e;
|
|
181
|
-
throw ((_g = (_f = error.response) == null ? void 0 : _f.data) == null ? void 0 : _g.error) || ((_h = error.response) == null ? void 0 : _h.data);
|
|
182
|
-
}
|
|
183
|
-
}),
|
|
184
|
-
sendRequestWithFetch: (data, options) => __async(void 0, null, function* () {
|
|
185
|
-
var _a, _b;
|
|
186
|
-
try {
|
|
187
|
-
const { url, method, data: bodyData, headers, contentType } = data;
|
|
188
|
-
const memberToken = getMemberToken();
|
|
189
|
-
const authHeader = [
|
|
190
|
-
(_a = headers == null ? void 0 : headers["Authorization"]) == null ? void 0 : _a.replace("Bearer ", ""),
|
|
191
|
-
memberToken,
|
|
192
|
-
options == null ? void 0 : options.token
|
|
193
|
-
].find((x) => x);
|
|
194
|
-
const formattedUrl = `${customEndpoint || endpoints.API}${url}`;
|
|
195
|
-
const fetchHeaders = __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, authHeader && { Authorization: `Bearer ${authHeader}` }), publicKey && { ["X-API-Key" /* API_KEY */]: publicKey }), appId && { ["X-APP-ID" /* APP_ID */]: appId }), {
|
|
196
|
-
["X-User-Agent" /* USER_AGENT */]: "@memberstack/client@1.2.0",
|
|
197
|
-
"Content-Type": "application/json",
|
|
198
|
-
Referer: window.location.href
|
|
199
|
-
});
|
|
200
|
-
const response = yield fetch(formattedUrl, {
|
|
201
|
-
method,
|
|
202
|
-
headers: fetchHeaders,
|
|
203
|
-
body: bodyData ? JSON.stringify(bodyData) : void 0,
|
|
204
|
-
credentials: "include",
|
|
205
|
-
keepalive: true
|
|
206
|
-
// Keeps the connection open for further requests
|
|
207
|
-
});
|
|
208
|
-
const contentTypeHeader = response.headers.get("content-type");
|
|
209
|
-
let result;
|
|
210
|
-
if (contentTypeHeader == null ? void 0 : contentTypeHeader.includes("application/json")) {
|
|
211
|
-
result = yield response.json();
|
|
212
|
-
} else if (contentTypeHeader == null ? void 0 : contentTypeHeader.includes("text")) {
|
|
213
|
-
result = yield response.text();
|
|
214
|
-
} else if (response.status === 204) {
|
|
215
|
-
result = null;
|
|
216
|
-
} else {
|
|
217
|
-
result = yield response.text();
|
|
218
|
-
}
|
|
219
|
-
if (response.headers.get("ms-mid")) {
|
|
220
|
-
token = response.headers.get("ms-mid");
|
|
221
|
-
}
|
|
222
|
-
if (!response.ok) {
|
|
223
|
-
if (((_b = result == null ? void 0 : result.error) == null ? void 0 : _b.name) === "JsonWebTokenError") {
|
|
224
|
-
throw {
|
|
225
|
-
code: "client/invalid-token",
|
|
226
|
-
message: "An invalid token has been provided. Please make sure the token is valid."
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
throw (result == null ? void 0 : result.error) || result;
|
|
230
|
-
}
|
|
231
|
-
return result;
|
|
232
|
-
} catch (e) {
|
|
233
|
-
console.error("Error in sendRequestWithFetch:", e);
|
|
234
|
-
throw e;
|
|
235
|
-
}
|
|
236
|
-
})
|
|
237
|
-
};
|
|
238
|
-
};
|
|
239
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
240
|
-
0 && (module.exports = {
|
|
241
|
-
HttpHeaders,
|
|
242
|
-
HttpMethod,
|
|
243
|
-
createRequestHandler
|
|
244
|
-
});
|
|
@@ -1,210 +0,0 @@
|
|
|
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: "http://localhost:3005"
|
|
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 getMemberToken = () => {
|
|
63
|
-
if (localStorageAvailable) {
|
|
64
|
-
const memAuthToken = localStorage.getItem(memberAuthTokenName);
|
|
65
|
-
if (memAuthToken)
|
|
66
|
-
return memAuthToken;
|
|
67
|
-
}
|
|
68
|
-
return Cookie.get(memberAuthTokenName);
|
|
69
|
-
};
|
|
70
|
-
var getSessionId = () => {
|
|
71
|
-
if (typeof window === "undefined")
|
|
72
|
-
return null;
|
|
73
|
-
const sessionId = window.localStorage.getItem("ms_session_id");
|
|
74
|
-
if (!sessionId || sessionId.length > 26) {
|
|
75
|
-
window.localStorage.removeItem("ms_session_id");
|
|
76
|
-
return null;
|
|
77
|
-
}
|
|
78
|
-
return sessionId;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
// src/methods/requests/requests.ts
|
|
82
|
-
var HttpMethod = /* @__PURE__ */ ((HttpMethod2) => {
|
|
83
|
-
HttpMethod2["POST"] = "POST";
|
|
84
|
-
HttpMethod2["GET"] = "GET";
|
|
85
|
-
HttpMethod2["PATCH"] = "PATCH";
|
|
86
|
-
HttpMethod2["PUT"] = "PUT";
|
|
87
|
-
HttpMethod2["DELETE"] = "DELETE";
|
|
88
|
-
return HttpMethod2;
|
|
89
|
-
})(HttpMethod || {});
|
|
90
|
-
var HttpHeaders = /* @__PURE__ */ ((HttpHeaders2) => {
|
|
91
|
-
HttpHeaders2["AUTHORIZATION"] = "Authorization";
|
|
92
|
-
HttpHeaders2["API_KEY"] = "X-API-Key";
|
|
93
|
-
HttpHeaders2["APP_ID"] = "X-APP-ID";
|
|
94
|
-
HttpHeaders2["API_VERSION"] = "X-API-Version";
|
|
95
|
-
HttpHeaders2["USER_AGENT"] = "X-User-Agent";
|
|
96
|
-
HttpHeaders2["SESSION_ID"] = "X-Session-ID";
|
|
97
|
-
return HttpHeaders2;
|
|
98
|
-
})(HttpHeaders || {});
|
|
99
|
-
var createRequestHandler = ({
|
|
100
|
-
publicKey,
|
|
101
|
-
appId,
|
|
102
|
-
token,
|
|
103
|
-
customEndpoint
|
|
104
|
-
}) => {
|
|
105
|
-
return {
|
|
106
|
-
sendRequest: (data, options) => __async(void 0, null, function* () {
|
|
107
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
108
|
-
try {
|
|
109
|
-
const { url } = data;
|
|
110
|
-
const memberToken = getMemberToken();
|
|
111
|
-
const sessionToken = getSessionId();
|
|
112
|
-
const authHeader = [
|
|
113
|
-
(_b = (_a = data.headers) == null ? void 0 : _a["Authorization"]) == null ? void 0 : _b.replace("Bearer ", ""),
|
|
114
|
-
memberToken,
|
|
115
|
-
options == null ? void 0 : options.token
|
|
116
|
-
].find((x) => x);
|
|
117
|
-
const formattedUrl = `${customEndpoint || endpoints.API}${url}`;
|
|
118
|
-
const res = yield axios({
|
|
119
|
-
method: data.method,
|
|
120
|
-
data: data.data,
|
|
121
|
-
url: formattedUrl,
|
|
122
|
-
headers: __spreadProps(__spreadValues(__spreadValues(__spreadProps(__spreadValues(__spreadValues(__spreadValues({}, authHeader && { authorization: `Bearer ${authHeader}` }), publicKey && { ["X-API-Key" /* API_KEY */]: publicKey }), appId && { ["X-APP-ID" /* APP_ID */]: appId }), {
|
|
123
|
-
["X-User-Agent" /* USER_AGENT */]: "@memberstack/client@1.2.0"
|
|
124
|
-
}), data.contentType && { "Content-Type": data.contentType }), sessionToken && {
|
|
125
|
-
["X-Session-ID" /* SESSION_ID */]: sessionToken
|
|
126
|
-
}), {
|
|
127
|
-
"referring-path": window.location.pathname
|
|
128
|
-
}),
|
|
129
|
-
withCredentials: true
|
|
130
|
-
});
|
|
131
|
-
if ((_c = res == null ? void 0 : res.headers) == null ? void 0 : _c["ms-mid"]) {
|
|
132
|
-
token = res.headers["ms-mid"];
|
|
133
|
-
}
|
|
134
|
-
if ((_d = res == null ? void 0 : res.data) == null ? void 0 : _d.error) {
|
|
135
|
-
if (res.data.error.name === "JsonWebTokenError") {
|
|
136
|
-
throw {
|
|
137
|
-
code: "client/invalid-token",
|
|
138
|
-
message: "An invalid token has been provided. Please make sure the token is valid."
|
|
139
|
-
};
|
|
140
|
-
}
|
|
141
|
-
throw (_e = res.data) == null ? void 0 : _e.error;
|
|
142
|
-
}
|
|
143
|
-
return res == null ? void 0 : res.data;
|
|
144
|
-
} catch (e) {
|
|
145
|
-
const error = e;
|
|
146
|
-
if (!error.response)
|
|
147
|
-
throw e;
|
|
148
|
-
throw ((_g = (_f = error.response) == null ? void 0 : _f.data) == null ? void 0 : _g.error) || ((_h = error.response) == null ? void 0 : _h.data);
|
|
149
|
-
}
|
|
150
|
-
}),
|
|
151
|
-
sendRequestWithFetch: (data, options) => __async(void 0, null, function* () {
|
|
152
|
-
var _a, _b;
|
|
153
|
-
try {
|
|
154
|
-
const { url, method, data: bodyData, headers, contentType } = data;
|
|
155
|
-
const memberToken = getMemberToken();
|
|
156
|
-
const authHeader = [
|
|
157
|
-
(_a = headers == null ? void 0 : headers["Authorization"]) == null ? void 0 : _a.replace("Bearer ", ""),
|
|
158
|
-
memberToken,
|
|
159
|
-
options == null ? void 0 : options.token
|
|
160
|
-
].find((x) => x);
|
|
161
|
-
const formattedUrl = `${customEndpoint || endpoints.API}${url}`;
|
|
162
|
-
const fetchHeaders = __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, authHeader && { Authorization: `Bearer ${authHeader}` }), publicKey && { ["X-API-Key" /* API_KEY */]: publicKey }), appId && { ["X-APP-ID" /* APP_ID */]: appId }), {
|
|
163
|
-
["X-User-Agent" /* USER_AGENT */]: "@memberstack/client@1.2.0",
|
|
164
|
-
"Content-Type": "application/json",
|
|
165
|
-
Referer: window.location.href
|
|
166
|
-
});
|
|
167
|
-
const response = yield fetch(formattedUrl, {
|
|
168
|
-
method,
|
|
169
|
-
headers: fetchHeaders,
|
|
170
|
-
body: bodyData ? JSON.stringify(bodyData) : void 0,
|
|
171
|
-
credentials: "include",
|
|
172
|
-
keepalive: true
|
|
173
|
-
// Keeps the connection open for further requests
|
|
174
|
-
});
|
|
175
|
-
const contentTypeHeader = response.headers.get("content-type");
|
|
176
|
-
let result;
|
|
177
|
-
if (contentTypeHeader == null ? void 0 : contentTypeHeader.includes("application/json")) {
|
|
178
|
-
result = yield response.json();
|
|
179
|
-
} else if (contentTypeHeader == null ? void 0 : contentTypeHeader.includes("text")) {
|
|
180
|
-
result = yield response.text();
|
|
181
|
-
} else if (response.status === 204) {
|
|
182
|
-
result = null;
|
|
183
|
-
} else {
|
|
184
|
-
result = yield response.text();
|
|
185
|
-
}
|
|
186
|
-
if (response.headers.get("ms-mid")) {
|
|
187
|
-
token = response.headers.get("ms-mid");
|
|
188
|
-
}
|
|
189
|
-
if (!response.ok) {
|
|
190
|
-
if (((_b = result == null ? void 0 : result.error) == null ? void 0 : _b.name) === "JsonWebTokenError") {
|
|
191
|
-
throw {
|
|
192
|
-
code: "client/invalid-token",
|
|
193
|
-
message: "An invalid token has been provided. Please make sure the token is valid."
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
throw (result == null ? void 0 : result.error) || result;
|
|
197
|
-
}
|
|
198
|
-
return result;
|
|
199
|
-
} catch (e) {
|
|
200
|
-
console.error("Error in sendRequestWithFetch:", e);
|
|
201
|
-
throw e;
|
|
202
|
-
}
|
|
203
|
-
})
|
|
204
|
-
};
|
|
205
|
-
};
|
|
206
|
-
export {
|
|
207
|
-
HttpHeaders,
|
|
208
|
-
HttpMethod,
|
|
209
|
-
createRequestHandler
|
|
210
|
-
};
|
package/lib/models-BmZS-mc4.d.ts
DELETED
|
@@ -1,193 +0,0 @@
|
|
|
1
|
-
import { Payload } from './types/utils/payloads.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @fileoverview Convenience type exports for Memberstack SDK.
|
|
5
|
-
* These types provide direct access to core data models without needing
|
|
6
|
-
* to navigate the Payload.Transforms namespace.
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* ```typescript
|
|
10
|
-
* import type { Member, Plan, PlanConnection } from '@memberstack/dom';
|
|
11
|
-
*
|
|
12
|
-
* function displayMember(member: Member) {
|
|
13
|
-
* console.log(member.auth.email);
|
|
14
|
-
* }
|
|
15
|
-
* ```
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* A Memberstack member (authenticated user).
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```typescript
|
|
23
|
-
* const { data: member } = await memberstack.getCurrentMember();
|
|
24
|
-
* if (member) {
|
|
25
|
-
* console.log('Email:', member.auth.email);
|
|
26
|
-
* console.log('Verified:', member.verified);
|
|
27
|
-
* console.log('Plans:', member.planConnections.map(p => p.planId));
|
|
28
|
-
* }
|
|
29
|
-
* ```
|
|
30
|
-
*/
|
|
31
|
-
type Member = Payload.Transforms["Member"];
|
|
32
|
-
/**
|
|
33
|
-
* A membership plan in your Memberstack app.
|
|
34
|
-
*
|
|
35
|
-
* @example
|
|
36
|
-
* ```typescript
|
|
37
|
-
* const { data: plans } = await memberstack.getPlans();
|
|
38
|
-
* plans.forEach((plan: Plan) => {
|
|
39
|
-
* console.log(`${plan.name}: ${plan.prices?.[0]?.amount}`);
|
|
40
|
-
* });
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
type Plan = Payload.Transforms["Plan"];
|
|
44
|
-
/**
|
|
45
|
-
* A price option for a plan (monthly, yearly, etc.).
|
|
46
|
-
*
|
|
47
|
-
* @example
|
|
48
|
-
* ```typescript
|
|
49
|
-
* const plan = plans[0];
|
|
50
|
-
* plan.prices?.forEach((price: Price) => {
|
|
51
|
-
* console.log(`${price.name}: ${price.amount} ${price.currency}/${price.interval.type}`);
|
|
52
|
-
* });
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
|
-
type Price = Payload.Transforms["Price"];
|
|
56
|
-
/**
|
|
57
|
-
* A member's connection to a plan (subscription or one-time purchase).
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```typescript
|
|
61
|
-
* const activePlans = member.planConnections.filter(
|
|
62
|
-
* (conn: PlanConnection) => conn.active
|
|
63
|
-
* );
|
|
64
|
-
* ```
|
|
65
|
-
*/
|
|
66
|
-
type PlanConnection = Payload.Transforms["MemberPlanConnection"];
|
|
67
|
-
/**
|
|
68
|
-
* A content group that restricts access to URLs.
|
|
69
|
-
*
|
|
70
|
-
* @example
|
|
71
|
-
* ```typescript
|
|
72
|
-
* const { data: groups } = await memberstack.getRestrictedUrlGroups();
|
|
73
|
-
* const accessibleGroups = groups.filter(
|
|
74
|
-
* (g: ContentGroup) => g.activeMemberHasAccess
|
|
75
|
-
* );
|
|
76
|
-
* ```
|
|
77
|
-
*/
|
|
78
|
-
type ContentGroup = Payload.Transforms["RestrictedUrlGroup"];
|
|
79
|
-
/**
|
|
80
|
-
* App configuration and settings.
|
|
81
|
-
*
|
|
82
|
-
* @example
|
|
83
|
-
* ```typescript
|
|
84
|
-
* const { data: app } = await memberstack.getApp();
|
|
85
|
-
* console.log('App:', app.name);
|
|
86
|
-
* console.log('Mode:', app.mode); // 'live' or 'sandbox'
|
|
87
|
-
* ```
|
|
88
|
-
*/
|
|
89
|
-
type App = Payload.Transforms["App"];
|
|
90
|
-
/**
|
|
91
|
-
* Authentication provider configuration (Google, Facebook, etc.).
|
|
92
|
-
*/
|
|
93
|
-
type AuthProvider = Payload.Transforms["AuthProvider"];
|
|
94
|
-
/**
|
|
95
|
-
* Authentication response with tokens and member data.
|
|
96
|
-
*/
|
|
97
|
-
type MemberAuth = Payload.Transforms["MemberAuth"];
|
|
98
|
-
/**
|
|
99
|
-
* Auth tokens returned after login/signup.
|
|
100
|
-
*/
|
|
101
|
-
type AuthTokens = MemberAuth["tokens"];
|
|
102
|
-
/**
|
|
103
|
-
* A saved payment card for a member.
|
|
104
|
-
*
|
|
105
|
-
* @example
|
|
106
|
-
* ```typescript
|
|
107
|
-
* const { data: cards } = await memberstack.getMemberCards();
|
|
108
|
-
* const defaultCard = cards.find((card: MemberCard) => card.default);
|
|
109
|
-
* ```
|
|
110
|
-
*/
|
|
111
|
-
type MemberCard = Payload.Transforms["MemberCard"];
|
|
112
|
-
/**
|
|
113
|
-
* An invoice for a member's subscription.
|
|
114
|
-
*/
|
|
115
|
-
type MemberInvoice = Payload.Transforms["MemberInvoice"];
|
|
116
|
-
/**
|
|
117
|
-
* A payment receipt.
|
|
118
|
-
*/
|
|
119
|
-
type MemberReceipt = Payload.Transforms["MemberReceipt"];
|
|
120
|
-
/**
|
|
121
|
-
* Checkout total calculation including taxes and fees.
|
|
122
|
-
*/
|
|
123
|
-
type CheckoutTotal = Payload.Transforms["TotalCheckoutAmount"];
|
|
124
|
-
/**
|
|
125
|
-
* Gated content returned by getSecureContent().
|
|
126
|
-
*/
|
|
127
|
-
type SecureContent = Payload.Transforms["SecureContent"];
|
|
128
|
-
/**
|
|
129
|
-
* A custom field defined in your Memberstack app.
|
|
130
|
-
*/
|
|
131
|
-
type CustomField = Payload.Transforms["CustomField"];
|
|
132
|
-
/**
|
|
133
|
-
* App branding configuration.
|
|
134
|
-
*/
|
|
135
|
-
type Branding = Payload.Transforms["Branding"];
|
|
136
|
-
/**
|
|
137
|
-
* A community post.
|
|
138
|
-
*/
|
|
139
|
-
type Post = Payload.Transforms["Post"];
|
|
140
|
-
/**
|
|
141
|
-
* A thread/reply on a post.
|
|
142
|
-
*/
|
|
143
|
-
type Thread = Payload.Transforms["Thread"];
|
|
144
|
-
/**
|
|
145
|
-
* Extract the data type from a Memberstack SDK response.
|
|
146
|
-
*
|
|
147
|
-
* @example
|
|
148
|
-
* ```typescript
|
|
149
|
-
* import type { ExtractData, GetCurrentMemberPayload } from '@memberstack/dom';
|
|
150
|
-
*
|
|
151
|
-
* // Get the member type from the response
|
|
152
|
-
* type MemberData = ExtractData<GetCurrentMemberPayload>;
|
|
153
|
-
* // MemberData = Member | null
|
|
154
|
-
* ```
|
|
155
|
-
*/
|
|
156
|
-
type ExtractData<T> = T extends {
|
|
157
|
-
data: infer D;
|
|
158
|
-
} ? D : never;
|
|
159
|
-
/**
|
|
160
|
-
* Generic paginated response shape.
|
|
161
|
-
*
|
|
162
|
-
* @example
|
|
163
|
-
* ```typescript
|
|
164
|
-
* type InvoicesPage = PaginatedData<MemberInvoice>;
|
|
165
|
-
* // { data: MemberInvoice[], hasNext: boolean, endCursor: string | null, totalCount: number }
|
|
166
|
-
* ```
|
|
167
|
-
*/
|
|
168
|
-
type PaginatedData<T> = {
|
|
169
|
-
data: T[];
|
|
170
|
-
hasNext: boolean;
|
|
171
|
-
endCursor: string | null;
|
|
172
|
-
totalCount: number;
|
|
173
|
-
};
|
|
174
|
-
/**
|
|
175
|
-
* Common member fields for display purposes.
|
|
176
|
-
*
|
|
177
|
-
* @example
|
|
178
|
-
* ```typescript
|
|
179
|
-
* function getMemberDisplayInfo(member: Member): MemberDisplayInfo {
|
|
180
|
-
* return {
|
|
181
|
-
* id: member.id,
|
|
182
|
-
* email: member.auth.email,
|
|
183
|
-
* profileImage: member.profileImage,
|
|
184
|
-
* verified: member.verified,
|
|
185
|
-
* };
|
|
186
|
-
* }
|
|
187
|
-
* ```
|
|
188
|
-
*/
|
|
189
|
-
type MemberDisplayInfo = Pick<Member, 'id' | 'profileImage' | 'verified'> & {
|
|
190
|
-
email: string;
|
|
191
|
-
};
|
|
192
|
-
|
|
193
|
-
export type { App as A, Branding as B, ContentGroup as C, ExtractData as E, Member as M, Plan as P, SecureContent as S, Thread as T, Price as a, PlanConnection as b, AuthProvider as c, MemberAuth as d, AuthTokens as e, MemberCard as f, MemberInvoice as g, MemberReceipt as h, CheckoutTotal as i, CustomField as j, Post as k, PaginatedData as l, MemberDisplayInfo as m };
|