@explorins/pers-sdk-react-native 2.1.3 → 2.1.5
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 +7 -7
- package/dist/hooks/index.d.ts +6 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +1 -0
- package/dist/hooks/useAnalytics.d.ts +37 -14
- package/dist/hooks/useAnalytics.d.ts.map +1 -1
- package/dist/hooks/useAnalytics.js +239 -19
- package/dist/hooks/useCampaigns.d.ts +14 -6
- package/dist/hooks/useCampaigns.d.ts.map +1 -1
- package/dist/hooks/useCampaigns.js +144 -10
- package/dist/hooks/useRedemptions.d.ts +5 -2
- package/dist/hooks/useRedemptions.d.ts.map +1 -1
- package/dist/hooks/useRedemptions.js +53 -2
- package/dist/hooks/useTransactions.d.ts +8 -5
- package/dist/hooks/useTransactions.d.ts.map +1 -1
- package/dist/hooks/useTransactions.js +70 -27
- package/dist/hooks/useTriggerSources.d.ts +76 -0
- package/dist/hooks/useTriggerSources.d.ts.map +1 -0
- package/dist/hooks/useTriggerSources.js +272 -0
- package/dist/index.d.ts +12 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2459 -393
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/hooks/index.ts +17 -1
- package/src/hooks/useAnalytics.ts +268 -21
- package/src/hooks/useCampaigns.ts +176 -14
- package/src/hooks/useRedemptions.ts +66 -3
- package/src/hooks/useTransactions.ts +84 -29
- package/src/hooks/useTriggerSources.ts +301 -0
- package/src/index.ts +33 -3
|
@@ -7,8 +7,13 @@ import type {
|
|
|
7
7
|
RedemptionRedeemDTO,
|
|
8
8
|
RedemptionRedeemRequestResponseDTO,
|
|
9
9
|
RedemptionTypeDTO,
|
|
10
|
-
PaginatedResponseDTO
|
|
10
|
+
PaginatedResponseDTO,
|
|
11
|
+
RedemptionRedeemIncludeRelation
|
|
11
12
|
} from '@explorins/pers-shared';
|
|
13
|
+
import type { RedemptionRedeemFilters } from '@explorins/pers-sdk/redemption';
|
|
14
|
+
|
|
15
|
+
// Re-export for consumers
|
|
16
|
+
export type { RedemptionRedeemFilters } from '@explorins/pers-sdk/redemption';
|
|
12
17
|
|
|
13
18
|
export const useRedemptions = () => {
|
|
14
19
|
const { sdk, isInitialized, isAuthenticated } = usePersSDK();
|
|
@@ -36,7 +41,25 @@ export const useRedemptions = () => {
|
|
|
36
41
|
}
|
|
37
42
|
}, [sdk, isInitialized]);
|
|
38
43
|
|
|
39
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Get user's redemption history with optional include relations
|
|
46
|
+
*
|
|
47
|
+
* @param include - Relations to include: 'redemption', 'user', 'business'
|
|
48
|
+
* @returns Promise resolving to paginated redemption history
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* // Get user redemptions with full redemption details
|
|
53
|
+
* const { data: redeems } = await getUserRedemptions(['redemption', 'business']);
|
|
54
|
+
* redeems.forEach(redeem => {
|
|
55
|
+
* console.log('Redemption:', redeem.included?.redemption?.title);
|
|
56
|
+
* console.log('Business:', redeem.included?.business?.displayName);
|
|
57
|
+
* });
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
const getUserRedemptions = useCallback(async (
|
|
61
|
+
include?: RedemptionRedeemIncludeRelation[]
|
|
62
|
+
): Promise<PaginatedResponseDTO<RedemptionRedeemDTO>> => {
|
|
40
63
|
if (!isInitialized || !sdk) {
|
|
41
64
|
throw new Error('SDK not initialized. Call initialize() first.');
|
|
42
65
|
}
|
|
@@ -46,7 +69,7 @@ export const useRedemptions = () => {
|
|
|
46
69
|
}
|
|
47
70
|
|
|
48
71
|
try {
|
|
49
|
-
const result = await sdk.redemptions.getUserRedemptions();
|
|
72
|
+
const result = await sdk.redemptions.getUserRedemptions(undefined, include);
|
|
50
73
|
return result;
|
|
51
74
|
} catch (error) {
|
|
52
75
|
console.error('Failed to fetch user redemptions:', error);
|
|
@@ -100,6 +123,45 @@ export const useRedemptions = () => {
|
|
|
100
123
|
}, [sdk, isInitialized, isAuthenticated, signAndSubmitTransactionWithJWT, isSignerAvailable]);
|
|
101
124
|
|
|
102
125
|
// Admin methods
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Admin: Get all redemption redeems with filters and include relations
|
|
129
|
+
*
|
|
130
|
+
* Retrieves all redemption redeems across the platform with filtering.
|
|
131
|
+
*
|
|
132
|
+
* @param filters - Optional filters for user, redemption, and pagination
|
|
133
|
+
* @param include - Relations to include: 'redemption', 'user', 'business'
|
|
134
|
+
* @returns Promise resolving to paginated redemption redeems
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```typescript
|
|
138
|
+
* // Get all redeems with user details
|
|
139
|
+
* const { data: redeems } = await getRedemptionRedeems({}, ['user', 'redemption']);
|
|
140
|
+
*
|
|
141
|
+
* // Filter by specific user
|
|
142
|
+
* const { data: userRedeems } = await getRedemptionRedeems(
|
|
143
|
+
* { userId: 'user-123' },
|
|
144
|
+
* ['redemption']
|
|
145
|
+
* );
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
const getRedemptionRedeems = useCallback(async (
|
|
149
|
+
filters?: RedemptionRedeemFilters,
|
|
150
|
+
include?: RedemptionRedeemIncludeRelation[]
|
|
151
|
+
): Promise<PaginatedResponseDTO<RedemptionRedeemDTO>> => {
|
|
152
|
+
if (!isInitialized || !sdk) {
|
|
153
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
try {
|
|
157
|
+
const result = await sdk.redemptions.getRedemptionRedeems(filters, include);
|
|
158
|
+
return result;
|
|
159
|
+
} catch (error) {
|
|
160
|
+
console.error('Failed to fetch redemption redeems:', error);
|
|
161
|
+
throw error;
|
|
162
|
+
}
|
|
163
|
+
}, [sdk, isInitialized]);
|
|
164
|
+
|
|
103
165
|
const createRedemption = useCallback(async (redemptionData: RedemptionCreateRequestDTO): Promise<RedemptionDTO> => {
|
|
104
166
|
if (!isInitialized || !sdk) {
|
|
105
167
|
throw new Error('SDK not initialized. Call initialize() first.');
|
|
@@ -161,6 +223,7 @@ export const useRedemptions = () => {
|
|
|
161
223
|
getUserRedemptions,
|
|
162
224
|
redeem,
|
|
163
225
|
getRedemptionTypes,
|
|
226
|
+
getRedemptionRedeems,
|
|
164
227
|
createRedemption,
|
|
165
228
|
updateRedemption,
|
|
166
229
|
toggleRedemptionStatus,
|
|
@@ -5,10 +5,14 @@ import type {
|
|
|
5
5
|
TransactionRequestDTO,
|
|
6
6
|
TransactionRequestResponseDTO,
|
|
7
7
|
TransactionDTO,
|
|
8
|
-
TransactionRole,
|
|
9
8
|
TransactionPaginationRequestDTO,
|
|
10
|
-
PaginatedResponseDTO
|
|
9
|
+
PaginatedResponseDTO,
|
|
10
|
+
TransactionIncludeRelation
|
|
11
11
|
} from '@explorins/pers-shared';
|
|
12
|
+
import type { TransactionQueryOptions } from '@explorins/pers-sdk/transaction';
|
|
13
|
+
|
|
14
|
+
// Re-export for consumers
|
|
15
|
+
export type { TransactionQueryOptions } from '@explorins/pers-sdk/transaction';
|
|
12
16
|
|
|
13
17
|
/**
|
|
14
18
|
* React hook for transaction operations in the PERS SDK
|
|
@@ -124,26 +128,36 @@ export const useTransactions = () => {
|
|
|
124
128
|
}, [sdk, isInitialized, signAndSubmitTransactionWithJWT, isSignerAvailable]);
|
|
125
129
|
|
|
126
130
|
/**
|
|
127
|
-
* Retrieves a specific transaction by its ID
|
|
131
|
+
* Retrieves a specific transaction by its ID with optional include relations
|
|
128
132
|
*
|
|
129
133
|
* @param transactionId - Unique identifier of the transaction
|
|
134
|
+
* @param include - Optional relations to include (sender, recipient, business) for enriched entity data
|
|
130
135
|
* @returns Promise resolving to transaction data or null if not found
|
|
131
136
|
* @throws Error if SDK is not initialized
|
|
132
137
|
*
|
|
133
138
|
* @example
|
|
134
139
|
* ```typescript
|
|
135
140
|
* const { getTransactionById } = useTransactions();
|
|
141
|
+
*
|
|
142
|
+
* // Basic retrieval
|
|
136
143
|
* const transaction = await getTransactionById('txn-123');
|
|
137
|
-
*
|
|
144
|
+
*
|
|
145
|
+
* // With enriched sender/recipient data
|
|
146
|
+
* const enrichedTx = await getTransactionById('txn-123', ['sender', 'recipient', 'business']);
|
|
147
|
+
* console.log('Sender:', enrichedTx?.included?.sender);
|
|
148
|
+
* console.log('Business:', enrichedTx?.included?.engagedBusiness?.displayName);
|
|
138
149
|
* ```
|
|
139
150
|
*/
|
|
140
|
-
const getTransactionById = useCallback(async (
|
|
151
|
+
const getTransactionById = useCallback(async (
|
|
152
|
+
transactionId: string,
|
|
153
|
+
include?: TransactionIncludeRelation[]
|
|
154
|
+
): Promise<TransactionDTO | null> => {
|
|
141
155
|
if (!isInitialized || !sdk) {
|
|
142
156
|
throw new Error('SDK not initialized. Call initialize() first.');
|
|
143
157
|
}
|
|
144
158
|
|
|
145
159
|
try {
|
|
146
|
-
const result = await sdk.transactions.getTransactionById(transactionId);
|
|
160
|
+
const result = await sdk.transactions.getTransactionById(transactionId, include);
|
|
147
161
|
return result;
|
|
148
162
|
} catch (error) {
|
|
149
163
|
console.error('Failed to fetch transaction:', error);
|
|
@@ -152,27 +166,52 @@ export const useTransactions = () => {
|
|
|
152
166
|
}, [sdk, isInitialized]);
|
|
153
167
|
|
|
154
168
|
/**
|
|
155
|
-
* Retrieves transaction history for the authenticated user
|
|
169
|
+
* Retrieves transaction history for the authenticated user with comprehensive filtering
|
|
156
170
|
*
|
|
157
|
-
*
|
|
158
|
-
*
|
|
171
|
+
* Supports filtering by role, status, type, business, token, and more.
|
|
172
|
+
* Optionally enrich with related entities (sender, recipient, business).
|
|
173
|
+
*
|
|
174
|
+
* @param options - Query options including filters, pagination, and include relations
|
|
175
|
+
* @returns Promise resolving to paginated array of user's transactions
|
|
159
176
|
* @throws Error if SDK is not initialized
|
|
160
177
|
*
|
|
161
178
|
* @example
|
|
162
179
|
* ```typescript
|
|
163
180
|
* const { getUserTransactionHistory } = useTransactions();
|
|
164
|
-
*
|
|
165
|
-
*
|
|
181
|
+
*
|
|
182
|
+
* // Simple: Get all transactions
|
|
183
|
+
* const allTransactions = await getUserTransactionHistory();
|
|
184
|
+
*
|
|
185
|
+
* // Filter by role (legacy support)
|
|
186
|
+
* const sentTransactions = await getUserTransactionHistory({ role: 'SENDER' });
|
|
187
|
+
*
|
|
188
|
+
* // Advanced filtering with include relations
|
|
189
|
+
* const filtered = await getUserTransactionHistory({
|
|
190
|
+
* role: 'SENDER',
|
|
191
|
+
* status: 'COMPLETED',
|
|
192
|
+
* engagedBusinessId: 'business-123',
|
|
193
|
+
* include: ['recipient', 'business'],
|
|
194
|
+
* page: 1,
|
|
195
|
+
* limit: 20
|
|
196
|
+
* });
|
|
197
|
+
*
|
|
198
|
+
* // Access enriched data
|
|
199
|
+
* filtered.data.forEach(tx => {
|
|
200
|
+
* console.log('Recipient:', tx.included?.recipient);
|
|
201
|
+
* console.log('Business:', tx.included?.engagedBusiness?.displayName);
|
|
202
|
+
* });
|
|
166
203
|
* ```
|
|
167
204
|
*/
|
|
168
|
-
const getUserTransactionHistory = useCallback(async (
|
|
205
|
+
const getUserTransactionHistory = useCallback(async (
|
|
206
|
+
options?: TransactionQueryOptions
|
|
207
|
+
): Promise<PaginatedResponseDTO<TransactionDTO>> => {
|
|
169
208
|
|
|
170
209
|
if (!isInitialized || !sdk) {
|
|
171
210
|
throw new Error('SDK not initialized. Call initialize() first.');
|
|
172
211
|
}
|
|
173
212
|
|
|
174
213
|
try {
|
|
175
|
-
const result = await sdk.transactions.getUserTransactionHistory(
|
|
214
|
+
const result = await sdk.transactions.getUserTransactionHistory(options);
|
|
176
215
|
return result;
|
|
177
216
|
} catch (error) {
|
|
178
217
|
console.error('Failed to fetch transaction history:', error);
|
|
@@ -180,27 +219,44 @@ export const useTransactions = () => {
|
|
|
180
219
|
}
|
|
181
220
|
}, [sdk, isInitialized]);
|
|
182
221
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
222
|
+
/**
|
|
223
|
+
* Admin: Get paginated transactions with optional include relations
|
|
224
|
+
*
|
|
225
|
+
* @param params - Pagination and filtering parameters
|
|
226
|
+
* @param include - Optional relations to include for enriched entity data
|
|
227
|
+
* @returns Promise resolving to paginated transaction results
|
|
228
|
+
* @throws Error if SDK is not initialized
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```typescript
|
|
232
|
+
* const { getPaginatedTransactions } = useTransactions();
|
|
233
|
+
*
|
|
234
|
+
* // Basic pagination
|
|
235
|
+
* const result = await getPaginatedTransactions({ page: 1, limit: 50 });
|
|
236
|
+
*
|
|
237
|
+
* // With include relations
|
|
238
|
+
* const enrichedResult = await getPaginatedTransactions(
|
|
239
|
+
* { page: 1, limit: 50, sortBy: 'createdAt', sortOrder: 'DESC' },
|
|
240
|
+
* include: ['sender', 'recipient', 'business']
|
|
241
|
+
* });
|
|
242
|
+
*
|
|
243
|
+
* enrichedResult.data.forEach(tx => {
|
|
244
|
+
* console.log('From:', tx.included?.sender);
|
|
245
|
+
* console.log('To:', tx.included?.recipient);
|
|
246
|
+
* });
|
|
247
|
+
* ```
|
|
248
|
+
*/
|
|
249
|
+
const getPaginatedTransactions = useCallback(async (
|
|
250
|
+
options: TransactionPaginationRequestDTO & {
|
|
251
|
+
include?: TransactionIncludeRelation[];
|
|
194
252
|
}
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
const getPaginatedTransactions = useCallback(async (params: TransactionPaginationRequestDTO): Promise<any> => {
|
|
253
|
+
): Promise<PaginatedResponseDTO<TransactionDTO>> => {
|
|
198
254
|
if (!isInitialized || !sdk) {
|
|
199
255
|
throw new Error('SDK not initialized. Call initialize() first.');
|
|
200
256
|
}
|
|
201
257
|
|
|
202
258
|
try {
|
|
203
|
-
const result = await sdk.transactions.getPaginatedTransactions(
|
|
259
|
+
const result = await sdk.transactions.getPaginatedTransactions(options);
|
|
204
260
|
return result;
|
|
205
261
|
} catch (error) {
|
|
206
262
|
console.error('Failed to fetch paginated transactions:', error);
|
|
@@ -226,7 +282,6 @@ export const useTransactions = () => {
|
|
|
226
282
|
createTransaction,
|
|
227
283
|
getTransactionById,
|
|
228
284
|
getUserTransactionHistory,
|
|
229
|
-
getTenantTransactions,
|
|
230
285
|
getPaginatedTransactions,
|
|
231
286
|
exportTransactionsCSV,
|
|
232
287
|
isAvailable: isInitialized && !!sdk?.transactions,
|
|
@@ -0,0 +1,301 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { usePersSDK } from '../providers/PersSDKProvider';
|
|
3
|
+
import type {
|
|
4
|
+
TriggerSourceDTO,
|
|
5
|
+
TriggerSourceCreateRequestDTO,
|
|
6
|
+
PaginatedResponseDTO
|
|
7
|
+
} from '@explorins/pers-shared';
|
|
8
|
+
import type { TriggerSourceQueryOptions } from '@explorins/pers-sdk/trigger-source';
|
|
9
|
+
|
|
10
|
+
// Re-export for consumers
|
|
11
|
+
export type { TriggerSourceQueryOptions } from '@explorins/pers-sdk/trigger-source';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* React hook for TriggerSource operations in the PERS SDK
|
|
15
|
+
*
|
|
16
|
+
* Manages trigger sources which are physical or digital activation points for campaigns:
|
|
17
|
+
* - **QR_CODE**: Scannable QR codes at physical locations
|
|
18
|
+
* - **NFC_TAG**: NFC tap points for contactless interactions
|
|
19
|
+
* - **GPS_GEOFENCE**: Location-based triggers with radius detection
|
|
20
|
+
* - **API_WEBHOOK**: External system integration triggers
|
|
21
|
+
* - **TRANSACTION**: Purchase/payment based triggers
|
|
22
|
+
*
|
|
23
|
+
* TriggerSources are standalone entities that can be created, managed, and then
|
|
24
|
+
* assigned to campaigns. This separation allows reuse across multiple campaigns.
|
|
25
|
+
*
|
|
26
|
+
* **Admin Only**: All create, update, and delete operations require admin authentication.
|
|
27
|
+
*
|
|
28
|
+
* @returns TriggerSource hook with CRUD operations
|
|
29
|
+
*
|
|
30
|
+
* @example Basic TriggerSource Operations
|
|
31
|
+
* ```typescript
|
|
32
|
+
* function TriggerSourceManager() {
|
|
33
|
+
* const {
|
|
34
|
+
* getAll,
|
|
35
|
+
* getById,
|
|
36
|
+
* create,
|
|
37
|
+
* update,
|
|
38
|
+
* remove
|
|
39
|
+
* } = useTriggerSources();
|
|
40
|
+
*
|
|
41
|
+
* // List all QR code trigger sources
|
|
42
|
+
* const loadQRSources = async () => {
|
|
43
|
+
* const { data: sources } = await getAll({ type: 'QR_CODE' });
|
|
44
|
+
* console.log('QR Sources:', sources);
|
|
45
|
+
* };
|
|
46
|
+
*
|
|
47
|
+
* // Create a new QR code for a store
|
|
48
|
+
* const createStoreQR = async () => {
|
|
49
|
+
* const source = await create({
|
|
50
|
+
* type: 'QR_CODE',
|
|
51
|
+
* name: 'Store Entrance QR',
|
|
52
|
+
* description: 'Scan at the entrance',
|
|
53
|
+
* businessId: 'business-123',
|
|
54
|
+
* coordsLatitude: 47.6062,
|
|
55
|
+
* coordsLongitude: -122.3321
|
|
56
|
+
* });
|
|
57
|
+
* console.log('Created:', source.id);
|
|
58
|
+
* };
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
61
|
+
*
|
|
62
|
+
* @example GPS Geofence Trigger
|
|
63
|
+
* ```typescript
|
|
64
|
+
* const { create } = useTriggerSources();
|
|
65
|
+
*
|
|
66
|
+
* // Create a GPS geofence around a location
|
|
67
|
+
* const geofence = await create({
|
|
68
|
+
* type: 'GPS_GEOFENCE',
|
|
69
|
+
* name: 'Downtown Area',
|
|
70
|
+
* coordsLatitude: 47.6062,
|
|
71
|
+
* coordsLongitude: -122.3321,
|
|
72
|
+
* metadata: { radiusMeters: 100 }
|
|
73
|
+
* });
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export const useTriggerSources = () => {
|
|
77
|
+
const { sdk, isInitialized, isAuthenticated } = usePersSDK();
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Get trigger sources with optional filters and pagination
|
|
81
|
+
*
|
|
82
|
+
* Retrieves trigger sources (QR codes, NFC tags, GPS geofences, webhooks, etc.)
|
|
83
|
+
* that can be used to activate campaigns. Supports filtering by type, business,
|
|
84
|
+
* campaign association, and active status.
|
|
85
|
+
*
|
|
86
|
+
* @param options - Filter and pagination options
|
|
87
|
+
* @returns Promise resolving to paginated trigger sources
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* // Get all QR code trigger sources
|
|
92
|
+
* const { data: qrSources } = await getAll({ type: 'QR_CODE' });
|
|
93
|
+
*
|
|
94
|
+
* // Get trigger sources for a specific business
|
|
95
|
+
* const { data: businessSources, pagination } = await getAll({
|
|
96
|
+
* businessId: 'business-123',
|
|
97
|
+
* active: true,
|
|
98
|
+
* page: 1,
|
|
99
|
+
* limit: 20
|
|
100
|
+
* });
|
|
101
|
+
*
|
|
102
|
+
* // Get trigger sources assigned to a campaign
|
|
103
|
+
* const { data: campaignSources } = await getAll({
|
|
104
|
+
* campaignId: 'campaign-456'
|
|
105
|
+
* });
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
const getAll = useCallback(async (
|
|
109
|
+
options?: TriggerSourceQueryOptions
|
|
110
|
+
): Promise<PaginatedResponseDTO<TriggerSourceDTO>> => {
|
|
111
|
+
if (!isInitialized || !sdk) {
|
|
112
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
try {
|
|
116
|
+
const result = await sdk.triggerSources.getAll(options);
|
|
117
|
+
return result;
|
|
118
|
+
} catch (error) {
|
|
119
|
+
console.error('Failed to fetch trigger sources:', error);
|
|
120
|
+
throw error;
|
|
121
|
+
}
|
|
122
|
+
}, [sdk, isInitialized]);
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Get trigger source by ID
|
|
126
|
+
*
|
|
127
|
+
* Retrieves detailed information for a specific trigger source including
|
|
128
|
+
* its type, location, metadata, and configuration.
|
|
129
|
+
*
|
|
130
|
+
* @param triggerSourceId - UUID of the trigger source
|
|
131
|
+
* @returns Promise resolving to trigger source details
|
|
132
|
+
* @throws {PersApiError} When trigger source with specified ID is not found
|
|
133
|
+
*
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* const source = await getById('source-123');
|
|
137
|
+
*
|
|
138
|
+
* console.log('Trigger Source:', source.name);
|
|
139
|
+
* console.log('Type:', source.type);
|
|
140
|
+
* console.log('Active:', source.isActive);
|
|
141
|
+
*
|
|
142
|
+
* if (source.coordsLatitude && source.coordsLongitude) {
|
|
143
|
+
* console.log('Location:', source.coordsLatitude, source.coordsLongitude);
|
|
144
|
+
* }
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
const getById = useCallback(async (
|
|
148
|
+
triggerSourceId: string
|
|
149
|
+
): Promise<TriggerSourceDTO> => {
|
|
150
|
+
if (!isInitialized || !sdk) {
|
|
151
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
try {
|
|
155
|
+
const result = await sdk.triggerSources.getById(triggerSourceId);
|
|
156
|
+
return result;
|
|
157
|
+
} catch (error) {
|
|
158
|
+
console.error('Failed to fetch trigger source:', error);
|
|
159
|
+
throw error;
|
|
160
|
+
}
|
|
161
|
+
}, [sdk, isInitialized]);
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Admin: Create a new trigger source
|
|
165
|
+
*
|
|
166
|
+
* Creates a new trigger source (QR code, NFC tag, GPS geofence, webhook, or
|
|
167
|
+
* transaction-based trigger) that can be assigned to campaigns. Requires
|
|
168
|
+
* administrator privileges.
|
|
169
|
+
*
|
|
170
|
+
* @param triggerSource - Trigger source creation data
|
|
171
|
+
* @returns Promise resolving to created trigger source
|
|
172
|
+
* @throws {PersApiError} When not authenticated as admin or validation fails
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* // Create a QR code trigger source
|
|
177
|
+
* const qrSource = await create({
|
|
178
|
+
* type: 'QR_CODE',
|
|
179
|
+
* name: 'Store Entrance QR',
|
|
180
|
+
* description: 'QR code at main entrance',
|
|
181
|
+
* businessId: 'business-123',
|
|
182
|
+
* coordsLatitude: 47.6062,
|
|
183
|
+
* coordsLongitude: -122.3321
|
|
184
|
+
* });
|
|
185
|
+
*
|
|
186
|
+
* // Create an NFC tag trigger source
|
|
187
|
+
* const nfcSource = await create({
|
|
188
|
+
* type: 'NFC_TAG',
|
|
189
|
+
* name: 'Product Display NFC',
|
|
190
|
+
* metadata: { productId: 'SKU-12345' }
|
|
191
|
+
* });
|
|
192
|
+
* ```
|
|
193
|
+
*/
|
|
194
|
+
const create = useCallback(async (
|
|
195
|
+
triggerSource: TriggerSourceCreateRequestDTO
|
|
196
|
+
): Promise<TriggerSourceDTO> => {
|
|
197
|
+
if (!isInitialized || !sdk) {
|
|
198
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
199
|
+
}
|
|
200
|
+
if (!isAuthenticated) {
|
|
201
|
+
throw new Error('SDK not authenticated. create requires admin authentication.');
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
try {
|
|
205
|
+
const result = await sdk.triggerSources.create(triggerSource);
|
|
206
|
+
return result;
|
|
207
|
+
} catch (error) {
|
|
208
|
+
console.error('Failed to create trigger source:', error);
|
|
209
|
+
throw error;
|
|
210
|
+
}
|
|
211
|
+
}, [sdk, isInitialized, isAuthenticated]);
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Admin: Update a trigger source
|
|
215
|
+
*
|
|
216
|
+
* Updates an existing trigger source's configuration. All fields are optional;
|
|
217
|
+
* only provided fields will be updated. Requires administrator privileges.
|
|
218
|
+
*
|
|
219
|
+
* @param triggerSourceId - UUID of the trigger source to update
|
|
220
|
+
* @param triggerSource - Updated trigger source data (partial)
|
|
221
|
+
* @returns Promise resolving to updated trigger source
|
|
222
|
+
* @throws {PersApiError} When not authenticated as admin or trigger source not found
|
|
223
|
+
*
|
|
224
|
+
* @example
|
|
225
|
+
* ```typescript
|
|
226
|
+
* // Update trigger source name and location
|
|
227
|
+
* const updated = await update('source-123', {
|
|
228
|
+
* name: 'Updated Store Entrance QR',
|
|
229
|
+
* description: 'New description',
|
|
230
|
+
* coordsLatitude: 47.6063,
|
|
231
|
+
* coordsLongitude: -122.3322
|
|
232
|
+
* });
|
|
233
|
+
* ```
|
|
234
|
+
*/
|
|
235
|
+
const update = useCallback(async (
|
|
236
|
+
triggerSourceId: string,
|
|
237
|
+
triggerSource: Partial<TriggerSourceCreateRequestDTO>
|
|
238
|
+
): Promise<TriggerSourceDTO> => {
|
|
239
|
+
if (!isInitialized || !sdk) {
|
|
240
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
241
|
+
}
|
|
242
|
+
if (!isAuthenticated) {
|
|
243
|
+
throw new Error('SDK not authenticated. update requires admin authentication.');
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
try {
|
|
247
|
+
const result = await sdk.triggerSources.update(triggerSourceId, triggerSource);
|
|
248
|
+
return result;
|
|
249
|
+
} catch (error) {
|
|
250
|
+
console.error('Failed to update trigger source:', error);
|
|
251
|
+
throw error;
|
|
252
|
+
}
|
|
253
|
+
}, [sdk, isInitialized, isAuthenticated]);
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* Admin: Delete a trigger source
|
|
257
|
+
*
|
|
258
|
+
* Soft deletes a trigger source, making it inactive. The trigger source will
|
|
259
|
+
* be removed from any campaigns it was assigned to. Requires administrator
|
|
260
|
+
* privileges.
|
|
261
|
+
*
|
|
262
|
+
* @param triggerSourceId - UUID of the trigger source to delete
|
|
263
|
+
* @returns Promise resolving to success status
|
|
264
|
+
* @throws {PersApiError} When not authenticated as admin or trigger source not found
|
|
265
|
+
*
|
|
266
|
+
* @example
|
|
267
|
+
* ```typescript
|
|
268
|
+
* const success = await remove('source-123');
|
|
269
|
+
* console.log('Trigger source deleted:', success);
|
|
270
|
+
* ```
|
|
271
|
+
*/
|
|
272
|
+
const remove = useCallback(async (
|
|
273
|
+
triggerSourceId: string
|
|
274
|
+
): Promise<boolean> => {
|
|
275
|
+
if (!isInitialized || !sdk) {
|
|
276
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
277
|
+
}
|
|
278
|
+
if (!isAuthenticated) {
|
|
279
|
+
throw new Error('SDK not authenticated. remove requires admin authentication.');
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
try {
|
|
283
|
+
const result = await sdk.triggerSources.delete(triggerSourceId);
|
|
284
|
+
return result;
|
|
285
|
+
} catch (error) {
|
|
286
|
+
console.error('Failed to delete trigger source:', error);
|
|
287
|
+
throw error;
|
|
288
|
+
}
|
|
289
|
+
}, [sdk, isInitialized, isAuthenticated]);
|
|
290
|
+
|
|
291
|
+
return {
|
|
292
|
+
getAll,
|
|
293
|
+
getById,
|
|
294
|
+
create,
|
|
295
|
+
update,
|
|
296
|
+
remove,
|
|
297
|
+
isAvailable: isInitialized && !!sdk?.triggerSources,
|
|
298
|
+
};
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
export type TriggerSourceHook = ReturnType<typeof useTriggerSources>;
|
package/src/index.ts
CHANGED
|
@@ -262,11 +262,20 @@ export {
|
|
|
262
262
|
useFiles,
|
|
263
263
|
useAnalytics,
|
|
264
264
|
useDonations,
|
|
265
|
-
useEvents
|
|
265
|
+
useEvents,
|
|
266
|
+
useTriggerSources
|
|
266
267
|
} from './hooks';
|
|
267
268
|
|
|
268
269
|
// Re-export signing status types for convenience
|
|
269
|
-
export type {
|
|
270
|
+
export type {
|
|
271
|
+
TransactionSignerHook,
|
|
272
|
+
OnStatusUpdateFn,
|
|
273
|
+
StatusUpdateData,
|
|
274
|
+
SigningStatusType,
|
|
275
|
+
TransactionSigningResult,
|
|
276
|
+
SubmissionResult,
|
|
277
|
+
AuthenticatedUser
|
|
278
|
+
} from './hooks';
|
|
270
279
|
|
|
271
280
|
// Re-export event types for convenience
|
|
272
281
|
export type { EventsHook, PersEvent, EventHandler, EventFilter, Unsubscribe } from './hooks';
|
|
@@ -274,6 +283,21 @@ export type { EventsHook, PersEvent, EventHandler, EventFilter, Unsubscribe } fr
|
|
|
274
283
|
// Re-export token balance types for convenience
|
|
275
284
|
export type { TokenBalanceWithToken, UseTokenBalancesOptions, UseTokenBalancesResult } from './hooks';
|
|
276
285
|
|
|
286
|
+
// Re-export campaign types for convenience
|
|
287
|
+
export type { CampaignClaimFilters, CampaignHook } from './hooks';
|
|
288
|
+
|
|
289
|
+
// Re-export redemption types for convenience
|
|
290
|
+
export type { RedemptionRedeemFilters, RedemptionHook } from './hooks';
|
|
291
|
+
|
|
292
|
+
// Re-export transaction types for convenience
|
|
293
|
+
export type { TransactionQueryOptions, TransactionHook } from './hooks';
|
|
294
|
+
|
|
295
|
+
// Re-export trigger source types for convenience
|
|
296
|
+
export type { TriggerSourceQueryOptions, TriggerSourceHook } from './hooks';
|
|
297
|
+
|
|
298
|
+
// Re-export analytics types for convenience
|
|
299
|
+
export type { AnalyticsHook } from './hooks';
|
|
300
|
+
|
|
277
301
|
// ==============================================================================
|
|
278
302
|
// PLATFORM ADAPTERS
|
|
279
303
|
// ==============================================================================
|
|
@@ -284,9 +308,15 @@ export type { TokenBalanceWithToken, UseTokenBalancesOptions, UseTokenBalancesRe
|
|
|
284
308
|
* Provides platform-specific networking with proper error handling, timeout management,
|
|
285
309
|
* and React Native compatibility. Automatically handles headers, authentication tokens,
|
|
286
310
|
* and response parsing.
|
|
311
|
+
*
|
|
312
|
+
* @see {@link ReactNativeHttpClient} - The HTTP client implementation
|
|
313
|
+
* @see {@link HttpClient} - The HTTP client interface
|
|
314
|
+
* @see {@link RequestOptions} - Request configuration options
|
|
287
315
|
*/
|
|
288
316
|
export {
|
|
289
|
-
ReactNativeHttpClient
|
|
317
|
+
ReactNativeHttpClient,
|
|
318
|
+
type HttpClient,
|
|
319
|
+
type RequestOptions
|
|
290
320
|
} from './providers/react-native-http-client';
|
|
291
321
|
|
|
292
322
|
// ==============================================================================
|