@memberstack/dom 2.0.1 → 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/README.md +356 -3
- package/lib/index.d.mts +1912 -64
- package/lib/index.d.ts +1912 -64
- package/lib/index.js +2316 -30656
- package/lib/index.mjs +2302 -30656
- package/lib/{types/utils/payloads.d.mts → models-CFT_ABd5.d.ts} +194 -6
- package/lib/testing/index.d.mts +295 -0
- package/lib/testing/index.d.ts +295 -0
- package/lib/testing/index.js +335 -0
- package/lib/testing/index.mjs +305 -0
- package/package.json +23 -12
- package/lib/auth/index.d.mts +0 -9
- package/lib/auth/index.d.ts +0 -9
- package/lib/auth/index.global.js +0 -244
- package/lib/auth/index.js +0 -158
- package/lib/auth/index.mjs +0 -121
- 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 -31
- package/lib/constants/endpoints.mjs +0 -7
- package/lib/index.global.js +0 -46364
- 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 -0
- package/lib/methods/dom/index.mjs +0 -0
- package/lib/methods/dom/main-dom.d.mts +0 -14
- package/lib/methods/dom/main-dom.d.ts +0 -14
- package/lib/methods/dom/main-dom.global.js +0 -30620
- package/lib/methods/dom/main-dom.js +0 -30618
- package/lib/methods/dom/main-dom.mjs +0 -30601
- package/lib/methods/dom/methods.d.mts +0 -18
- package/lib/methods/dom/methods.d.ts +0 -18
- package/lib/methods/dom/methods.global.js +0 -30827
- package/lib/methods/dom/methods.js +0 -30835
- package/lib/methods/dom/methods.mjs +0 -30806
- package/lib/methods/index.d.mts +0 -103
- package/lib/methods/index.d.ts +0 -103
- package/lib/methods/index.global.js +0 -46361
- package/lib/methods/index.js +0 -32125
- package/lib/methods/index.mjs +0 -32096
- package/lib/methods/requests/index.d.mts +0 -92
- package/lib/methods/requests/index.d.ts +0 -92
- package/lib/methods/requests/index.global.js +0 -15553
- package/lib/methods/requests/index.js +0 -1322
- package/lib/methods/requests/index.mjs +0 -1288
- package/lib/methods/requests/requests.d.mts +0 -42
- package/lib/methods/requests/requests.d.ts +0 -42
- package/lib/methods/requests/requests.global.js +0 -14528
- package/lib/methods/requests/requests.js +0 -242
- package/lib/methods/requests/requests.mjs +0 -209
- package/lib/types/index.d.mts +0 -4
- package/lib/types/index.d.ts +0 -4
- package/lib/types/index.global.js +0 -19
- package/lib/types/index.js +0 -17
- package/lib/types/index.mjs +0 -0
- package/lib/types/params.d.mts +0 -322
- package/lib/types/params.d.ts +0 -322
- package/lib/types/params.global.js +0 -19
- package/lib/types/params.js +0 -17
- package/lib/types/params.mjs +0 -0
- package/lib/types/payloads.d.mts +0 -143
- package/lib/types/payloads.d.ts +0 -143
- package/lib/types/payloads.global.js +0 -19
- package/lib/types/payloads.js +0 -17
- package/lib/types/payloads.mjs +0 -0
- package/lib/types/translations.d.mts +0 -43
- package/lib/types/translations.d.ts +0 -43
- package/lib/types/translations.global.js +0 -19
- package/lib/types/translations.js +0 -17
- package/lib/types/translations.mjs +0 -0
- package/lib/types/utils/payloads.d.ts +0 -299
- package/lib/types/utils/payloads.global.js +0 -19
- package/lib/types/utils/payloads.js +0 -17
- 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 -179
- package/lib/utils/cookies.mjs +0 -138
- 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 -129
- package/lib/utils/defaultMessageBox.mjs +0 -103
|
@@ -0,0 +1,305 @@
|
|
|
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/testing/index.ts
|
|
42
|
+
function mockMember(overrides = {}) {
|
|
43
|
+
const defaults = {
|
|
44
|
+
id: `mem_${randomId()}`,
|
|
45
|
+
verified: true,
|
|
46
|
+
profileImage: "",
|
|
47
|
+
auth: {
|
|
48
|
+
email: "test@example.com",
|
|
49
|
+
hasPassword: true,
|
|
50
|
+
providers: []
|
|
51
|
+
},
|
|
52
|
+
loginRedirect: "/",
|
|
53
|
+
stripeCustomerId: "",
|
|
54
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
55
|
+
metaData: {},
|
|
56
|
+
customFields: {},
|
|
57
|
+
permissions: [],
|
|
58
|
+
planConnections: []
|
|
59
|
+
};
|
|
60
|
+
return deepMerge(defaults, overrides);
|
|
61
|
+
}
|
|
62
|
+
function mockPlan(overrides = {}) {
|
|
63
|
+
const defaults = {
|
|
64
|
+
id: `pln_${randomId()}`,
|
|
65
|
+
name: "Test Plan",
|
|
66
|
+
description: "A test plan",
|
|
67
|
+
status: "PUBLISHED",
|
|
68
|
+
redirects: {
|
|
69
|
+
afterLogin: "/",
|
|
70
|
+
afterLogout: "/",
|
|
71
|
+
afterSignup: "/"
|
|
72
|
+
},
|
|
73
|
+
prices: []
|
|
74
|
+
};
|
|
75
|
+
return deepMerge(defaults, overrides);
|
|
76
|
+
}
|
|
77
|
+
function mockPlanConnection(overrides = {}) {
|
|
78
|
+
const defaults = {
|
|
79
|
+
id: `conn_${randomId()}`,
|
|
80
|
+
active: true,
|
|
81
|
+
status: "ACTIVE",
|
|
82
|
+
planId: `pln_${randomId()}`,
|
|
83
|
+
type: "FREE",
|
|
84
|
+
payment: null
|
|
85
|
+
};
|
|
86
|
+
return deepMerge(defaults, overrides);
|
|
87
|
+
}
|
|
88
|
+
function mockCard(overrides = {}) {
|
|
89
|
+
const defaults = {
|
|
90
|
+
id: `card_${randomId()}`,
|
|
91
|
+
brand: "visa",
|
|
92
|
+
expMonth: "12",
|
|
93
|
+
expYear: String((/* @__PURE__ */ new Date()).getFullYear() + 3),
|
|
94
|
+
last4: "4242",
|
|
95
|
+
default: true
|
|
96
|
+
};
|
|
97
|
+
return deepMerge(defaults, overrides);
|
|
98
|
+
}
|
|
99
|
+
function mockPrice(overrides = {}) {
|
|
100
|
+
const defaults = {
|
|
101
|
+
id: `prc_${randomId()}`,
|
|
102
|
+
amount: "0",
|
|
103
|
+
interval: {
|
|
104
|
+
type: "month",
|
|
105
|
+
count: 1
|
|
106
|
+
},
|
|
107
|
+
name: "Monthly",
|
|
108
|
+
type: "SUBSCRIPTION",
|
|
109
|
+
status: "ACTIVE",
|
|
110
|
+
currency: "usd"
|
|
111
|
+
};
|
|
112
|
+
return deepMerge(defaults, overrides);
|
|
113
|
+
}
|
|
114
|
+
function mockApp(overrides = {}) {
|
|
115
|
+
const defaults = {
|
|
116
|
+
id: `app_${randomId()}`,
|
|
117
|
+
name: "Test App",
|
|
118
|
+
mode: "sandbox",
|
|
119
|
+
plans: [],
|
|
120
|
+
contentGroups: [],
|
|
121
|
+
emailVerificationEnabled: false,
|
|
122
|
+
requireEmailVerification: false,
|
|
123
|
+
customField: [],
|
|
124
|
+
branding: {
|
|
125
|
+
logo: "",
|
|
126
|
+
colors: {
|
|
127
|
+
lightMode: {
|
|
128
|
+
primaryButton: "#6366f1"
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
authProviders: []
|
|
133
|
+
};
|
|
134
|
+
return deepMerge(defaults, overrides);
|
|
135
|
+
}
|
|
136
|
+
function mockContentGroup(overrides = {}) {
|
|
137
|
+
const defaults = {
|
|
138
|
+
id: `grp_${randomId()}`,
|
|
139
|
+
name: "Test Group",
|
|
140
|
+
key: "test-group",
|
|
141
|
+
allowAllMembers: false,
|
|
142
|
+
activeMemberHasAccess: false,
|
|
143
|
+
redirect: "/login",
|
|
144
|
+
urls: [],
|
|
145
|
+
plans: []
|
|
146
|
+
};
|
|
147
|
+
return deepMerge(defaults, overrides);
|
|
148
|
+
}
|
|
149
|
+
function createMockMemberstack(options = {}) {
|
|
150
|
+
var _a, _b, _c, _d, _e;
|
|
151
|
+
let currentMember = (_a = options.member) != null ? _a : null;
|
|
152
|
+
const plans = (_b = options.plans) != null ? _b : [];
|
|
153
|
+
const app = (_c = options.app) != null ? _c : mockApp();
|
|
154
|
+
const contentGroups = (_d = options.contentGroups) != null ? _d : [];
|
|
155
|
+
const cards = (_e = options.cards) != null ? _e : [];
|
|
156
|
+
const authListeners = [];
|
|
157
|
+
const notifyAuthChange = () => {
|
|
158
|
+
authListeners.forEach((cb) => cb({ member: currentMember }));
|
|
159
|
+
};
|
|
160
|
+
const instance = {
|
|
161
|
+
getCurrentMember: () => __async(this, null, function* () {
|
|
162
|
+
return { data: currentMember };
|
|
163
|
+
}),
|
|
164
|
+
getPlans: () => __async(this, null, function* () {
|
|
165
|
+
return { data: plans };
|
|
166
|
+
}),
|
|
167
|
+
getPlan: (_0) => __async(this, [_0], function* ({ planId }) {
|
|
168
|
+
var _a2;
|
|
169
|
+
return {
|
|
170
|
+
data: (_a2 = plans.find((p) => p.id === planId)) != null ? _a2 : null
|
|
171
|
+
};
|
|
172
|
+
}),
|
|
173
|
+
getApp: () => __async(this, null, function* () {
|
|
174
|
+
return { data: app };
|
|
175
|
+
}),
|
|
176
|
+
getRestrictedUrlGroups: () => __async(this, null, function* () {
|
|
177
|
+
return { data: contentGroups };
|
|
178
|
+
}),
|
|
179
|
+
getMemberCards: () => __async(this, null, function* () {
|
|
180
|
+
return { data: cards };
|
|
181
|
+
}),
|
|
182
|
+
loginMemberEmailPassword: (_0) => __async(this, [_0], function* ({ email }) {
|
|
183
|
+
currentMember = mockMember({ auth: { email, hasPassword: true, providers: [] } });
|
|
184
|
+
notifyAuthChange();
|
|
185
|
+
return {
|
|
186
|
+
data: {
|
|
187
|
+
member: currentMember,
|
|
188
|
+
tokens: { accessToken: `mock_token_${randomId()}`, expires: Date.now() + 36e5, type: "bearer" },
|
|
189
|
+
redirect: "/"
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
}),
|
|
193
|
+
signupMemberEmailPassword: (_0) => __async(this, [_0], function* ({ email }) {
|
|
194
|
+
currentMember = mockMember({ auth: { email, hasPassword: true, providers: [] } });
|
|
195
|
+
notifyAuthChange();
|
|
196
|
+
return {
|
|
197
|
+
data: {
|
|
198
|
+
member: currentMember,
|
|
199
|
+
tokens: { accessToken: `mock_token_${randomId()}`, expires: Date.now() + 36e5, type: "bearer" },
|
|
200
|
+
redirect: "/"
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
}),
|
|
204
|
+
logout: () => __async(this, null, function* () {
|
|
205
|
+
currentMember = null;
|
|
206
|
+
notifyAuthChange();
|
|
207
|
+
return { data: {} };
|
|
208
|
+
}),
|
|
209
|
+
updateMember: (_0) => __async(this, [_0], function* ({ customFields }) {
|
|
210
|
+
if (!currentMember) {
|
|
211
|
+
throw new Error("Not logged in");
|
|
212
|
+
}
|
|
213
|
+
if (customFields) {
|
|
214
|
+
currentMember = __spreadProps(__spreadValues({}, currentMember), {
|
|
215
|
+
customFields: __spreadValues(__spreadValues({}, currentMember.customFields), customFields)
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
return { data: currentMember };
|
|
219
|
+
}),
|
|
220
|
+
onAuthChange: (callback) => {
|
|
221
|
+
authListeners.push(callback);
|
|
222
|
+
callback({ member: currentMember });
|
|
223
|
+
return () => {
|
|
224
|
+
const index = authListeners.indexOf(callback);
|
|
225
|
+
if (index > -1)
|
|
226
|
+
authListeners.splice(index, 1);
|
|
227
|
+
};
|
|
228
|
+
},
|
|
229
|
+
// Test helpers
|
|
230
|
+
_setMember: (member) => {
|
|
231
|
+
currentMember = member;
|
|
232
|
+
notifyAuthChange();
|
|
233
|
+
},
|
|
234
|
+
_getMockState: () => ({ member: currentMember, plans, app })
|
|
235
|
+
};
|
|
236
|
+
if (options.overrides) {
|
|
237
|
+
Object.assign(instance, options.overrides);
|
|
238
|
+
}
|
|
239
|
+
return instance;
|
|
240
|
+
}
|
|
241
|
+
function randomId() {
|
|
242
|
+
return Math.random().toString(36).substring(2, 10);
|
|
243
|
+
}
|
|
244
|
+
function deepMerge(target, source) {
|
|
245
|
+
const result = __spreadValues({}, target);
|
|
246
|
+
for (const key in source) {
|
|
247
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
248
|
+
const sourceValue = source[key];
|
|
249
|
+
const targetValue = result[key];
|
|
250
|
+
if (sourceValue !== void 0 && typeof sourceValue === "object" && sourceValue !== null && !Array.isArray(sourceValue) && typeof targetValue === "object" && targetValue !== null && !Array.isArray(targetValue)) {
|
|
251
|
+
result[key] = deepMerge(targetValue, sourceValue);
|
|
252
|
+
} else if (sourceValue !== void 0) {
|
|
253
|
+
result[key] = sourceValue;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return result;
|
|
258
|
+
}
|
|
259
|
+
var memberstackMatchers = {
|
|
260
|
+
/**
|
|
261
|
+
* Assert that a member is logged in (not null and has an email).
|
|
262
|
+
*/
|
|
263
|
+
toBeLoggedIn(received) {
|
|
264
|
+
var _a;
|
|
265
|
+
const pass = received !== null && typeof ((_a = received.auth) == null ? void 0 : _a.email) === "string";
|
|
266
|
+
return {
|
|
267
|
+
pass,
|
|
268
|
+
message: () => pass ? `Expected member not to be logged in` : `Expected member to be logged in, but got ${received === null ? "null" : "invalid member object"}`
|
|
269
|
+
};
|
|
270
|
+
},
|
|
271
|
+
/**
|
|
272
|
+
* Assert that a member has a specific plan.
|
|
273
|
+
*/
|
|
274
|
+
toHavePlan(received, planId) {
|
|
275
|
+
var _a, _b;
|
|
276
|
+
const hasPlan = (_b = (_a = received == null ? void 0 : received.planConnections) == null ? void 0 : _a.some(
|
|
277
|
+
(conn) => conn.planId === planId && conn.active
|
|
278
|
+
)) != null ? _b : false;
|
|
279
|
+
return {
|
|
280
|
+
pass: hasPlan,
|
|
281
|
+
message: () => hasPlan ? `Expected member not to have plan ${planId}` : `Expected member to have plan ${planId}, but they don't`
|
|
282
|
+
};
|
|
283
|
+
},
|
|
284
|
+
/**
|
|
285
|
+
* Assert that a member's email is verified.
|
|
286
|
+
*/
|
|
287
|
+
toBeVerified(received) {
|
|
288
|
+
const pass = (received == null ? void 0 : received.verified) === true;
|
|
289
|
+
return {
|
|
290
|
+
pass,
|
|
291
|
+
message: () => pass ? `Expected member not to be verified` : `Expected member to be verified`
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
};
|
|
295
|
+
export {
|
|
296
|
+
createMockMemberstack,
|
|
297
|
+
memberstackMatchers,
|
|
298
|
+
mockApp,
|
|
299
|
+
mockCard,
|
|
300
|
+
mockContentGroup,
|
|
301
|
+
mockMember,
|
|
302
|
+
mockPlan,
|
|
303
|
+
mockPlanConnection,
|
|
304
|
+
mockPrice
|
|
305
|
+
};
|
package/package.json
CHANGED
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@memberstack/dom",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"main": "./lib/index.js",
|
|
5
5
|
"module": "./lib/index.mjs",
|
|
6
6
|
"types": "./lib/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./lib/index.d.ts",
|
|
10
|
+
"import": "./lib/index.mjs",
|
|
11
|
+
"require": "./lib/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./testing": {
|
|
14
|
+
"types": "./lib/testing/index.d.ts",
|
|
15
|
+
"import": "./lib/testing/index.mjs",
|
|
16
|
+
"require": "./lib/testing/index.js"
|
|
17
|
+
}
|
|
18
|
+
},
|
|
7
19
|
"files": [
|
|
8
20
|
"lib/**/*"
|
|
9
21
|
],
|
|
@@ -11,23 +23,22 @@
|
|
|
11
23
|
"license": "MIT",
|
|
12
24
|
"dependencies": {
|
|
13
25
|
"axios": "1.10.0",
|
|
14
|
-
"jose": "^4.8.1",
|
|
15
26
|
"js-cookie": "^3.0.1"
|
|
16
27
|
},
|
|
17
28
|
"scripts": {
|
|
18
|
-
"dev": "tsup --
|
|
19
|
-
"build": "tsup --
|
|
20
|
-
"prepublishOnly": "
|
|
21
|
-
"prepublishOnly:porter-prod": "
|
|
22
|
-
"prepublishOnly:porter-dev": "
|
|
29
|
+
"dev": "tsup --watch --env.API_ENDPOINT https://client.memberstack.com",
|
|
30
|
+
"build": "tsup --env.API_ENDPOINT https://client.memberstack.com",
|
|
31
|
+
"prepublishOnly": "tsup --env.API_ENDPOINT https://client.memberstack.com",
|
|
32
|
+
"prepublishOnly:porter-prod": "tsup --env.API_ENDPOINT https://client.memberstack.com",
|
|
33
|
+
"prepublishOnly:porter-dev": "tsup --env.API_ENDPOINT https://dev-client.memberstack.com",
|
|
23
34
|
"watch": "tsc-watch",
|
|
24
|
-
"watch:dev": "tsup --
|
|
25
|
-
"watch:dev-ngrok": "tsup --
|
|
26
|
-
"watch:dev-api": "tsup --
|
|
35
|
+
"watch:dev": "tsup --watch --env.API_ENDPOINT http://localhost:3005",
|
|
36
|
+
"watch:dev-ngrok": "tsup --watch --env.API_ENDPOINT https://client-testing.ngrok.io",
|
|
37
|
+
"watch:dev-api": "tsup --watch --env.API_ENDPOINT https://dev-client.memberstack.com",
|
|
27
38
|
"clean": "rm -rf node_modules lib",
|
|
28
39
|
"deploy:latest": "npx np --tag latest --no-tests --any-branch",
|
|
29
40
|
"deploy:next": "npx np --tag next --no-tests --any-branch",
|
|
30
|
-
"build:local": "tsup --
|
|
41
|
+
"build:local": "tsup --env.API_ENDPOINT https://dev-client.memberstack.com"
|
|
31
42
|
},
|
|
32
43
|
"devDependencies": {
|
|
33
44
|
"@types/node": "^20",
|
|
@@ -36,4 +47,4 @@
|
|
|
36
47
|
"tsc-watch": "^6.0.4",
|
|
37
48
|
"tsup": "^7.2.0"
|
|
38
49
|
}
|
|
39
|
-
}
|
|
50
|
+
}
|
package/lib/auth/index.d.mts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
declare const getPersistedMember: () => any;
|
|
2
|
-
declare const setPersistedMember: (member: any) => void;
|
|
3
|
-
declare const updatePersistedMember: (member: any) => void;
|
|
4
|
-
declare const unsetPersistedMember: () => void;
|
|
5
|
-
declare const onAuthChange: (cb: any) => {
|
|
6
|
-
unsubscribe: () => boolean;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export { getPersistedMember, onAuthChange, setPersistedMember, unsetPersistedMember, updatePersistedMember };
|
package/lib/auth/index.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
declare const getPersistedMember: () => any;
|
|
2
|
-
declare const setPersistedMember: (member: any) => void;
|
|
3
|
-
declare const updatePersistedMember: (member: any) => void;
|
|
4
|
-
declare const unsetPersistedMember: () => void;
|
|
5
|
-
declare const onAuthChange: (cb: any) => {
|
|
6
|
-
unsubscribe: () => boolean;
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
export { getPersistedMember, onAuthChange, setPersistedMember, unsetPersistedMember, updatePersistedMember };
|
package/lib/auth/index.global.js
DELETED
|
@@ -1,244 +0,0 @@
|
|
|
1
|
-
var MemberstackDOM = (() => {
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
-
var __spreadValues = (a, b) => {
|
|
10
|
-
for (var prop in b || (b = {}))
|
|
11
|
-
if (__hasOwnProp.call(b, prop))
|
|
12
|
-
__defNormalProp(a, prop, b[prop]);
|
|
13
|
-
if (__getOwnPropSymbols)
|
|
14
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
-
if (__propIsEnum.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
}
|
|
18
|
-
return a;
|
|
19
|
-
};
|
|
20
|
-
var __export = (target, all) => {
|
|
21
|
-
for (var name in all)
|
|
22
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
23
|
-
};
|
|
24
|
-
var __copyProps = (to, from, except, desc) => {
|
|
25
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
26
|
-
for (let key of __getOwnPropNames(from))
|
|
27
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
28
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
29
|
-
}
|
|
30
|
-
return to;
|
|
31
|
-
};
|
|
32
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
33
|
-
|
|
34
|
-
// src/auth/index.ts
|
|
35
|
-
var auth_exports = {};
|
|
36
|
-
__export(auth_exports, {
|
|
37
|
-
getPersistedMember: () => getPersistedMember,
|
|
38
|
-
onAuthChange: () => onAuthChange,
|
|
39
|
-
setPersistedMember: () => setPersistedMember,
|
|
40
|
-
unsetPersistedMember: () => unsetPersistedMember,
|
|
41
|
-
updatePersistedMember: () => updatePersistedMember
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
// ../../node_modules/js-cookie/dist/js.cookie.mjs
|
|
45
|
-
function assign(target) {
|
|
46
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
47
|
-
var source = arguments[i];
|
|
48
|
-
for (var key in source) {
|
|
49
|
-
target[key] = source[key];
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
return target;
|
|
53
|
-
}
|
|
54
|
-
var defaultConverter = {
|
|
55
|
-
read: function(value) {
|
|
56
|
-
if (value[0] === '"') {
|
|
57
|
-
value = value.slice(1, -1);
|
|
58
|
-
}
|
|
59
|
-
return value.replace(/(%[\dA-F]{2})+/gi, decodeURIComponent);
|
|
60
|
-
},
|
|
61
|
-
write: function(value) {
|
|
62
|
-
return encodeURIComponent(value).replace(
|
|
63
|
-
/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,
|
|
64
|
-
decodeURIComponent
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
function init(converter, defaultAttributes) {
|
|
69
|
-
function set(name, value, attributes) {
|
|
70
|
-
if (typeof document === "undefined") {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
attributes = assign({}, defaultAttributes, attributes);
|
|
74
|
-
if (typeof attributes.expires === "number") {
|
|
75
|
-
attributes.expires = new Date(Date.now() + attributes.expires * 864e5);
|
|
76
|
-
}
|
|
77
|
-
if (attributes.expires) {
|
|
78
|
-
attributes.expires = attributes.expires.toUTCString();
|
|
79
|
-
}
|
|
80
|
-
name = encodeURIComponent(name).replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent).replace(/[()]/g, escape);
|
|
81
|
-
var stringifiedAttributes = "";
|
|
82
|
-
for (var attributeName in attributes) {
|
|
83
|
-
if (!attributes[attributeName]) {
|
|
84
|
-
continue;
|
|
85
|
-
}
|
|
86
|
-
stringifiedAttributes += "; " + attributeName;
|
|
87
|
-
if (attributes[attributeName] === true) {
|
|
88
|
-
continue;
|
|
89
|
-
}
|
|
90
|
-
stringifiedAttributes += "=" + attributes[attributeName].split(";")[0];
|
|
91
|
-
}
|
|
92
|
-
return document.cookie = name + "=" + converter.write(value, name) + stringifiedAttributes;
|
|
93
|
-
}
|
|
94
|
-
function get(name) {
|
|
95
|
-
if (typeof document === "undefined" || arguments.length && !name) {
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
var cookies = document.cookie ? document.cookie.split("; ") : [];
|
|
99
|
-
var jar = {};
|
|
100
|
-
for (var i = 0; i < cookies.length; i++) {
|
|
101
|
-
var parts = cookies[i].split("=");
|
|
102
|
-
var value = parts.slice(1).join("=");
|
|
103
|
-
try {
|
|
104
|
-
var found = decodeURIComponent(parts[0]);
|
|
105
|
-
jar[found] = converter.read(value, found);
|
|
106
|
-
if (name === found) {
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
} catch (e) {
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
return name ? jar[name] : jar;
|
|
113
|
-
}
|
|
114
|
-
return Object.create(
|
|
115
|
-
{
|
|
116
|
-
set,
|
|
117
|
-
get,
|
|
118
|
-
remove: function(name, attributes) {
|
|
119
|
-
set(
|
|
120
|
-
name,
|
|
121
|
-
"",
|
|
122
|
-
assign({}, attributes, {
|
|
123
|
-
expires: -1
|
|
124
|
-
})
|
|
125
|
-
);
|
|
126
|
-
},
|
|
127
|
-
withAttributes: function(attributes) {
|
|
128
|
-
return init(this.converter, assign({}, this.attributes, attributes));
|
|
129
|
-
},
|
|
130
|
-
withConverter: function(converter2) {
|
|
131
|
-
return init(assign({}, this.converter, converter2), this.attributes);
|
|
132
|
-
}
|
|
133
|
-
},
|
|
134
|
-
{
|
|
135
|
-
attributes: { value: Object.freeze(defaultAttributes) },
|
|
136
|
-
converter: { value: Object.freeze(converter) }
|
|
137
|
-
}
|
|
138
|
-
);
|
|
139
|
-
}
|
|
140
|
-
var api = init(defaultConverter, { path: "/" });
|
|
141
|
-
|
|
142
|
-
// src/utils/cookies.ts
|
|
143
|
-
var memberAuthTokenName = "_ms-mid";
|
|
144
|
-
function isLocalStorageAvailable() {
|
|
145
|
-
try {
|
|
146
|
-
localStorage.setItem("test", "test");
|
|
147
|
-
localStorage.removeItem("test");
|
|
148
|
-
return true;
|
|
149
|
-
} catch (e) {
|
|
150
|
-
return false;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
var localStorageAvailable = isLocalStorageAvailable();
|
|
154
|
-
var setCookieOnRootDomain = false;
|
|
155
|
-
var extractDomainFromHostname = (hostname) => {
|
|
156
|
-
const hostnameParts = hostname.split(".");
|
|
157
|
-
const isCountryCodeTLD = hostnameParts.length >= 3 && hostnameParts[hostnameParts.length - 2].length <= 3;
|
|
158
|
-
if (isCountryCodeTLD) {
|
|
159
|
-
return hostnameParts.slice(-3).join(".");
|
|
160
|
-
} else {
|
|
161
|
-
return hostnameParts.slice(-2).join(".");
|
|
162
|
-
}
|
|
163
|
-
};
|
|
164
|
-
var removeMemberToken = () => {
|
|
165
|
-
if (localStorageAvailable) {
|
|
166
|
-
localStorage.removeItem(memberAuthTokenName);
|
|
167
|
-
}
|
|
168
|
-
const domain = extractDomainFromHostname(window.location.hostname);
|
|
169
|
-
api.set(memberAuthTokenName, "", __spreadValues({
|
|
170
|
-
expires: -1,
|
|
171
|
-
sameSite: "strict"
|
|
172
|
-
}, setCookieOnRootDomain && { domain }));
|
|
173
|
-
api.set(memberAuthTokenName, "", {
|
|
174
|
-
expires: -1,
|
|
175
|
-
sameSite: "strict"
|
|
176
|
-
});
|
|
177
|
-
};
|
|
178
|
-
var removeSessionId = () => {
|
|
179
|
-
if (typeof window !== "undefined") {
|
|
180
|
-
window.localStorage.removeItem("ms_session_id");
|
|
181
|
-
} else {
|
|
182
|
-
console.warn("removeSessionId: window is not defined");
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
// src/auth/index.ts
|
|
187
|
-
var createObservable = () => {
|
|
188
|
-
const observer = /* @__PURE__ */ new Map();
|
|
189
|
-
return {
|
|
190
|
-
subscribe: (key, fn) => {
|
|
191
|
-
if (typeof fn !== "function")
|
|
192
|
-
return;
|
|
193
|
-
return observer.set(key, fn);
|
|
194
|
-
},
|
|
195
|
-
unsubscribe: (key) => {
|
|
196
|
-
return observer.delete(key);
|
|
197
|
-
},
|
|
198
|
-
notify: (data) => {
|
|
199
|
-
return [...observer.values()].forEach((fn) => fn(data));
|
|
200
|
-
}
|
|
201
|
-
};
|
|
202
|
-
};
|
|
203
|
-
var observable = createObservable();
|
|
204
|
-
var getPersistedMember = () => {
|
|
205
|
-
return JSON.parse(localStorage == null ? void 0 : localStorage.getItem("_ms-mem"));
|
|
206
|
-
};
|
|
207
|
-
var setPersistedMember = (member) => {
|
|
208
|
-
if (member) {
|
|
209
|
-
const data = JSON.stringify(member);
|
|
210
|
-
if (data)
|
|
211
|
-
localStorage == null ? void 0 : localStorage.setItem("_ms-mem", data);
|
|
212
|
-
observable.notify(member);
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
var updatePersistedMember = (member) => {
|
|
216
|
-
if (member) {
|
|
217
|
-
const data = JSON.stringify(member);
|
|
218
|
-
if (data)
|
|
219
|
-
localStorage == null ? void 0 : localStorage.setItem("_ms-mem", data);
|
|
220
|
-
} else {
|
|
221
|
-
localStorage == null ? void 0 : localStorage.removeItem("_ms-mem");
|
|
222
|
-
removeMemberToken();
|
|
223
|
-
}
|
|
224
|
-
};
|
|
225
|
-
var unsetPersistedMember = () => {
|
|
226
|
-
localStorage == null ? void 0 : localStorage.removeItem("_ms-mem");
|
|
227
|
-
removeMemberToken();
|
|
228
|
-
removeSessionId();
|
|
229
|
-
observable.notify(null);
|
|
230
|
-
};
|
|
231
|
-
var onAuthChange = (cb) => {
|
|
232
|
-
const id = Math.floor(Math.random() * 1e3);
|
|
233
|
-
observable.subscribe(id, cb);
|
|
234
|
-
return {
|
|
235
|
-
unsubscribe: () => observable.unsubscribe(id)
|
|
236
|
-
};
|
|
237
|
-
};
|
|
238
|
-
return __toCommonJS(auth_exports);
|
|
239
|
-
})();
|
|
240
|
-
/*! Bundled license information:
|
|
241
|
-
|
|
242
|
-
js-cookie/dist/js.cookie.mjs:
|
|
243
|
-
(*! js-cookie v3.0.5 | MIT *)
|
|
244
|
-
*/
|