@memberstack/dom 2.0.0 → 2.0.2-beta.0
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/auth/index.d.mts +58 -4
- package/lib/auth/index.d.ts +58 -4
- package/lib/auth/index.js +5 -2
- package/lib/auth/index.mjs +4 -2
- package/lib/constants/endpoints.js +2 -1
- package/lib/constants/endpoints.mjs +1 -1
- package/lib/index.d.mts +1874 -61
- package/lib/index.d.ts +1874 -61
- package/lib/index.js +1548 -30626
- package/lib/index.mjs +1534 -30626
- package/lib/methods/dom/index.js +1 -0
- package/lib/methods/dom/main-dom.d.mts +1 -13
- package/lib/methods/dom/main-dom.d.ts +1 -13
- package/lib/methods/dom/main-dom.js +14545 -29552
- package/lib/methods/dom/main-dom.mjs +14544 -29552
- package/lib/methods/dom/methods.d.mts +88 -6
- package/lib/methods/dom/methods.d.ts +88 -6
- package/lib/methods/dom/methods.js +137 -30637
- package/lib/methods/dom/methods.mjs +135 -30639
- package/lib/methods/index.d.mts +111 -29
- package/lib/methods/index.d.ts +111 -29
- package/lib/methods/index.js +1024 -30617
- package/lib/methods/index.mjs +1023 -30617
- package/lib/methods/requests/index.d.mts +843 -23
- package/lib/methods/requests/index.d.ts +843 -23
- package/lib/methods/requests/index.js +867 -42
- package/lib/methods/requests/index.mjs +866 -42
- package/lib/methods/requests/requests.d.mts +9 -8
- package/lib/methods/requests/requests.d.ts +9 -8
- package/lib/methods/requests/requests.js +5 -3
- package/lib/methods/requests/requests.mjs +4 -3
- package/lib/models-BmZS-mc4.d.ts +193 -0
- package/lib/models-CTRKogoR.d.ts +487 -0
- package/lib/models-le7xaT4H.d.ts +193 -0
- package/lib/testing/index.d.mts +272 -0
- package/lib/testing/index.d.ts +272 -0
- package/lib/testing/index.js +313 -0
- package/lib/testing/index.mjs +284 -0
- package/lib/types/index.d.mts +1 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/index.js +1 -0
- package/lib/types/params.d.mts +634 -10
- package/lib/types/params.d.ts +634 -10
- package/lib/types/params.js +1 -0
- package/lib/types/payloads.d.mts +200 -1
- package/lib/types/payloads.d.ts +200 -1
- package/lib/types/payloads.js +1 -0
- package/lib/types/translations.d.mts +58 -0
- package/lib/types/translations.d.ts +58 -0
- package/lib/types/translations.js +1 -0
- package/lib/types/utils/payloads.d.mts +1 -3
- package/lib/types/utils/payloads.d.ts +1 -3
- package/lib/types/utils/payloads.js +1 -0
- package/lib/utils/cookies.d.mts +5 -5
- package/lib/utils/cookies.d.ts +5 -5
- package/lib/utils/cookies.js +14 -3
- package/lib/utils/cookies.mjs +13 -3
- package/lib/utils/defaultMessageBox.js +1 -0
- package/package.json +23 -12
- package/lib/index.global.js +0 -46364
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
"use strict";
|
|
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 __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __spreadValues = (a, b) => {
|
|
12
|
+
for (var prop in b || (b = {}))
|
|
13
|
+
if (__hasOwnProp.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
15
|
+
if (__getOwnPropSymbols)
|
|
16
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
17
|
+
if (__propIsEnum.call(b, prop))
|
|
18
|
+
__defNormalProp(a, prop, b[prop]);
|
|
19
|
+
}
|
|
20
|
+
return a;
|
|
21
|
+
};
|
|
22
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
23
|
+
var __export = (target, all) => {
|
|
24
|
+
for (var name in all)
|
|
25
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
26
|
+
};
|
|
27
|
+
var __copyProps = (to, from, except, desc) => {
|
|
28
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
29
|
+
for (let key of __getOwnPropNames(from))
|
|
30
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
31
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
32
|
+
}
|
|
33
|
+
return to;
|
|
34
|
+
};
|
|
35
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
36
|
+
var __async = (__this, __arguments, generator) => {
|
|
37
|
+
return new Promise((resolve, reject) => {
|
|
38
|
+
var fulfilled = (value) => {
|
|
39
|
+
try {
|
|
40
|
+
step(generator.next(value));
|
|
41
|
+
} catch (e) {
|
|
42
|
+
reject(e);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
var rejected = (value) => {
|
|
46
|
+
try {
|
|
47
|
+
step(generator.throw(value));
|
|
48
|
+
} catch (e) {
|
|
49
|
+
reject(e);
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
53
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
// src/testing/index.ts
|
|
58
|
+
var testing_exports = {};
|
|
59
|
+
__export(testing_exports, {
|
|
60
|
+
createMockMemberstack: () => createMockMemberstack,
|
|
61
|
+
memberstackMatchers: () => memberstackMatchers,
|
|
62
|
+
mockApp: () => mockApp,
|
|
63
|
+
mockCard: () => mockCard,
|
|
64
|
+
mockContentGroup: () => mockContentGroup,
|
|
65
|
+
mockMember: () => mockMember,
|
|
66
|
+
mockPlan: () => mockPlan,
|
|
67
|
+
mockPlanConnection: () => mockPlanConnection
|
|
68
|
+
});
|
|
69
|
+
module.exports = __toCommonJS(testing_exports);
|
|
70
|
+
function mockMember(overrides = {}) {
|
|
71
|
+
const defaults = {
|
|
72
|
+
id: `mem_${randomId()}`,
|
|
73
|
+
verified: true,
|
|
74
|
+
profileImage: "",
|
|
75
|
+
auth: {
|
|
76
|
+
email: "test@example.com",
|
|
77
|
+
hasPassword: true,
|
|
78
|
+
providers: []
|
|
79
|
+
},
|
|
80
|
+
loginRedirect: "/",
|
|
81
|
+
stripeCustomerId: "",
|
|
82
|
+
createdAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
83
|
+
metaData: {},
|
|
84
|
+
customFields: {},
|
|
85
|
+
permissions: [],
|
|
86
|
+
planConnections: []
|
|
87
|
+
};
|
|
88
|
+
return deepMerge(defaults, overrides);
|
|
89
|
+
}
|
|
90
|
+
function mockPlan(overrides = {}) {
|
|
91
|
+
const defaults = {
|
|
92
|
+
id: `pln_${randomId()}`,
|
|
93
|
+
name: "Test Plan",
|
|
94
|
+
description: "A test plan",
|
|
95
|
+
status: "PUBLISHED",
|
|
96
|
+
redirects: {
|
|
97
|
+
afterLogin: "/",
|
|
98
|
+
afterLogout: "/",
|
|
99
|
+
afterSignup: "/"
|
|
100
|
+
},
|
|
101
|
+
prices: []
|
|
102
|
+
};
|
|
103
|
+
return deepMerge(defaults, overrides);
|
|
104
|
+
}
|
|
105
|
+
function mockPlanConnection(overrides = {}) {
|
|
106
|
+
const defaults = {
|
|
107
|
+
id: `conn_${randomId()}`,
|
|
108
|
+
active: true,
|
|
109
|
+
status: "ACTIVE",
|
|
110
|
+
planId: `pln_${randomId()}`,
|
|
111
|
+
type: "FREE",
|
|
112
|
+
payment: null
|
|
113
|
+
};
|
|
114
|
+
return deepMerge(defaults, overrides);
|
|
115
|
+
}
|
|
116
|
+
function mockCard(overrides = {}) {
|
|
117
|
+
const defaults = {
|
|
118
|
+
id: `card_${randomId()}`,
|
|
119
|
+
brand: "visa",
|
|
120
|
+
expMonth: "12",
|
|
121
|
+
expYear: "2025",
|
|
122
|
+
last4: "4242",
|
|
123
|
+
default: true
|
|
124
|
+
};
|
|
125
|
+
return deepMerge(defaults, overrides);
|
|
126
|
+
}
|
|
127
|
+
function mockApp(overrides = {}) {
|
|
128
|
+
const defaults = {
|
|
129
|
+
id: `app_${randomId()}`,
|
|
130
|
+
name: "Test App",
|
|
131
|
+
mode: "sandbox",
|
|
132
|
+
plans: [],
|
|
133
|
+
contentGroups: [],
|
|
134
|
+
emailVerificationEnabled: false,
|
|
135
|
+
requireEmailVerification: false,
|
|
136
|
+
customField: [],
|
|
137
|
+
branding: {
|
|
138
|
+
logo: "",
|
|
139
|
+
colors: {
|
|
140
|
+
lightMode: {
|
|
141
|
+
primaryButton: "#6366f1"
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
authProviders: []
|
|
146
|
+
};
|
|
147
|
+
return deepMerge(defaults, overrides);
|
|
148
|
+
}
|
|
149
|
+
function mockContentGroup(overrides = {}) {
|
|
150
|
+
const defaults = {
|
|
151
|
+
id: `grp_${randomId()}`,
|
|
152
|
+
name: "Test Group",
|
|
153
|
+
key: "test-group",
|
|
154
|
+
allowAllMembers: false,
|
|
155
|
+
activeMemberHasAccess: false,
|
|
156
|
+
redirect: "/login",
|
|
157
|
+
urls: [],
|
|
158
|
+
plans: []
|
|
159
|
+
};
|
|
160
|
+
return deepMerge(defaults, overrides);
|
|
161
|
+
}
|
|
162
|
+
function createMockMemberstack(options = {}) {
|
|
163
|
+
var _a, _b, _c, _d, _e;
|
|
164
|
+
let currentMember = (_a = options.member) != null ? _a : null;
|
|
165
|
+
const plans = (_b = options.plans) != null ? _b : [];
|
|
166
|
+
const app = (_c = options.app) != null ? _c : mockApp();
|
|
167
|
+
const contentGroups = (_d = options.contentGroups) != null ? _d : [];
|
|
168
|
+
const cards = (_e = options.cards) != null ? _e : [];
|
|
169
|
+
const authListeners = [];
|
|
170
|
+
const notifyAuthChange = () => {
|
|
171
|
+
authListeners.forEach((cb) => cb({ member: currentMember }));
|
|
172
|
+
};
|
|
173
|
+
const instance = {
|
|
174
|
+
getCurrentMember: () => __async(this, null, function* () {
|
|
175
|
+
return { data: currentMember };
|
|
176
|
+
}),
|
|
177
|
+
getPlans: () => __async(this, null, function* () {
|
|
178
|
+
return { data: plans };
|
|
179
|
+
}),
|
|
180
|
+
getPlan: (_0) => __async(this, [_0], function* ({ planId }) {
|
|
181
|
+
var _a2;
|
|
182
|
+
return {
|
|
183
|
+
data: (_a2 = plans.find((p) => p.id === planId)) != null ? _a2 : null
|
|
184
|
+
};
|
|
185
|
+
}),
|
|
186
|
+
getApp: () => __async(this, null, function* () {
|
|
187
|
+
return { data: app };
|
|
188
|
+
}),
|
|
189
|
+
getRestrictedUrlGroups: () => __async(this, null, function* () {
|
|
190
|
+
return { data: contentGroups };
|
|
191
|
+
}),
|
|
192
|
+
getMemberCards: () => __async(this, null, function* () {
|
|
193
|
+
return { data: cards };
|
|
194
|
+
}),
|
|
195
|
+
loginMemberEmailPassword: (_0) => __async(this, [_0], function* ({ email }) {
|
|
196
|
+
currentMember = mockMember({ auth: { email, hasPassword: true, providers: [] } });
|
|
197
|
+
notifyAuthChange();
|
|
198
|
+
return {
|
|
199
|
+
data: {
|
|
200
|
+
member: currentMember,
|
|
201
|
+
tokens: { accessToken: `mock_token_${randomId()}` }
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
}),
|
|
205
|
+
signupMemberEmailPassword: (_0) => __async(this, [_0], function* ({ email }) {
|
|
206
|
+
currentMember = mockMember({ auth: { email, hasPassword: true, providers: [] } });
|
|
207
|
+
notifyAuthChange();
|
|
208
|
+
return {
|
|
209
|
+
data: {
|
|
210
|
+
member: currentMember,
|
|
211
|
+
tokens: { accessToken: `mock_token_${randomId()}` }
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
}),
|
|
215
|
+
logout: () => __async(this, null, function* () {
|
|
216
|
+
currentMember = null;
|
|
217
|
+
notifyAuthChange();
|
|
218
|
+
return { data: {} };
|
|
219
|
+
}),
|
|
220
|
+
updateMember: (_0) => __async(this, [_0], function* ({ customFields }) {
|
|
221
|
+
if (currentMember && customFields) {
|
|
222
|
+
currentMember = __spreadProps(__spreadValues({}, currentMember), {
|
|
223
|
+
customFields: __spreadValues(__spreadValues({}, currentMember.customFields), customFields)
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
return { data: currentMember };
|
|
227
|
+
}),
|
|
228
|
+
onAuthChange: (callback) => {
|
|
229
|
+
authListeners.push(callback);
|
|
230
|
+
callback({ member: currentMember });
|
|
231
|
+
return () => {
|
|
232
|
+
const index = authListeners.indexOf(callback);
|
|
233
|
+
if (index > -1)
|
|
234
|
+
authListeners.splice(index, 1);
|
|
235
|
+
};
|
|
236
|
+
},
|
|
237
|
+
// Test helpers
|
|
238
|
+
_setMember: (member) => {
|
|
239
|
+
currentMember = member;
|
|
240
|
+
notifyAuthChange();
|
|
241
|
+
},
|
|
242
|
+
_getMockState: () => ({ member: currentMember, plans, app })
|
|
243
|
+
};
|
|
244
|
+
if (options.overrides) {
|
|
245
|
+
Object.assign(instance, options.overrides);
|
|
246
|
+
}
|
|
247
|
+
return instance;
|
|
248
|
+
}
|
|
249
|
+
function randomId() {
|
|
250
|
+
return Math.random().toString(36).substring(2, 10);
|
|
251
|
+
}
|
|
252
|
+
function deepMerge(target, source) {
|
|
253
|
+
const result = __spreadValues({}, target);
|
|
254
|
+
for (const key in source) {
|
|
255
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
256
|
+
const sourceValue = source[key];
|
|
257
|
+
const targetValue = result[key];
|
|
258
|
+
if (sourceValue !== void 0 && typeof sourceValue === "object" && sourceValue !== null && !Array.isArray(sourceValue) && typeof targetValue === "object" && targetValue !== null && !Array.isArray(targetValue)) {
|
|
259
|
+
result[key] = deepMerge(targetValue, sourceValue);
|
|
260
|
+
} else if (sourceValue !== void 0) {
|
|
261
|
+
result[key] = sourceValue;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return result;
|
|
266
|
+
}
|
|
267
|
+
var memberstackMatchers = {
|
|
268
|
+
/**
|
|
269
|
+
* Assert that a member is logged in (not null and has an email).
|
|
270
|
+
*/
|
|
271
|
+
toBeLoggedIn(received) {
|
|
272
|
+
var _a;
|
|
273
|
+
const pass = received !== null && typeof ((_a = received.auth) == null ? void 0 : _a.email) === "string";
|
|
274
|
+
return {
|
|
275
|
+
pass,
|
|
276
|
+
message: () => pass ? `Expected member not to be logged in` : `Expected member to be logged in, but got ${received === null ? "null" : "invalid member object"}`
|
|
277
|
+
};
|
|
278
|
+
},
|
|
279
|
+
/**
|
|
280
|
+
* Assert that a member has a specific plan.
|
|
281
|
+
*/
|
|
282
|
+
toHavePlan(received, planId) {
|
|
283
|
+
var _a, _b;
|
|
284
|
+
const hasPlan = (_b = (_a = received == null ? void 0 : received.planConnections) == null ? void 0 : _a.some(
|
|
285
|
+
(conn) => conn.planId === planId && conn.active
|
|
286
|
+
)) != null ? _b : false;
|
|
287
|
+
return {
|
|
288
|
+
pass: hasPlan,
|
|
289
|
+
message: () => hasPlan ? `Expected member not to have plan ${planId}` : `Expected member to have plan ${planId}, but they don't`
|
|
290
|
+
};
|
|
291
|
+
},
|
|
292
|
+
/**
|
|
293
|
+
* Assert that a member's email is verified.
|
|
294
|
+
*/
|
|
295
|
+
toBeVerified(received) {
|
|
296
|
+
const pass = (received == null ? void 0 : received.verified) === true;
|
|
297
|
+
return {
|
|
298
|
+
pass,
|
|
299
|
+
message: () => pass ? `Expected member not to be verified` : `Expected member to be verified`
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
304
|
+
0 && (module.exports = {
|
|
305
|
+
createMockMemberstack,
|
|
306
|
+
memberstackMatchers,
|
|
307
|
+
mockApp,
|
|
308
|
+
mockCard,
|
|
309
|
+
mockContentGroup,
|
|
310
|
+
mockMember,
|
|
311
|
+
mockPlan,
|
|
312
|
+
mockPlanConnection
|
|
313
|
+
});
|
|
@@ -0,0 +1,284 @@
|
|
|
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: "2025",
|
|
94
|
+
last4: "4242",
|
|
95
|
+
default: true
|
|
96
|
+
};
|
|
97
|
+
return deepMerge(defaults, overrides);
|
|
98
|
+
}
|
|
99
|
+
function mockApp(overrides = {}) {
|
|
100
|
+
const defaults = {
|
|
101
|
+
id: `app_${randomId()}`,
|
|
102
|
+
name: "Test App",
|
|
103
|
+
mode: "sandbox",
|
|
104
|
+
plans: [],
|
|
105
|
+
contentGroups: [],
|
|
106
|
+
emailVerificationEnabled: false,
|
|
107
|
+
requireEmailVerification: false,
|
|
108
|
+
customField: [],
|
|
109
|
+
branding: {
|
|
110
|
+
logo: "",
|
|
111
|
+
colors: {
|
|
112
|
+
lightMode: {
|
|
113
|
+
primaryButton: "#6366f1"
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
authProviders: []
|
|
118
|
+
};
|
|
119
|
+
return deepMerge(defaults, overrides);
|
|
120
|
+
}
|
|
121
|
+
function mockContentGroup(overrides = {}) {
|
|
122
|
+
const defaults = {
|
|
123
|
+
id: `grp_${randomId()}`,
|
|
124
|
+
name: "Test Group",
|
|
125
|
+
key: "test-group",
|
|
126
|
+
allowAllMembers: false,
|
|
127
|
+
activeMemberHasAccess: false,
|
|
128
|
+
redirect: "/login",
|
|
129
|
+
urls: [],
|
|
130
|
+
plans: []
|
|
131
|
+
};
|
|
132
|
+
return deepMerge(defaults, overrides);
|
|
133
|
+
}
|
|
134
|
+
function createMockMemberstack(options = {}) {
|
|
135
|
+
var _a, _b, _c, _d, _e;
|
|
136
|
+
let currentMember = (_a = options.member) != null ? _a : null;
|
|
137
|
+
const plans = (_b = options.plans) != null ? _b : [];
|
|
138
|
+
const app = (_c = options.app) != null ? _c : mockApp();
|
|
139
|
+
const contentGroups = (_d = options.contentGroups) != null ? _d : [];
|
|
140
|
+
const cards = (_e = options.cards) != null ? _e : [];
|
|
141
|
+
const authListeners = [];
|
|
142
|
+
const notifyAuthChange = () => {
|
|
143
|
+
authListeners.forEach((cb) => cb({ member: currentMember }));
|
|
144
|
+
};
|
|
145
|
+
const instance = {
|
|
146
|
+
getCurrentMember: () => __async(this, null, function* () {
|
|
147
|
+
return { data: currentMember };
|
|
148
|
+
}),
|
|
149
|
+
getPlans: () => __async(this, null, function* () {
|
|
150
|
+
return { data: plans };
|
|
151
|
+
}),
|
|
152
|
+
getPlan: (_0) => __async(this, [_0], function* ({ planId }) {
|
|
153
|
+
var _a2;
|
|
154
|
+
return {
|
|
155
|
+
data: (_a2 = plans.find((p) => p.id === planId)) != null ? _a2 : null
|
|
156
|
+
};
|
|
157
|
+
}),
|
|
158
|
+
getApp: () => __async(this, null, function* () {
|
|
159
|
+
return { data: app };
|
|
160
|
+
}),
|
|
161
|
+
getRestrictedUrlGroups: () => __async(this, null, function* () {
|
|
162
|
+
return { data: contentGroups };
|
|
163
|
+
}),
|
|
164
|
+
getMemberCards: () => __async(this, null, function* () {
|
|
165
|
+
return { data: cards };
|
|
166
|
+
}),
|
|
167
|
+
loginMemberEmailPassword: (_0) => __async(this, [_0], function* ({ email }) {
|
|
168
|
+
currentMember = mockMember({ auth: { email, hasPassword: true, providers: [] } });
|
|
169
|
+
notifyAuthChange();
|
|
170
|
+
return {
|
|
171
|
+
data: {
|
|
172
|
+
member: currentMember,
|
|
173
|
+
tokens: { accessToken: `mock_token_${randomId()}` }
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
}),
|
|
177
|
+
signupMemberEmailPassword: (_0) => __async(this, [_0], function* ({ email }) {
|
|
178
|
+
currentMember = mockMember({ auth: { email, hasPassword: true, providers: [] } });
|
|
179
|
+
notifyAuthChange();
|
|
180
|
+
return {
|
|
181
|
+
data: {
|
|
182
|
+
member: currentMember,
|
|
183
|
+
tokens: { accessToken: `mock_token_${randomId()}` }
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
}),
|
|
187
|
+
logout: () => __async(this, null, function* () {
|
|
188
|
+
currentMember = null;
|
|
189
|
+
notifyAuthChange();
|
|
190
|
+
return { data: {} };
|
|
191
|
+
}),
|
|
192
|
+
updateMember: (_0) => __async(this, [_0], function* ({ customFields }) {
|
|
193
|
+
if (currentMember && customFields) {
|
|
194
|
+
currentMember = __spreadProps(__spreadValues({}, currentMember), {
|
|
195
|
+
customFields: __spreadValues(__spreadValues({}, currentMember.customFields), customFields)
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
return { data: currentMember };
|
|
199
|
+
}),
|
|
200
|
+
onAuthChange: (callback) => {
|
|
201
|
+
authListeners.push(callback);
|
|
202
|
+
callback({ member: currentMember });
|
|
203
|
+
return () => {
|
|
204
|
+
const index = authListeners.indexOf(callback);
|
|
205
|
+
if (index > -1)
|
|
206
|
+
authListeners.splice(index, 1);
|
|
207
|
+
};
|
|
208
|
+
},
|
|
209
|
+
// Test helpers
|
|
210
|
+
_setMember: (member) => {
|
|
211
|
+
currentMember = member;
|
|
212
|
+
notifyAuthChange();
|
|
213
|
+
},
|
|
214
|
+
_getMockState: () => ({ member: currentMember, plans, app })
|
|
215
|
+
};
|
|
216
|
+
if (options.overrides) {
|
|
217
|
+
Object.assign(instance, options.overrides);
|
|
218
|
+
}
|
|
219
|
+
return instance;
|
|
220
|
+
}
|
|
221
|
+
function randomId() {
|
|
222
|
+
return Math.random().toString(36).substring(2, 10);
|
|
223
|
+
}
|
|
224
|
+
function deepMerge(target, source) {
|
|
225
|
+
const result = __spreadValues({}, target);
|
|
226
|
+
for (const key in source) {
|
|
227
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
228
|
+
const sourceValue = source[key];
|
|
229
|
+
const targetValue = result[key];
|
|
230
|
+
if (sourceValue !== void 0 && typeof sourceValue === "object" && sourceValue !== null && !Array.isArray(sourceValue) && typeof targetValue === "object" && targetValue !== null && !Array.isArray(targetValue)) {
|
|
231
|
+
result[key] = deepMerge(targetValue, sourceValue);
|
|
232
|
+
} else if (sourceValue !== void 0) {
|
|
233
|
+
result[key] = sourceValue;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return result;
|
|
238
|
+
}
|
|
239
|
+
var memberstackMatchers = {
|
|
240
|
+
/**
|
|
241
|
+
* Assert that a member is logged in (not null and has an email).
|
|
242
|
+
*/
|
|
243
|
+
toBeLoggedIn(received) {
|
|
244
|
+
var _a;
|
|
245
|
+
const pass = received !== null && typeof ((_a = received.auth) == null ? void 0 : _a.email) === "string";
|
|
246
|
+
return {
|
|
247
|
+
pass,
|
|
248
|
+
message: () => pass ? `Expected member not to be logged in` : `Expected member to be logged in, but got ${received === null ? "null" : "invalid member object"}`
|
|
249
|
+
};
|
|
250
|
+
},
|
|
251
|
+
/**
|
|
252
|
+
* Assert that a member has a specific plan.
|
|
253
|
+
*/
|
|
254
|
+
toHavePlan(received, planId) {
|
|
255
|
+
var _a, _b;
|
|
256
|
+
const hasPlan = (_b = (_a = received == null ? void 0 : received.planConnections) == null ? void 0 : _a.some(
|
|
257
|
+
(conn) => conn.planId === planId && conn.active
|
|
258
|
+
)) != null ? _b : false;
|
|
259
|
+
return {
|
|
260
|
+
pass: hasPlan,
|
|
261
|
+
message: () => hasPlan ? `Expected member not to have plan ${planId}` : `Expected member to have plan ${planId}, but they don't`
|
|
262
|
+
};
|
|
263
|
+
},
|
|
264
|
+
/**
|
|
265
|
+
* Assert that a member's email is verified.
|
|
266
|
+
*/
|
|
267
|
+
toBeVerified(received) {
|
|
268
|
+
const pass = (received == null ? void 0 : received.verified) === true;
|
|
269
|
+
return {
|
|
270
|
+
pass,
|
|
271
|
+
message: () => pass ? `Expected member not to be verified` : `Expected member to be verified`
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
export {
|
|
276
|
+
createMockMemberstack,
|
|
277
|
+
memberstackMatchers,
|
|
278
|
+
mockApp,
|
|
279
|
+
mockCard,
|
|
280
|
+
mockContentGroup,
|
|
281
|
+
mockMember,
|
|
282
|
+
mockPlan,
|
|
283
|
+
mockPlanConnection
|
|
284
|
+
};
|
package/lib/types/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { AddMemberCardParams, AddPlanParams, CancelPlanParams, CountClause, CreateDataRecordParams, CreatePostParams, CreateThreadParams, DataRecordsQuery, DeleteDataRecordParams, DeletePostParams, DeleteThreadParams, GenerateInviteTokenParams, GetAuthenticationClientSecretParams, GetDataRecordParams, GetDataRecordsParams, GetDataTableParams, GetMemberInvoicesParams, GetMemberPurchasesParams, GetMemberReceiptsParams, GetPlanParams, GetPlansParams, GetPostsParams, GetSecureContentParams, GetTeamParams, GetThreadsParams, GetTotalCheckoutAmountParams, IncludeClause, JoinTeamParams, LaunchStripeCustomerPortalParams, LoginMemberEmailPasswordParams, LoginMemberPasswordlessParams, LoginWithProviderParams, MemberReferenceOperation, MemberReferenceSelector, OpenStripeCustomerPortalParams, OrderByClause, PostVoteParams, PurchasePlansParams, PurchasePlansWithCheckoutParams, QueryDataRecordsParams, ReferenceOperation, ReferenceSelector, RemoveMemberFromTeamParams, RemovePlanParams, ReplacePlanParams, ResetMemberPasswordParams, SelectClause, SendMemberLoginPasswordlessEmailParams, SendMemberResetPasswordEmailParams, SetPasswordParams, SignupMemberAuthProviderParams, SignupMemberEmailPasswordParams, SignupWithProviderParams, ThreadVoteParams, UpdateDataRecordParams, UpdateDefaultCardParams, UpdateMemberAuthParams, UpdateMemberJSONParams, UpdateMemberParams, UpdateMemberProfileImageParams, UpdatePlanPaymentParams, UpdatePostParams, UpdateThreadParams, WhereClause, WhereOperators } from './params.mjs';
|
|
2
2
|
export { AddMemberCardPayload, AddPlanPayload, AppPayload, CancelPlanPayload, ConnectProviderPayload, CreateDataRecordPayload, CreatePostPayload, CreateThreadPayload, DeleteDataRecordPayload, DeleteMemberPayload, GetAppAndMemberPayload, GetAuthProvidersPayload, GetAuthenticationClientSecretPayload, GetCurrentMemberPayload, GetDataRecordPayload, GetDataRecordsPayload, GetDataTablePayload, GetDataTablesPayload, GetMemberCardsPayload, GetMemberInvoicesPayload, GetMemberJSONPayload, GetMemberReceiptsPayload, GetPlanPayload, GetPlansPayload, GetPostsPayload, GetRestrictedUrlGroupsPayload, GetSecureContentPayload, GetThreadsPayload, GetTotalCheckoutAmountPayload, LaunchStripeCustomerPortalPayload, LoginMemberEmailPasswordPayload, LogoutMemberPayload, MemberReferenceFieldResult, OpenStripeCustomerPortalPayload, PurchasePlansPayload, PurchasePlansWithCheckoutPayload, QueryDataRecordsPayload, ReferenceFieldResult, RefreshMemberTokensPayload, RemovePlanPayload, ReplacePlanPayload, ResetMemberPassworPayload, SendMemberLoginPasswordlessEmailPayload, SendMemberResetPasswordEmailPayload, SendMemberVerificationEmailPayload, SetPasswordPayload, SignupMemberAuthProviderPayload, SignupMemberEmailPasswordPayload, UpdateDataRecordPayload, UpdateDefaultCardPayload, UpdateMemberAuthPayload, UpdateMemberPayload, UpdateMemberProfileImagePayload, UpdatePlanPaymentPayload, UpdatePostPayload, UpdateThreadPayload } from './payloads.mjs';
|
|
3
3
|
export { MemberstackTranslations } from './translations.mjs';
|
|
4
|
+
export { A as App, c as AuthProvider, e as AuthTokens, B as Branding, i as CheckoutTotal, C as ContentGroup, j as CustomField, E as ExtractData, M as Member, d as MemberAuth, f as MemberCard, m as MemberDisplayInfo, g as MemberInvoice, h as MemberReceipt, l as PaginatedData, P as Plan, b as PlanConnection, k as Post, a as Price, S as SecureContent, T as Thread } from '../models-le7xaT4H.js';
|
|
4
5
|
import './utils/payloads.mjs';
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { AddMemberCardParams, AddPlanParams, CancelPlanParams, CountClause, CreateDataRecordParams, CreatePostParams, CreateThreadParams, DataRecordsQuery, DeleteDataRecordParams, DeletePostParams, DeleteThreadParams, GenerateInviteTokenParams, GetAuthenticationClientSecretParams, GetDataRecordParams, GetDataRecordsParams, GetDataTableParams, GetMemberInvoicesParams, GetMemberPurchasesParams, GetMemberReceiptsParams, GetPlanParams, GetPlansParams, GetPostsParams, GetSecureContentParams, GetTeamParams, GetThreadsParams, GetTotalCheckoutAmountParams, IncludeClause, JoinTeamParams, LaunchStripeCustomerPortalParams, LoginMemberEmailPasswordParams, LoginMemberPasswordlessParams, LoginWithProviderParams, MemberReferenceOperation, MemberReferenceSelector, OpenStripeCustomerPortalParams, OrderByClause, PostVoteParams, PurchasePlansParams, PurchasePlansWithCheckoutParams, QueryDataRecordsParams, ReferenceOperation, ReferenceSelector, RemoveMemberFromTeamParams, RemovePlanParams, ReplacePlanParams, ResetMemberPasswordParams, SelectClause, SendMemberLoginPasswordlessEmailParams, SendMemberResetPasswordEmailParams, SetPasswordParams, SignupMemberAuthProviderParams, SignupMemberEmailPasswordParams, SignupWithProviderParams, ThreadVoteParams, UpdateDataRecordParams, UpdateDefaultCardParams, UpdateMemberAuthParams, UpdateMemberJSONParams, UpdateMemberParams, UpdateMemberProfileImageParams, UpdatePlanPaymentParams, UpdatePostParams, UpdateThreadParams, WhereClause, WhereOperators } from './params.js';
|
|
2
2
|
export { AddMemberCardPayload, AddPlanPayload, AppPayload, CancelPlanPayload, ConnectProviderPayload, CreateDataRecordPayload, CreatePostPayload, CreateThreadPayload, DeleteDataRecordPayload, DeleteMemberPayload, GetAppAndMemberPayload, GetAuthProvidersPayload, GetAuthenticationClientSecretPayload, GetCurrentMemberPayload, GetDataRecordPayload, GetDataRecordsPayload, GetDataTablePayload, GetDataTablesPayload, GetMemberCardsPayload, GetMemberInvoicesPayload, GetMemberJSONPayload, GetMemberReceiptsPayload, GetPlanPayload, GetPlansPayload, GetPostsPayload, GetRestrictedUrlGroupsPayload, GetSecureContentPayload, GetThreadsPayload, GetTotalCheckoutAmountPayload, LaunchStripeCustomerPortalPayload, LoginMemberEmailPasswordPayload, LogoutMemberPayload, MemberReferenceFieldResult, OpenStripeCustomerPortalPayload, PurchasePlansPayload, PurchasePlansWithCheckoutPayload, QueryDataRecordsPayload, ReferenceFieldResult, RefreshMemberTokensPayload, RemovePlanPayload, ReplacePlanPayload, ResetMemberPassworPayload, SendMemberLoginPasswordlessEmailPayload, SendMemberResetPasswordEmailPayload, SendMemberVerificationEmailPayload, SetPasswordPayload, SignupMemberAuthProviderPayload, SignupMemberEmailPasswordPayload, UpdateDataRecordPayload, UpdateDefaultCardPayload, UpdateMemberAuthPayload, UpdateMemberPayload, UpdateMemberProfileImagePayload, UpdatePlanPaymentPayload, UpdatePostPayload, UpdateThreadPayload } from './payloads.js';
|
|
3
3
|
export { MemberstackTranslations } from './translations.js';
|
|
4
|
+
export { A as App, c as AuthProvider, e as AuthTokens, B as Branding, i as CheckoutTotal, C as ContentGroup, j as CustomField, E as ExtractData, M as Member, d as MemberAuth, f as MemberCard, m as MemberDisplayInfo, g as MemberInvoice, h as MemberReceipt, l as PaginatedData, P as Plan, b as PlanConnection, k as Post, a as Price, S as SecureContent, T as Thread } from '../models-BmZS-mc4.js';
|
|
4
5
|
import './utils/payloads.js';
|
package/lib/types/index.js
CHANGED