@explorins/pers-sdk-react-native 2.1.14-beta.0 → 2.1.18
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/dist/hooks/index.d.ts +3 -2
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/useAnalytics.d.ts +1 -1
- package/dist/hooks/useAnalytics.d.ts.map +1 -1
- package/dist/hooks/useAuth.d.ts +3 -3
- package/dist/hooks/useAuth.d.ts.map +1 -1
- package/dist/hooks/useAuth.js +14 -27
- package/dist/hooks/useBusiness.d.ts +3 -2
- package/dist/hooks/useBusiness.d.ts.map +1 -1
- package/dist/hooks/useBusiness.js +28 -2
- package/dist/hooks/useCampaigns.d.ts +10 -4
- package/dist/hooks/useCampaigns.d.ts.map +1 -1
- package/dist/hooks/useCampaigns.js +36 -8
- package/dist/hooks/useDonations.d.ts +1 -1
- package/dist/hooks/useDonations.d.ts.map +1 -1
- package/dist/hooks/usePurchases.d.ts +2 -2
- package/dist/hooks/usePurchases.d.ts.map +1 -1
- package/dist/hooks/useRedemptions.d.ts +10 -2
- package/dist/hooks/useRedemptions.d.ts.map +1 -1
- package/dist/hooks/useRedemptions.js +32 -4
- package/dist/hooks/useTenants.d.ts +1 -1
- package/dist/hooks/useTenants.d.ts.map +1 -1
- package/dist/hooks/useTokenBalances.d.ts +1 -1
- package/dist/hooks/useTokenBalances.d.ts.map +1 -1
- package/dist/hooks/useTokenBalances.js +1 -1
- package/dist/hooks/useTokens.d.ts +1 -1
- package/dist/hooks/useTokens.d.ts.map +1 -1
- package/dist/hooks/useTransactions.d.ts +1 -1
- package/dist/hooks/useTransactions.d.ts.map +1 -1
- package/dist/hooks/useTriggerSources.d.ts +1 -1
- package/dist/hooks/useTriggerSources.d.ts.map +1 -1
- package/dist/hooks/useUserStatus.d.ts +1 -1
- package/dist/hooks/useUserStatus.d.ts.map +1 -1
- package/dist/hooks/useUsers.d.ts +1 -1
- package/dist/hooks/useUsers.d.ts.map +1 -1
- package/dist/index-CzLxqePZ.js +7717 -0
- package/dist/index-CzLxqePZ.js.map +1 -0
- package/dist/index.d.ts +4 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1731 -284
- package/dist/index.js.map +1 -1
- package/dist/providers/PersSDKProvider.d.ts.map +1 -1
- package/dist/providers/PersSDKProvider.js +26 -37
- package/package.json +182 -182
- package/src/hooks/index.ts +5 -2
- package/src/hooks/useAnalytics.ts +1 -1
- package/src/hooks/useAuth.ts +16 -32
- package/src/hooks/useBusiness.ts +32 -3
- package/src/hooks/useCampaigns.ts +47 -12
- package/src/hooks/useDonations.ts +1 -1
- package/src/hooks/usePurchases.ts +1 -1
- package/src/hooks/useRedemptions.ts +43 -6
- package/src/hooks/useTenants.ts +1 -1
- package/src/hooks/useTokenBalances.ts +1 -1
- package/src/hooks/useTokens.ts +1 -1
- package/src/hooks/useTransactions.ts +1 -1
- package/src/hooks/useTriggerSources.ts +1 -1
- package/src/hooks/useUserStatus.ts +1 -1
- package/src/hooks/useUsers.ts +1 -1
- package/src/index.ts +6 -3
- package/src/providers/PersSDKProvider.tsx +29 -40
|
@@ -9,23 +9,30 @@ import type {
|
|
|
9
9
|
CampaignClaimIncludeRelation,
|
|
10
10
|
CampaignIncludeRelation,
|
|
11
11
|
SortOrder,
|
|
12
|
+
CampaignFilterOptions,
|
|
12
13
|
// DynamicContext
|
|
13
|
-
} from '@explorins/pers-
|
|
14
|
+
} from '@explorins/pers-sdk';
|
|
14
15
|
import type { CampaignClaimFilters } from '@explorins/pers-sdk/campaign';
|
|
15
16
|
|
|
16
17
|
// Re-export for consumers
|
|
17
18
|
export type { CampaignClaimFilters } from '@explorins/pers-sdk/campaign';
|
|
19
|
+
export type { CampaignFilterOptions } from '@explorins/pers-sdk';
|
|
18
20
|
|
|
19
21
|
/**
|
|
20
22
|
* Options for fetching campaigns
|
|
23
|
+
* @deprecated Use CampaignFilterOptions from '@explorins/pers-sdk/campaign' instead
|
|
21
24
|
*/
|
|
22
25
|
export interface GetCampaignsOptions {
|
|
23
|
-
/** Filter by tag */
|
|
24
|
-
|
|
26
|
+
/** Filter by tag(s) - single tag or array for OR match */
|
|
27
|
+
tags?: string | string[];
|
|
25
28
|
/** Free text search across name and description (case-insensitive) */
|
|
26
29
|
search?: string;
|
|
27
30
|
/** Filter by business ID */
|
|
28
31
|
businessId?: string;
|
|
32
|
+
/** Filter campaigns starting on or after this date */
|
|
33
|
+
startDate?: Date | string;
|
|
34
|
+
/** Filter campaigns ending on or before this date */
|
|
35
|
+
endDate?: Date | string;
|
|
29
36
|
/** Page number (1-indexed) */
|
|
30
37
|
page?: number;
|
|
31
38
|
/** Items per page */
|
|
@@ -34,7 +41,7 @@ export interface GetCampaignsOptions {
|
|
|
34
41
|
sortBy?: 'name' | 'createdAt' | 'startDate';
|
|
35
42
|
/** Sort order */
|
|
36
43
|
sortOrder?: SortOrder;
|
|
37
|
-
/** Relations to include: 'triggerSources', 'businesses' */
|
|
44
|
+
/** Relations to include: 'triggerSources', 'businesses', 'claimCount' */
|
|
38
45
|
include?: CampaignIncludeRelation[];
|
|
39
46
|
}
|
|
40
47
|
|
|
@@ -59,11 +66,15 @@ export const useCampaigns = () => {
|
|
|
59
66
|
* include: ['triggerSources', 'businesses']
|
|
60
67
|
* });
|
|
61
68
|
*
|
|
62
|
-
* // Filter by
|
|
63
|
-
* const { data } = await getActiveCampaigns({
|
|
69
|
+
* // Filter by date range
|
|
70
|
+
* const { data } = await getActiveCampaigns({
|
|
71
|
+
* startDate: '2026-05-01',
|
|
72
|
+
* endDate: '2026-12-31'
|
|
73
|
+
* });
|
|
64
74
|
*
|
|
65
|
-
* //
|
|
66
|
-
* const { data } = await getActiveCampaigns({
|
|
75
|
+
* // Get campaigns with claim count
|
|
76
|
+
* const { data } = await getActiveCampaigns({ include: ['claimCount'] });
|
|
77
|
+
* data.forEach(c => console.log(`${c.name}: ${c.claimCount} claims`));
|
|
67
78
|
* ```
|
|
68
79
|
*/
|
|
69
80
|
const getActiveCampaigns = useCallback(async (
|
|
@@ -89,7 +100,7 @@ export const useCampaigns = () => {
|
|
|
89
100
|
* Get campaign by ID with optional include relations
|
|
90
101
|
*
|
|
91
102
|
* @param campaignId - The campaign ID
|
|
92
|
-
* @param include - Relations to include: 'triggerSources', 'businesses'
|
|
103
|
+
* @param include - Relations to include: 'triggerSources', 'businesses', 'claimCount'
|
|
93
104
|
* @returns Promise resolving to campaign data
|
|
94
105
|
*
|
|
95
106
|
* @example
|
|
@@ -97,6 +108,10 @@ export const useCampaigns = () => {
|
|
|
97
108
|
* // Get campaign with all related data
|
|
98
109
|
* const campaign = await getCampaignById('campaign-123', ['triggerSources', 'businesses']);
|
|
99
110
|
* console.log('Trigger sources:', campaign.included?.triggerSources);
|
|
111
|
+
*
|
|
112
|
+
* // Get campaign with claim count
|
|
113
|
+
* const campaign = await getCampaignById('campaign-123', ['claimCount']);
|
|
114
|
+
* console.log('Total claims:', campaign.claimCount);
|
|
100
115
|
* ```
|
|
101
116
|
*/
|
|
102
117
|
const getCampaignById = useCallback(async (
|
|
@@ -259,8 +274,13 @@ export const useCampaigns = () => {
|
|
|
259
274
|
* // Get only active campaigns with trigger sources
|
|
260
275
|
* const { data } = await getAllCampaigns({ active: true, include: ['triggerSources'] });
|
|
261
276
|
*
|
|
262
|
-
* //
|
|
263
|
-
* const { data } = await getAllCampaigns({
|
|
277
|
+
* // Filter by date range with claim count
|
|
278
|
+
* const { data } = await getAllCampaigns({
|
|
279
|
+
* startDate: '2026-05-01',
|
|
280
|
+
* endDate: '2026-12-31',
|
|
281
|
+
* include: ['claimCount']
|
|
282
|
+
* });
|
|
283
|
+
* data.forEach(c => console.log(`${c.name}: ${c.claimCount} claims`));
|
|
264
284
|
*
|
|
265
285
|
* // With pagination and sorting
|
|
266
286
|
* const { data } = await getAllCampaigns({
|
|
@@ -290,7 +310,16 @@ export const useCampaigns = () => {
|
|
|
290
310
|
/**
|
|
291
311
|
* Admin: Get campaign claims with optional filters and include relations
|
|
292
312
|
*
|
|
293
|
-
* @param filters - Optional filters for campaign, user,
|
|
313
|
+
* @param filters - Optional filters for campaign, user, business, and date range
|
|
314
|
+
* @param filters.campaignId - Filter by specific campaign ID
|
|
315
|
+
* @param filters.userId - Filter by user ID
|
|
316
|
+
* @param filters.businessId - Filter by business ID
|
|
317
|
+
* @param filters.dateFrom - Filter claims created on or after this date (ISO 8601 format)
|
|
318
|
+
* @param filters.dateTo - Filter claims created on or before this date (ISO 8601 format)
|
|
319
|
+
* @param filters.page - Page number (1-indexed)
|
|
320
|
+
* @param filters.limit - Items per page
|
|
321
|
+
* @param filters.sortBy - Field to sort by
|
|
322
|
+
* @param filters.sortOrder - Sort direction
|
|
294
323
|
* @param include - Relations to include: 'campaign', 'user', 'business'
|
|
295
324
|
* @returns Promise resolving to paginated campaign claims
|
|
296
325
|
*
|
|
@@ -301,6 +330,12 @@ export const useCampaigns = () => {
|
|
|
301
330
|
*
|
|
302
331
|
* // Get claims for a specific campaign
|
|
303
332
|
* const { data } = await getCampaignClaims({ campaignId: 'campaign-123' }, ['user', 'business']);
|
|
333
|
+
*
|
|
334
|
+
* // Filter by date range
|
|
335
|
+
* const { data } = await getCampaignClaims({
|
|
336
|
+
* dateFrom: '2026-01-01',
|
|
337
|
+
* dateTo: '2026-03-31'
|
|
338
|
+
* }, ['campaign']);
|
|
304
339
|
* ```
|
|
305
340
|
*/
|
|
306
341
|
const getCampaignClaims = useCallback(async (
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
2
|
import { usePersSDK } from '../providers/PersSDKProvider';
|
|
3
|
-
import type { DonationTypeDTO, PaginatedResponseDTO } from '@explorins/pers-
|
|
3
|
+
import type { DonationTypeDTO, PaginatedResponseDTO } from '@explorins/pers-sdk';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* React hook for donation operations in the PERS SDK
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
2
|
import { usePersSDK } from '../providers/PersSDKProvider';
|
|
3
|
-
import type { PurchaseTokenDTO, PurchaseDTO, PaginatedResponseDTO } from '@explorins/pers-
|
|
3
|
+
import type { PurchaseTokenDTO, PurchaseDTO, PaginatedResponseDTO } from '@explorins/pers-sdk';
|
|
4
4
|
|
|
5
5
|
export const usePurchases = () => {
|
|
6
6
|
const { sdk, isInitialized, isAuthenticated } = usePersSDK();
|
|
@@ -9,10 +9,11 @@ import type {
|
|
|
9
9
|
RedemptionTypeDTO,
|
|
10
10
|
PaginatedResponseDTO,
|
|
11
11
|
RedemptionRedeemIncludeRelation,
|
|
12
|
+
RedemptionIncludeRelation,
|
|
12
13
|
ProcessRecordStatus,
|
|
13
14
|
DynamicContext,
|
|
14
15
|
SortOrder
|
|
15
|
-
} from '@explorins/pers-
|
|
16
|
+
} from '@explorins/pers-sdk';
|
|
16
17
|
import type { RedemptionRedeemFilters, RedemptionFilterOptions } from '@explorins/pers-sdk/redemption';
|
|
17
18
|
import type { PaginationOptions } from '@explorins/pers-sdk';
|
|
18
19
|
|
|
@@ -27,12 +28,20 @@ export interface GetRedemptionsOptions {
|
|
|
27
28
|
active?: boolean;
|
|
28
29
|
/** Free text search across name, description, tags (case-insensitive) */
|
|
29
30
|
search?: string;
|
|
31
|
+
/** Filter by tag(s) - single tag or array for OR match */
|
|
32
|
+
tags?: string | string[];
|
|
33
|
+
/** Filter redemptions starting on or after this date */
|
|
34
|
+
startDate?: Date | string;
|
|
35
|
+
/** Filter redemptions ending on or before this date */
|
|
36
|
+
endDate?: Date | string;
|
|
37
|
+
/** Relations to include: 'redeemCount' */
|
|
38
|
+
include?: RedemptionIncludeRelation[];
|
|
30
39
|
/** Page number (1-indexed) */
|
|
31
40
|
page?: number;
|
|
32
41
|
/** Results per page */
|
|
33
42
|
limit?: number;
|
|
34
43
|
/** Field to sort by */
|
|
35
|
-
sortBy?: 'name' | 'createdAt';
|
|
44
|
+
sortBy?: 'name' | 'createdAt' | 'startDate';
|
|
36
45
|
/** Sort direction */
|
|
37
46
|
sortOrder?: SortOrder;
|
|
38
47
|
}
|
|
@@ -52,6 +61,9 @@ export const useRedemptions = () => {
|
|
|
52
61
|
* @param options - Filter and pagination options
|
|
53
62
|
* @param options.active - Filter by active status (Admin only)
|
|
54
63
|
* @param options.search - Free text search across name, description, tags
|
|
64
|
+
* @param options.startDate - Filter redemptions starting on or after this date
|
|
65
|
+
* @param options.endDate - Filter redemptions ending on or before this date
|
|
66
|
+
* @param options.include - Relations to include: 'redeemCount'
|
|
55
67
|
* @param options.page - Page number (1-indexed)
|
|
56
68
|
* @param options.limit - Results per page
|
|
57
69
|
* @param options.sortBy - Field to sort by ('name' | 'createdAt')
|
|
@@ -62,12 +74,21 @@ export const useRedemptions = () => {
|
|
|
62
74
|
* const { data: offers } = await getRedemptions();
|
|
63
75
|
* ```
|
|
64
76
|
*
|
|
65
|
-
* @example
|
|
77
|
+
* @example Filter by date range
|
|
66
78
|
* ```typescript
|
|
67
|
-
* const { data:
|
|
79
|
+
* const { data: dateFiltered } = await getRedemptions({
|
|
80
|
+
* startDate: '2026-05-01',
|
|
81
|
+
* endDate: '2026-06-30'
|
|
82
|
+
* });
|
|
68
83
|
* ```
|
|
69
84
|
*
|
|
70
|
-
* @example
|
|
85
|
+
* @example Get redemptions with redeem count
|
|
86
|
+
* ```typescript
|
|
87
|
+
* const { data: offers } = await getRedemptions({ include: ['redeemCount'] });
|
|
88
|
+
* offers.forEach(o => console.log(`${o.name}: ${o.redeemCount} redeems`));
|
|
89
|
+
* ```
|
|
90
|
+
*
|
|
91
|
+
* @example Search with pagination
|
|
71
92
|
* ```typescript
|
|
72
93
|
* const { data, pagination } = await getRedemptions({
|
|
73
94
|
* search: 'discount',
|
|
@@ -242,7 +263,17 @@ export const useRedemptions = () => {
|
|
|
242
263
|
*
|
|
243
264
|
* Retrieves all redemption redeems across the platform with filtering.
|
|
244
265
|
*
|
|
245
|
-
* @param filters - Optional filters for user, redemption, and pagination
|
|
266
|
+
* @param filters - Optional filters for user, redemption, date range, and pagination
|
|
267
|
+
* @param filters.userId - Filter by user ID
|
|
268
|
+
* @param filters.redemptionId - Filter by redemption offer ID
|
|
269
|
+
* @param filters.businessId - Filter by business ID (admin only)
|
|
270
|
+
* @param filters.status - Filter by processing status (PENDING, PROCESSING, COMPLETED, FAILED)
|
|
271
|
+
* @param filters.dateFrom - Filter redeems created on or after this date (ISO 8601 format)
|
|
272
|
+
* @param filters.dateTo - Filter redeems created on or before this date (ISO 8601 format)
|
|
273
|
+
* @param filters.page - Page number (1-indexed)
|
|
274
|
+
* @param filters.limit - Items per page
|
|
275
|
+
* @param filters.sortBy - Field to sort by
|
|
276
|
+
* @param filters.sortOrder - Sort direction
|
|
246
277
|
* @param include - Relations to include: 'redemption', 'user', 'business'
|
|
247
278
|
* @returns Promise resolving to paginated redemption redeems
|
|
248
279
|
*
|
|
@@ -256,6 +287,12 @@ export const useRedemptions = () => {
|
|
|
256
287
|
* { userId: 'user-123' },
|
|
257
288
|
* ['redemption']
|
|
258
289
|
* );
|
|
290
|
+
*
|
|
291
|
+
* // Filter by date range
|
|
292
|
+
* const { data } = await getRedemptionRedeems({
|
|
293
|
+
* dateFrom: '2026-01-01',
|
|
294
|
+
* dateTo: '2026-03-31'
|
|
295
|
+
* }, ['user', 'redemption']);
|
|
259
296
|
* ```
|
|
260
297
|
*/
|
|
261
298
|
const getRedemptionRedeems = useCallback(async (
|
package/src/hooks/useTenants.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
2
|
import { usePersSDK } from '../providers/PersSDKProvider';
|
|
3
|
-
import type { TenantPublicDTO, TenantClientConfigDTO, AdminDTO, PaginatedResponseDTO } from '@explorins/pers-
|
|
3
|
+
import type { TenantPublicDTO, TenantClientConfigDTO, AdminDTO, PaginatedResponseDTO } from '@explorins/pers-sdk';
|
|
4
4
|
|
|
5
5
|
export const useTenants = () => {
|
|
6
6
|
const { sdk, isInitialized } = usePersSDK();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useCallback, useEffect, useState, useRef } from 'react';
|
|
2
2
|
import { usePersSDK } from '../providers/PersSDKProvider';
|
|
3
3
|
import { useWeb3 } from './useWeb3';
|
|
4
|
-
import { NativeTokenTypes, type TokenDTO } from '@explorins/pers-
|
|
4
|
+
import { NativeTokenTypes, type TokenDTO } from '@explorins/pers-sdk';
|
|
5
5
|
import type { TokenBalance, TokenBalanceRequest } from '@explorins/pers-sdk/web3';
|
|
6
6
|
|
|
7
7
|
/**
|
package/src/hooks/useTokens.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
2
|
import { usePersSDK } from '../providers/PersSDKProvider';
|
|
3
|
-
import type { TokenDTO, PaginatedResponseDTO } from '@explorins/pers-
|
|
3
|
+
import type { TokenDTO, PaginatedResponseDTO } from '@explorins/pers-sdk';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* React hook for token operations in the PERS SDK
|
|
@@ -8,7 +8,7 @@ import type {
|
|
|
8
8
|
TransactionPaginationRequestDTO,
|
|
9
9
|
PaginatedResponseDTO,
|
|
10
10
|
TransactionIncludeRelation
|
|
11
|
-
} from '@explorins/pers-
|
|
11
|
+
} from '@explorins/pers-sdk';
|
|
12
12
|
import type { TransactionQueryOptions } from '@explorins/pers-sdk/transaction';
|
|
13
13
|
|
|
14
14
|
// Re-export for consumers
|
|
@@ -4,7 +4,7 @@ import type {
|
|
|
4
4
|
TriggerSourceDTO,
|
|
5
5
|
TriggerSourceCreateRequestDTO,
|
|
6
6
|
PaginatedResponseDTO
|
|
7
|
-
} from '@explorins/pers-
|
|
7
|
+
} from '@explorins/pers-sdk';
|
|
8
8
|
import type { TriggerSourceQueryOptions } from '@explorins/pers-sdk/trigger-source';
|
|
9
9
|
|
|
10
10
|
// Re-export for consumers
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
2
|
import { usePersSDK } from '../providers/PersSDKProvider';
|
|
3
|
-
import type { UserStatusTypeDTO, PaginatedResponseDTO } from '@explorins/pers-
|
|
3
|
+
import type { UserStatusTypeDTO, PaginatedResponseDTO } from '@explorins/pers-sdk';
|
|
4
4
|
|
|
5
5
|
export const useUserStatus = () => {
|
|
6
6
|
const { sdk, isInitialized, isAuthenticated } = usePersSDK();
|
package/src/hooks/useUsers.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useCallback } from 'react';
|
|
2
2
|
import { usePersSDK } from '../providers/PersSDKProvider';
|
|
3
|
-
import type { UserDTO, UserCreateRequestDTO, PaginatedResponseDTO } from '@explorins/pers-
|
|
3
|
+
import type { UserDTO, UserCreateRequestDTO, PaginatedResponseDTO } from '@explorins/pers-sdk';
|
|
4
4
|
import type { UserPublicProfileDTO, UserQueryOptions } from '@explorins/pers-sdk/user';
|
|
5
5
|
|
|
6
6
|
// Re-export for consumers
|
package/src/index.ts
CHANGED
|
@@ -284,10 +284,13 @@ export type { EventsHook, PersEvent, EventHandler, EventFilter, Unsubscribe } fr
|
|
|
284
284
|
export type { TokenBalanceWithToken, UseTokenBalancesOptions, UseTokenBalancesResult } from './hooks';
|
|
285
285
|
|
|
286
286
|
// Re-export campaign types for convenience
|
|
287
|
-
export type { CampaignClaimFilters, CampaignHook, GetCampaignsOptions } from './hooks';
|
|
287
|
+
export type { CampaignClaimFilters, CampaignFilterOptions, CampaignHook, GetCampaignsOptions } from './hooks';
|
|
288
288
|
|
|
289
289
|
// Re-export redemption types for convenience
|
|
290
|
-
export type { RedemptionRedeemFilters, RedemptionHook } from './hooks';
|
|
290
|
+
export type { RedemptionRedeemFilters, RedemptionFilterOptions, RedemptionHook, GetRedemptionsOptions } from './hooks';
|
|
291
|
+
|
|
292
|
+
// Re-export business types for convenience
|
|
293
|
+
export type { BusinessFilterOptions, BusinessHook } from './hooks';
|
|
291
294
|
|
|
292
295
|
// Re-export transaction types for convenience
|
|
293
296
|
export type { TransactionQueryOptions, TransactionHook } from './hooks';
|
|
@@ -357,7 +360,7 @@ export {
|
|
|
357
360
|
*
|
|
358
361
|
* @see {@link https://github.com/eXplorins/pers-shared} - Shared library documentation
|
|
359
362
|
*/
|
|
360
|
-
export * from '@explorins/pers-
|
|
363
|
+
export * from '@explorins/pers-sdk';
|
|
361
364
|
|
|
362
365
|
/**
|
|
363
366
|
* Token utilities re-exported from token module
|
|
@@ -89,6 +89,7 @@ export const PersSDKProvider: React.FC<{
|
|
|
89
89
|
config?: PersConfig;
|
|
90
90
|
}> = ({ children, config }) => {
|
|
91
91
|
const initializingRef = useRef(false);
|
|
92
|
+
const eventUnsubscribeRef = useRef<(() => void) | null>(null);
|
|
92
93
|
|
|
93
94
|
// State refs for stable functions to read current values
|
|
94
95
|
const sdkRef = useRef<PersSDK | null>(null);
|
|
@@ -156,6 +157,23 @@ export const PersSDKProvider: React.FC<{
|
|
|
156
157
|
// Initialize PersSDK with platform-aware auth provider
|
|
157
158
|
const sdkInstance = new PersSDK(httpClient, sdkConfig);
|
|
158
159
|
|
|
160
|
+
// Subscribe to auth events BEFORE exposing SDK to consumers
|
|
161
|
+
// This ensures no events are missed due to React timing
|
|
162
|
+
eventUnsubscribeRef.current = sdkInstance.events.subscribe((event) => {
|
|
163
|
+
if (event.type === 'session_restored' || event.type === 'login_success') {
|
|
164
|
+
const details = event.details as { user?: UserDTO | AdminDTO };
|
|
165
|
+
if (details?.user) {
|
|
166
|
+
setUser(details.user);
|
|
167
|
+
setIsAuthenticated(true);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (event.type === 'logout_success' || event.type === 'session_restoration_failed' || event.code === 'AUTH_FAILED') {
|
|
172
|
+
setUser(null);
|
|
173
|
+
setIsAuthenticated(false);
|
|
174
|
+
}
|
|
175
|
+
}, { domains: ['authentication'], replay: true });
|
|
176
|
+
|
|
159
177
|
setAuthProvider(authProvider);
|
|
160
178
|
setSdk(sdkInstance);
|
|
161
179
|
setIsInitialized(true);
|
|
@@ -167,6 +185,16 @@ export const PersSDKProvider: React.FC<{
|
|
|
167
185
|
initializingRef.current = false;
|
|
168
186
|
}
|
|
169
187
|
}, [isInitialized]);
|
|
188
|
+
|
|
189
|
+
// Cleanup subscription on unmount
|
|
190
|
+
useEffect(() => {
|
|
191
|
+
return () => {
|
|
192
|
+
if (eventUnsubscribeRef.current) {
|
|
193
|
+
eventUnsubscribeRef.current();
|
|
194
|
+
eventUnsubscribeRef.current = null;
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
}, []);
|
|
170
198
|
|
|
171
199
|
const setAuthenticationState = useCallback((user: UserDTO | AdminDTO | null, isAuthenticated: boolean) => {
|
|
172
200
|
setUser(user);
|
|
@@ -219,45 +247,7 @@ export const PersSDKProvider: React.FC<{
|
|
|
219
247
|
console.error('[PersSDK] Failed to restore session:', error);
|
|
220
248
|
throw error;
|
|
221
249
|
}
|
|
222
|
-
}, [setAuthenticationState]);
|
|
223
|
-
|
|
224
|
-
// Listen for authentication events from core SDK
|
|
225
|
-
// Set up immediately when SDK is created (don't wait for isInitialized)
|
|
226
|
-
// to catch session_restored events that fire during SDK initialization
|
|
227
|
-
useEffect(() => {
|
|
228
|
-
if (!sdk) return;
|
|
229
|
-
|
|
230
|
-
const unsubscribe = sdk.events.subscribe((event) => {
|
|
231
|
-
if (event.domain !== 'authentication') return;
|
|
232
|
-
|
|
233
|
-
// Session restored successfully - sync React state
|
|
234
|
-
if (event.type === 'session_restored') {
|
|
235
|
-
console.log('[PersSDK] Session restoration event received, syncing state...');
|
|
236
|
-
// Read user from event details if available, otherwise fetch
|
|
237
|
-
const userId = event.details?.userId;
|
|
238
|
-
if (userId) {
|
|
239
|
-
// User ID available, fetch user data
|
|
240
|
-
sdk.users.getCurrentUser()
|
|
241
|
-
.then(userData => {
|
|
242
|
-
setAuthenticationState(userData, true);
|
|
243
|
-
})
|
|
244
|
-
.catch(error => {
|
|
245
|
-
console.error('[PersSDK] Failed to sync restored session:', error);
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
// Session restoration failed or auth error - clear React state
|
|
251
|
-
if (event.type === 'session_restoration_failed' || event.code === 'AUTH_FAILED') {
|
|
252
|
-
console.log('[PersSDK] Authentication failed - clearing session');
|
|
253
|
-
setAuthenticationState(null, false);
|
|
254
|
-
}
|
|
255
|
-
}, { domains: ['authentication'] });
|
|
256
|
-
|
|
257
|
-
return () => {
|
|
258
|
-
unsubscribe();
|
|
259
|
-
};
|
|
260
|
-
}, [sdk, setAuthenticationState]);
|
|
250
|
+
}, [setAuthenticationState]);
|
|
261
251
|
|
|
262
252
|
// iOS/Android: Monitor app state and validate tokens when app becomes active
|
|
263
253
|
useEffect(() => {
|
|
@@ -267,7 +257,6 @@ export const PersSDKProvider: React.FC<{
|
|
|
267
257
|
|
|
268
258
|
const handleAppStateChange = async (nextAppState: AppStateStatus) => {
|
|
269
259
|
if (nextAppState === 'active' && isAuthenticated) {
|
|
270
|
-
console.log('[PersSDK] App became active - validating tokens');
|
|
271
260
|
try {
|
|
272
261
|
// Trigger token validation when app resumes from background
|
|
273
262
|
// This ensures tokens are checked after extended inactivity
|