@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
|
@@ -114,9 +114,7 @@ declare namespace Payload {
|
|
|
114
114
|
redirect: string;
|
|
115
115
|
contentGroups?: Transforms["RestrictedUrlGroup"][];
|
|
116
116
|
};
|
|
117
|
-
MemberJSON:
|
|
118
|
-
json: object;
|
|
119
|
-
};
|
|
117
|
+
MemberJSON: object;
|
|
120
118
|
AuthProviders: {
|
|
121
119
|
providers: {
|
|
122
120
|
provider: string;
|
|
@@ -137,8 +135,8 @@ declare namespace Payload {
|
|
|
137
135
|
loginRedirect: string;
|
|
138
136
|
stripeCustomerId: string;
|
|
139
137
|
createdAt: string;
|
|
140
|
-
metaData:
|
|
141
|
-
customFields:
|
|
138
|
+
metaData: Record<string, unknown>;
|
|
139
|
+
customFields: Record<string, unknown>;
|
|
142
140
|
permissions: string[] | [];
|
|
143
141
|
planConnections: Transforms["MemberPlanConnection"][];
|
|
144
142
|
};
|
|
@@ -296,4 +294,194 @@ declare namespace Payload {
|
|
|
296
294
|
}
|
|
297
295
|
}
|
|
298
296
|
|
|
299
|
-
|
|
297
|
+
/**
|
|
298
|
+
* @fileoverview Convenience type exports for Memberstack SDK.
|
|
299
|
+
* These types provide direct access to core data models without needing
|
|
300
|
+
* to navigate the Payload.Transforms namespace.
|
|
301
|
+
*
|
|
302
|
+
* @example
|
|
303
|
+
* ```typescript
|
|
304
|
+
* import type { Member, Plan, PlanConnection } from '@memberstack/dom';
|
|
305
|
+
*
|
|
306
|
+
* function displayMember(member: Member) {
|
|
307
|
+
* console.log(member.auth.email);
|
|
308
|
+
* }
|
|
309
|
+
* ```
|
|
310
|
+
*/
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* A Memberstack member (authenticated user).
|
|
314
|
+
*
|
|
315
|
+
* @example
|
|
316
|
+
* ```typescript
|
|
317
|
+
* const { data: member } = await memberstack.getCurrentMember();
|
|
318
|
+
* if (member) {
|
|
319
|
+
* console.log('Email:', member.auth.email);
|
|
320
|
+
* console.log('Verified:', member.verified);
|
|
321
|
+
* console.log('Plans:', member.planConnections.map(p => p.planId));
|
|
322
|
+
* }
|
|
323
|
+
* ```
|
|
324
|
+
*/
|
|
325
|
+
type Member = Payload.Transforms["Member"];
|
|
326
|
+
/**
|
|
327
|
+
* A membership plan in your Memberstack app.
|
|
328
|
+
*
|
|
329
|
+
* @example
|
|
330
|
+
* ```typescript
|
|
331
|
+
* const { data: plans } = await memberstack.getPlans();
|
|
332
|
+
* plans.forEach((plan: Plan) => {
|
|
333
|
+
* console.log(`${plan.name}: ${plan.prices?.[0]?.amount}`);
|
|
334
|
+
* });
|
|
335
|
+
* ```
|
|
336
|
+
*/
|
|
337
|
+
type Plan = Payload.Transforms["Plan"];
|
|
338
|
+
/**
|
|
339
|
+
* A price option for a plan (monthly, yearly, etc.).
|
|
340
|
+
*
|
|
341
|
+
* @example
|
|
342
|
+
* ```typescript
|
|
343
|
+
* const plan = plans[0];
|
|
344
|
+
* plan.prices?.forEach((price: Price) => {
|
|
345
|
+
* console.log(`${price.name}: ${price.amount} ${price.currency}/${price.interval.type}`);
|
|
346
|
+
* });
|
|
347
|
+
* ```
|
|
348
|
+
*/
|
|
349
|
+
type Price = Payload.Transforms["Price"];
|
|
350
|
+
/**
|
|
351
|
+
* A member's connection to a plan (subscription or one-time purchase).
|
|
352
|
+
*
|
|
353
|
+
* @example
|
|
354
|
+
* ```typescript
|
|
355
|
+
* const activePlans = member.planConnections.filter(
|
|
356
|
+
* (conn: PlanConnection) => conn.active
|
|
357
|
+
* );
|
|
358
|
+
* ```
|
|
359
|
+
*/
|
|
360
|
+
type PlanConnection = Payload.Transforms["MemberPlanConnection"];
|
|
361
|
+
/**
|
|
362
|
+
* A content group that restricts access to URLs.
|
|
363
|
+
*
|
|
364
|
+
* @example
|
|
365
|
+
* ```typescript
|
|
366
|
+
* const { data: groups } = await memberstack.getRestrictedUrlGroups();
|
|
367
|
+
* const accessibleGroups = groups.filter(
|
|
368
|
+
* (g: ContentGroup) => g.activeMemberHasAccess
|
|
369
|
+
* );
|
|
370
|
+
* ```
|
|
371
|
+
*/
|
|
372
|
+
type ContentGroup = Payload.Transforms["RestrictedUrlGroup"];
|
|
373
|
+
/**
|
|
374
|
+
* App configuration and settings.
|
|
375
|
+
*
|
|
376
|
+
* @example
|
|
377
|
+
* ```typescript
|
|
378
|
+
* const { data: app } = await memberstack.getApp();
|
|
379
|
+
* console.log('App:', app.name);
|
|
380
|
+
* console.log('Mode:', app.mode); // 'live' or 'sandbox'
|
|
381
|
+
* ```
|
|
382
|
+
*/
|
|
383
|
+
type App = Payload.Transforms["App"];
|
|
384
|
+
/**
|
|
385
|
+
* Authentication provider configuration (Google, Facebook, etc.).
|
|
386
|
+
*/
|
|
387
|
+
type AuthProvider = Payload.Transforms["AuthProvider"];
|
|
388
|
+
/**
|
|
389
|
+
* Authentication response with tokens and member data.
|
|
390
|
+
*/
|
|
391
|
+
type MemberAuth = Payload.Transforms["MemberAuth"];
|
|
392
|
+
/**
|
|
393
|
+
* Auth tokens returned after login/signup.
|
|
394
|
+
*/
|
|
395
|
+
type AuthTokens = MemberAuth["tokens"];
|
|
396
|
+
/**
|
|
397
|
+
* A saved payment card for a member.
|
|
398
|
+
*
|
|
399
|
+
* @example
|
|
400
|
+
* ```typescript
|
|
401
|
+
* const { data: cards } = await memberstack.getMemberCards();
|
|
402
|
+
* const defaultCard = cards.find((card: MemberCard) => card.default);
|
|
403
|
+
* ```
|
|
404
|
+
*/
|
|
405
|
+
type MemberCard = Payload.Transforms["MemberCard"];
|
|
406
|
+
/**
|
|
407
|
+
* An invoice for a member's subscription.
|
|
408
|
+
*/
|
|
409
|
+
type MemberInvoice = Payload.Transforms["MemberInvoice"];
|
|
410
|
+
/**
|
|
411
|
+
* A payment receipt.
|
|
412
|
+
*/
|
|
413
|
+
type MemberReceipt = Payload.Transforms["MemberReceipt"];
|
|
414
|
+
/**
|
|
415
|
+
* Checkout total calculation including taxes and fees.
|
|
416
|
+
*/
|
|
417
|
+
type CheckoutTotal = Payload.Transforms["TotalCheckoutAmount"];
|
|
418
|
+
/**
|
|
419
|
+
* Gated content returned by getSecureContent().
|
|
420
|
+
*/
|
|
421
|
+
type SecureContent = Payload.Transforms["SecureContent"];
|
|
422
|
+
/**
|
|
423
|
+
* A custom field defined in your Memberstack app.
|
|
424
|
+
*/
|
|
425
|
+
type CustomField = Payload.Transforms["CustomField"];
|
|
426
|
+
/**
|
|
427
|
+
* App branding configuration.
|
|
428
|
+
*/
|
|
429
|
+
type Branding = Payload.Transforms["Branding"];
|
|
430
|
+
/**
|
|
431
|
+
* A community post.
|
|
432
|
+
*/
|
|
433
|
+
type Post = Payload.Transforms["Post"];
|
|
434
|
+
/**
|
|
435
|
+
* A thread/reply on a post.
|
|
436
|
+
*/
|
|
437
|
+
type Thread = Payload.Transforms["Thread"];
|
|
438
|
+
/**
|
|
439
|
+
* Extract the data type from a Memberstack SDK response.
|
|
440
|
+
*
|
|
441
|
+
* @example
|
|
442
|
+
* ```typescript
|
|
443
|
+
* import type { ExtractData, GetCurrentMemberPayload } from '@memberstack/dom';
|
|
444
|
+
*
|
|
445
|
+
* // Get the member type from the response
|
|
446
|
+
* type MemberData = ExtractData<GetCurrentMemberPayload>;
|
|
447
|
+
* // MemberData = Member | null
|
|
448
|
+
* ```
|
|
449
|
+
*/
|
|
450
|
+
type ExtractData<T> = T extends {
|
|
451
|
+
data: infer D;
|
|
452
|
+
} ? D : never;
|
|
453
|
+
/**
|
|
454
|
+
* Generic paginated response shape.
|
|
455
|
+
*
|
|
456
|
+
* @example
|
|
457
|
+
* ```typescript
|
|
458
|
+
* type InvoicesPage = PaginatedData<MemberInvoice>;
|
|
459
|
+
* // { data: MemberInvoice[], hasNext: boolean, endCursor: string | null, totalCount: number }
|
|
460
|
+
* ```
|
|
461
|
+
*/
|
|
462
|
+
type PaginatedData<T> = {
|
|
463
|
+
data: T[];
|
|
464
|
+
hasNext: boolean;
|
|
465
|
+
endCursor: string | null;
|
|
466
|
+
totalCount: number;
|
|
467
|
+
};
|
|
468
|
+
/**
|
|
469
|
+
* Common member fields for display purposes.
|
|
470
|
+
*
|
|
471
|
+
* @example
|
|
472
|
+
* ```typescript
|
|
473
|
+
* function getMemberDisplayInfo(member: Member): MemberDisplayInfo {
|
|
474
|
+
* return {
|
|
475
|
+
* id: member.id,
|
|
476
|
+
* email: member.auth.email,
|
|
477
|
+
* profileImage: member.profileImage,
|
|
478
|
+
* verified: member.verified,
|
|
479
|
+
* };
|
|
480
|
+
* }
|
|
481
|
+
* ```
|
|
482
|
+
*/
|
|
483
|
+
type MemberDisplayInfo = Pick<Member, 'id' | 'profileImage' | 'verified'> & {
|
|
484
|
+
email: string;
|
|
485
|
+
};
|
|
486
|
+
|
|
487
|
+
export { type App as A, type Branding as B, type ContentGroup as C, type ExtractData as E, type Member as M, Payload as P, type SecureContent as S, type Thread as T, type Plan as a, type Price as b, type PlanConnection as c, type AuthProvider as d, type MemberAuth as e, type AuthTokens as f, type MemberCard as g, type MemberInvoice as h, type MemberReceipt as i, type CheckoutTotal as j, type CustomField as k, type Post as l, type PaginatedData as m, type MemberDisplayInfo as n };
|
|
@@ -0,0 +1,295 @@
|
|
|
1
|
+
import { M as Member, a as Plan, c as PlanConnection, g as MemberCard, b as Price, A as App, C as ContentGroup } from '../models-CFT_ABd5.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @fileoverview Test utilities for Memberstack SDK.
|
|
5
|
+
* Provides mock factories and helpers for testing applications that use Memberstack.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```typescript
|
|
9
|
+
* import { createMockMemberstack, mockMember, mockPlan } from '@memberstack/dom/testing';
|
|
10
|
+
*
|
|
11
|
+
* // Create a mock SDK instance
|
|
12
|
+
* const mockMs = createMockMemberstack({
|
|
13
|
+
* member: mockMember({ email: 'test@example.com' }),
|
|
14
|
+
* plans: [mockPlan({ name: 'Pro' })]
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* // Use in tests
|
|
18
|
+
* const { data: member } = await mockMs.getCurrentMember();
|
|
19
|
+
* expect(member?.auth.email).toBe('test@example.com');
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @packageDocumentation
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Creates a mock member object with sensible defaults.
|
|
27
|
+
* Override any property by passing it in the options.
|
|
28
|
+
*
|
|
29
|
+
* @param overrides - Partial member data to override defaults
|
|
30
|
+
* @returns A complete mock Member object
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```typescript
|
|
34
|
+
* // Basic usage
|
|
35
|
+
* const member = mockMember();
|
|
36
|
+
*
|
|
37
|
+
* // With custom email
|
|
38
|
+
* const member = mockMember({ auth: { email: 'custom@test.com' } });
|
|
39
|
+
*
|
|
40
|
+
* // With plans
|
|
41
|
+
* const member = mockMember({
|
|
42
|
+
* planConnections: [mockPlanConnection({ planId: 'pln_abc123' })]
|
|
43
|
+
* });
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
declare function mockMember(overrides?: DeepPartial<Member>): Member;
|
|
47
|
+
/**
|
|
48
|
+
* Creates a mock plan object.
|
|
49
|
+
*
|
|
50
|
+
* @param overrides - Partial plan data to override defaults
|
|
51
|
+
* @returns A complete mock Plan object
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```typescript
|
|
55
|
+
* const freePlan = mockPlan({ name: 'Free', prices: [] });
|
|
56
|
+
* const proPlan = mockPlan({
|
|
57
|
+
* name: 'Pro',
|
|
58
|
+
* prices: [mockPrice({ amount: '9.99' })]
|
|
59
|
+
* });
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
declare function mockPlan(overrides?: DeepPartial<Plan>): Plan;
|
|
63
|
+
/**
|
|
64
|
+
* Creates a mock plan connection (member's subscription to a plan).
|
|
65
|
+
*
|
|
66
|
+
* @param overrides - Partial connection data to override defaults
|
|
67
|
+
* @returns A complete mock PlanConnection object
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* ```typescript
|
|
71
|
+
* // Active subscription
|
|
72
|
+
* const conn = mockPlanConnection({ active: true, status: 'ACTIVE' });
|
|
73
|
+
*
|
|
74
|
+
* // Canceled subscription
|
|
75
|
+
* const conn = mockPlanConnection({
|
|
76
|
+
* active: false,
|
|
77
|
+
* status: 'CANCELED',
|
|
78
|
+
* payment: { cancelAtDate: Date.now() + 86400000 }
|
|
79
|
+
* });
|
|
80
|
+
* ```
|
|
81
|
+
*/
|
|
82
|
+
declare function mockPlanConnection(overrides?: DeepPartial<PlanConnection>): PlanConnection;
|
|
83
|
+
/**
|
|
84
|
+
* Creates a mock payment card.
|
|
85
|
+
*
|
|
86
|
+
* @param overrides - Partial card data to override defaults
|
|
87
|
+
* @returns A complete mock MemberCard object
|
|
88
|
+
*/
|
|
89
|
+
declare function mockCard(overrides?: DeepPartial<MemberCard>): MemberCard;
|
|
90
|
+
/**
|
|
91
|
+
* Creates a mock price object for a plan.
|
|
92
|
+
*
|
|
93
|
+
* @param overrides - Partial price data to override defaults
|
|
94
|
+
* @returns A complete mock Price object
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```typescript
|
|
98
|
+
* const monthlyPrice = mockPrice({ amount: '9.99', name: 'Monthly' });
|
|
99
|
+
* const yearlyPrice = mockPrice({
|
|
100
|
+
* amount: '99.99',
|
|
101
|
+
* name: 'Yearly',
|
|
102
|
+
* interval: { type: 'year', count: 1 }
|
|
103
|
+
* });
|
|
104
|
+
* ```
|
|
105
|
+
*/
|
|
106
|
+
declare function mockPrice(overrides?: DeepPartial<Price>): Price;
|
|
107
|
+
/**
|
|
108
|
+
* Creates a mock app configuration.
|
|
109
|
+
*
|
|
110
|
+
* @param overrides - Partial app data to override defaults
|
|
111
|
+
* @returns A complete mock App object
|
|
112
|
+
*/
|
|
113
|
+
declare function mockApp(overrides?: DeepPartial<App>): App;
|
|
114
|
+
/**
|
|
115
|
+
* Creates a mock content group (restricted URL group).
|
|
116
|
+
*
|
|
117
|
+
* @param overrides - Partial group data to override defaults
|
|
118
|
+
* @returns A complete mock ContentGroup object
|
|
119
|
+
*/
|
|
120
|
+
declare function mockContentGroup(overrides?: DeepPartial<ContentGroup>): ContentGroup;
|
|
121
|
+
/**
|
|
122
|
+
* Options for creating a mock Memberstack instance.
|
|
123
|
+
*/
|
|
124
|
+
interface MockMemberstackOptions {
|
|
125
|
+
/** The currently logged-in member, or null if logged out */
|
|
126
|
+
member?: Member | null;
|
|
127
|
+
/** Available plans in the app */
|
|
128
|
+
plans?: Plan[];
|
|
129
|
+
/** App configuration */
|
|
130
|
+
app?: App;
|
|
131
|
+
/** Content groups */
|
|
132
|
+
contentGroups?: ContentGroup[];
|
|
133
|
+
/** Member's saved cards */
|
|
134
|
+
cards?: MemberCard[];
|
|
135
|
+
/** Custom method overrides */
|
|
136
|
+
overrides?: Partial<MockMemberstackInstance>;
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Mock implementation of the Memberstack SDK.
|
|
140
|
+
* Implements the most commonly used methods for testing.
|
|
141
|
+
*/
|
|
142
|
+
interface MockMemberstackInstance {
|
|
143
|
+
getCurrentMember: () => Promise<{
|
|
144
|
+
data: Member | null;
|
|
145
|
+
}>;
|
|
146
|
+
getPlans: () => Promise<{
|
|
147
|
+
data: Plan[];
|
|
148
|
+
}>;
|
|
149
|
+
getPlan: (params: {
|
|
150
|
+
planId: string;
|
|
151
|
+
}) => Promise<{
|
|
152
|
+
data: Plan | null;
|
|
153
|
+
}>;
|
|
154
|
+
getApp: () => Promise<{
|
|
155
|
+
data: App;
|
|
156
|
+
}>;
|
|
157
|
+
getRestrictedUrlGroups: () => Promise<{
|
|
158
|
+
data: ContentGroup[];
|
|
159
|
+
}>;
|
|
160
|
+
getMemberCards: () => Promise<{
|
|
161
|
+
data: MemberCard[];
|
|
162
|
+
}>;
|
|
163
|
+
loginMemberEmailPassword: (params: {
|
|
164
|
+
email: string;
|
|
165
|
+
password: string;
|
|
166
|
+
}) => Promise<{
|
|
167
|
+
data: {
|
|
168
|
+
member: Member;
|
|
169
|
+
tokens: {
|
|
170
|
+
accessToken: string;
|
|
171
|
+
expires: number;
|
|
172
|
+
type: string;
|
|
173
|
+
};
|
|
174
|
+
redirect: string;
|
|
175
|
+
};
|
|
176
|
+
}>;
|
|
177
|
+
signupMemberEmailPassword: (params: {
|
|
178
|
+
email: string;
|
|
179
|
+
password: string;
|
|
180
|
+
}) => Promise<{
|
|
181
|
+
data: {
|
|
182
|
+
member: Member;
|
|
183
|
+
tokens: {
|
|
184
|
+
accessToken: string;
|
|
185
|
+
expires: number;
|
|
186
|
+
type: string;
|
|
187
|
+
};
|
|
188
|
+
redirect: string;
|
|
189
|
+
};
|
|
190
|
+
}>;
|
|
191
|
+
logout: () => Promise<{
|
|
192
|
+
data: {
|
|
193
|
+
redirect?: string;
|
|
194
|
+
};
|
|
195
|
+
}>;
|
|
196
|
+
updateMember: (params: {
|
|
197
|
+
customFields?: object;
|
|
198
|
+
}) => Promise<{
|
|
199
|
+
data: Member;
|
|
200
|
+
}>;
|
|
201
|
+
onAuthChange: (callback: (payload: {
|
|
202
|
+
member: Member | null;
|
|
203
|
+
}) => void) => () => void;
|
|
204
|
+
_setMember: (member: Member | null) => void;
|
|
205
|
+
_getMockState: () => {
|
|
206
|
+
member: Member | null;
|
|
207
|
+
plans: Plan[];
|
|
208
|
+
app: App;
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Creates a mock Memberstack SDK instance for testing.
|
|
213
|
+
* All methods return promises with mock data based on the provided options.
|
|
214
|
+
*
|
|
215
|
+
* @param options - Configuration for the mock instance
|
|
216
|
+
* @returns A mock Memberstack instance with common methods
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```typescript
|
|
220
|
+
* // Basic setup
|
|
221
|
+
* const mockMs = createMockMemberstack({
|
|
222
|
+
* member: mockMember({ auth: { email: 'test@test.com' } }),
|
|
223
|
+
* plans: [mockPlan({ name: 'Free' }), mockPlan({ name: 'Pro' })]
|
|
224
|
+
* });
|
|
225
|
+
*
|
|
226
|
+
* // Use in component tests
|
|
227
|
+
* const { data: member } = await mockMs.getCurrentMember();
|
|
228
|
+
* expect(member).not.toBeNull();
|
|
229
|
+
*
|
|
230
|
+
* // Test logout flow
|
|
231
|
+
* await mockMs.logout();
|
|
232
|
+
* const { data: afterLogout } = await mockMs.getCurrentMember();
|
|
233
|
+
* expect(afterLogout).toBeNull();
|
|
234
|
+
*
|
|
235
|
+
* // Subscribe to auth changes
|
|
236
|
+
* const authCallback = jest.fn();
|
|
237
|
+
* mockMs.onAuthChange(authCallback);
|
|
238
|
+
* mockMs._setMember(null); // Simulate logout
|
|
239
|
+
* expect(authCallback).toHaveBeenCalledWith({ member: null });
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
declare function createMockMemberstack(options?: MockMemberstackOptions): MockMemberstackInstance;
|
|
243
|
+
/** Deep partial type for nested object overrides */
|
|
244
|
+
type DeepPartial<T> = {
|
|
245
|
+
[P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P];
|
|
246
|
+
};
|
|
247
|
+
/**
|
|
248
|
+
* Custom matchers for testing Memberstack data.
|
|
249
|
+
* These can be extended with Jest's expect.extend() or Vitest's expect.extend().
|
|
250
|
+
*
|
|
251
|
+
* @example
|
|
252
|
+
* ```typescript
|
|
253
|
+
* // In your test setup file:
|
|
254
|
+
* import { memberstackMatchers } from '@memberstack/dom/testing';
|
|
255
|
+
* expect.extend(memberstackMatchers);
|
|
256
|
+
*
|
|
257
|
+
* // In tests:
|
|
258
|
+
* expect(member).toBeLoggedIn();
|
|
259
|
+
* expect(member).toHavePlan('pln_abc123');
|
|
260
|
+
* ```
|
|
261
|
+
*/
|
|
262
|
+
declare const memberstackMatchers: {
|
|
263
|
+
/**
|
|
264
|
+
* Assert that a member is logged in (not null and has an email).
|
|
265
|
+
*/
|
|
266
|
+
toBeLoggedIn(received: Member | null): {
|
|
267
|
+
pass: boolean;
|
|
268
|
+
message: () => string;
|
|
269
|
+
};
|
|
270
|
+
/**
|
|
271
|
+
* Assert that a member has a specific plan.
|
|
272
|
+
*/
|
|
273
|
+
toHavePlan(received: Member | null, planId: string): {
|
|
274
|
+
pass: boolean;
|
|
275
|
+
message: () => string;
|
|
276
|
+
};
|
|
277
|
+
/**
|
|
278
|
+
* Assert that a member's email is verified.
|
|
279
|
+
*/
|
|
280
|
+
toBeVerified(received: Member | null): {
|
|
281
|
+
pass: boolean;
|
|
282
|
+
message: () => "Expected member not to be verified" | "Expected member to be verified";
|
|
283
|
+
};
|
|
284
|
+
};
|
|
285
|
+
declare global {
|
|
286
|
+
namespace jest {
|
|
287
|
+
interface Matchers<R> {
|
|
288
|
+
toBeLoggedIn(): R;
|
|
289
|
+
toHavePlan(planId: string): R;
|
|
290
|
+
toBeVerified(): R;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
export { type MockMemberstackInstance, type MockMemberstackOptions, createMockMemberstack, memberstackMatchers, mockApp, mockCard, mockContentGroup, mockMember, mockPlan, mockPlanConnection, mockPrice };
|