@explorins/pers-sdk 2.1.3 → 2.1.6
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/analytics/api/analytics-api.d.ts +175 -1
- package/dist/analytics/api/analytics-api.d.ts.map +1 -1
- package/dist/analytics/models/index.d.ts +2 -5
- package/dist/analytics/models/index.d.ts.map +1 -1
- package/dist/analytics/services/analytics-service.d.ts +32 -1
- package/dist/analytics/services/analytics-service.d.ts.map +1 -1
- package/dist/analytics.cjs +9 -44
- package/dist/analytics.cjs.map +1 -1
- package/dist/analytics.js +2 -45
- package/dist/analytics.js.map +1 -1
- package/dist/campaign/api/campaign-api.d.ts +59 -4
- package/dist/campaign/api/campaign-api.d.ts.map +1 -1
- package/dist/campaign/index.d.ts +1 -0
- package/dist/campaign/index.d.ts.map +1 -1
- package/dist/campaign/models/index.d.ts +31 -0
- package/dist/campaign/models/index.d.ts.map +1 -0
- package/dist/campaign/services/campaign-service.d.ts +49 -7
- package/dist/campaign/services/campaign-service.d.ts.map +1 -1
- package/dist/campaign.cjs +150 -14
- package/dist/campaign.cjs.map +1 -1
- package/dist/campaign.js +150 -14
- package/dist/campaign.js.map +1 -1
- package/dist/chunks/analytics-service-B9IfG6ox.js +271 -0
- package/dist/chunks/analytics-service-B9IfG6ox.js.map +1 -0
- package/dist/chunks/analytics-service-DwkeBB08.cjs +274 -0
- package/dist/chunks/analytics-service-DwkeBB08.cjs.map +1 -0
- package/dist/chunks/{pers-sdk-fWg-J3_h.js → pers-sdk-BtvhucPY.js} +845 -208
- package/dist/chunks/pers-sdk-BtvhucPY.js.map +1 -0
- package/dist/chunks/{pers-sdk-BQw3QUWR.cjs → pers-sdk-D4XVDZk3.cjs} +847 -209
- package/dist/chunks/pers-sdk-D4XVDZk3.cjs.map +1 -0
- package/dist/chunks/{redemption-service-rMB6T2W5.cjs → redemption-service-C61Qr2vI.cjs} +34 -24
- package/dist/chunks/redemption-service-C61Qr2vI.cjs.map +1 -0
- package/dist/chunks/{redemption-service-D-hBqh42.js → redemption-service-C_UTTDag.js} +34 -24
- package/dist/chunks/redemption-service-C_UTTDag.js.map +1 -0
- package/dist/chunks/{transaction-request.builder-BpgtuMMq.cjs → transaction-request.builder-B7n7tc1e.cjs} +120 -70
- package/dist/chunks/transaction-request.builder-B7n7tc1e.cjs.map +1 -0
- package/dist/chunks/{transaction-request.builder-C1vVVFto.js → transaction-request.builder-VbJpI34c.js} +121 -71
- package/dist/chunks/transaction-request.builder-VbJpI34c.js.map +1 -0
- package/dist/core/auth/api/auth-api.d.ts +1 -4
- package/dist/core/auth/api/auth-api.d.ts.map +1 -1
- package/dist/core/auth/index.d.ts +1 -1
- package/dist/core/auth/index.d.ts.map +1 -1
- package/dist/core/auth/services/auth-service.d.ts +1 -4
- package/dist/core/auth/services/auth-service.d.ts.map +1 -1
- package/dist/core/pers-api-client.d.ts.map +1 -1
- package/dist/core.cjs +6 -4
- package/dist/core.cjs.map +1 -1
- package/dist/core.js +5 -4
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +14 -6
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -5
- package/dist/index.js.map +1 -1
- package/dist/managers/analytics-manager.d.ts +165 -2
- package/dist/managers/analytics-manager.d.ts.map +1 -1
- package/dist/managers/auth-manager.d.ts +1 -2
- package/dist/managers/auth-manager.d.ts.map +1 -1
- package/dist/managers/campaign-manager.d.ts +186 -50
- package/dist/managers/campaign-manager.d.ts.map +1 -1
- package/dist/managers/index.d.ts +1 -0
- package/dist/managers/index.d.ts.map +1 -1
- package/dist/managers/redemption-manager.d.ts +50 -3
- package/dist/managers/redemption-manager.d.ts.map +1 -1
- package/dist/managers/transaction-manager.d.ts +70 -132
- package/dist/managers/transaction-manager.d.ts.map +1 -1
- package/dist/managers/trigger-source-manager.d.ts +185 -0
- package/dist/managers/trigger-source-manager.d.ts.map +1 -0
- package/dist/managers/user-manager.d.ts +30 -7
- package/dist/managers/user-manager.d.ts.map +1 -1
- package/dist/node.cjs +5 -4
- package/dist/node.cjs.map +1 -1
- package/dist/node.js +5 -4
- package/dist/node.js.map +1 -1
- package/dist/package.json +7 -2
- package/dist/pers-sdk.d.ts +33 -2
- package/dist/pers-sdk.d.ts.map +1 -1
- package/dist/redemption/api/redemption-api.d.ts +10 -18
- package/dist/redemption/api/redemption-api.d.ts.map +1 -1
- package/dist/redemption/index.d.ts +1 -0
- package/dist/redemption/index.d.ts.map +1 -1
- package/dist/redemption/models/index.d.ts +19 -0
- package/dist/redemption/models/index.d.ts.map +1 -1
- package/dist/redemption/services/redemption-service.d.ts +7 -3
- package/dist/redemption/services/redemption-service.d.ts.map +1 -1
- package/dist/redemption.cjs +1 -1
- package/dist/redemption.js +1 -1
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/transaction/api/transaction-api.d.ts +38 -42
- package/dist/transaction/api/transaction-api.d.ts.map +1 -1
- package/dist/transaction/index.d.ts +2 -1
- package/dist/transaction/index.d.ts.map +1 -1
- package/dist/transaction/models/index.d.ts +21 -0
- package/dist/transaction/models/index.d.ts.map +1 -1
- package/dist/transaction/services/transaction-service.d.ts +12 -15
- package/dist/transaction/services/transaction-service.d.ts.map +1 -1
- package/dist/transaction.cjs +1 -1
- package/dist/transaction.js +1 -1
- package/dist/trigger-source/api/trigger-source-api.d.ts +86 -0
- package/dist/trigger-source/api/trigger-source-api.d.ts.map +1 -0
- package/dist/trigger-source/index.d.ts +10 -0
- package/dist/trigger-source/index.d.ts.map +1 -0
- package/dist/trigger-source/models/index.d.ts +26 -0
- package/dist/trigger-source/models/index.d.ts.map +1 -0
- package/dist/trigger-source/services/trigger-source-service.d.ts +42 -0
- package/dist/trigger-source/services/trigger-source-service.d.ts.map +1 -0
- package/dist/trigger-source.cjs +145 -0
- package/dist/trigger-source.cjs.map +1 -0
- package/dist/trigger-source.js +142 -0
- package/dist/trigger-source.js.map +1 -0
- package/dist/user/api/user-api.d.ts +18 -1
- package/dist/user/api/user-api.d.ts.map +1 -1
- package/dist/user/services/user-service.d.ts +3 -1
- package/dist/user/services/user-service.d.ts.map +1 -1
- package/dist/user.cjs +26 -4
- package/dist/user.cjs.map +1 -1
- package/dist/user.js +26 -4
- package/dist/user.js.map +1 -1
- package/package.json +7 -2
- package/dist/chunks/pers-sdk-BQw3QUWR.cjs.map +0 -1
- package/dist/chunks/pers-sdk-fWg-J3_h.js.map +0 -1
- package/dist/chunks/redemption-service-D-hBqh42.js.map +0 -1
- package/dist/chunks/redemption-service-rMB6T2W5.cjs.map +0 -1
- package/dist/chunks/transaction-request.builder-BpgtuMMq.cjs.map +0 -1
- package/dist/chunks/transaction-request.builder-C1vVVFto.js.map +0 -1
|
@@ -5,13 +5,14 @@ import { createUserStatusSDK } from '../user-status.js';
|
|
|
5
5
|
import { a as TokenService, T as TokenApi } from './token-service-Bfj6C0yz.js';
|
|
6
6
|
import { B as BusinessApi, b as BusinessService, a as BusinessMembershipApi, c as BusinessMembershipService } from './business-membership-service-D6vaVQTR.js';
|
|
7
7
|
import { CampaignService, CampaignApi } from '../campaign.js';
|
|
8
|
-
import { a as RedemptionService, R as RedemptionApi } from './redemption-service-
|
|
9
|
-
import { a as TransactionService, T as TransactionApi } from './transaction-request.builder-
|
|
8
|
+
import { a as RedemptionService, R as RedemptionApi } from './redemption-service-C_UTTDag.js';
|
|
9
|
+
import { a as TransactionService, T as TransactionApi } from './transaction-request.builder-VbJpI34c.js';
|
|
10
10
|
import { a as PaymentService, P as PurchaseApi } from './payment-service-IvM6rryM.js';
|
|
11
11
|
import { a as TenantService, T as TenantApi } from './tenant-service-CsRA3O2V.js';
|
|
12
12
|
import { b as buildPaginationParams, n as normalizeToPaginated } from './pagination-utils-9vQ-Npkr.js';
|
|
13
|
-
import { AnalyticsService, AnalyticsApi } from '
|
|
13
|
+
import { a as AnalyticsService, A as AnalyticsApi } from './analytics-service-B9IfG6ox.js';
|
|
14
14
|
import { DonationService, DonationApi } from '../donation.js';
|
|
15
|
+
import { TriggerSourceService, TriggerSourceApi } from '../trigger-source.js';
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* PERS SDK Configuration interfaces and utilities
|
|
@@ -96,10 +97,7 @@ class AuthApi {
|
|
|
96
97
|
* Authenticates a user in a business context with role included in JWT.
|
|
97
98
|
*
|
|
98
99
|
* @param jwt - Authentication token (passkey or Firebase JWT)
|
|
99
|
-
* @param options - Business authentication options
|
|
100
|
-
* @param options.businessId - The business ID to authenticate as
|
|
101
|
-
* - If user has single business membership, auto-selected
|
|
102
|
-
* - If user has multiple memberships without businessId, throws MULTIPLE_CONTEXT_SELECTION_REQUIRED
|
|
100
|
+
* @param options - Business authentication options (businessId for multi-business users, auto-selected if single membership)
|
|
103
101
|
* @returns Session response with business context and role in JWT
|
|
104
102
|
* @throws MultipleContextSelectionError when businessId is required but not provided
|
|
105
103
|
*
|
|
@@ -218,10 +216,7 @@ class AuthService {
|
|
|
218
216
|
* the user's role within that business.
|
|
219
217
|
*
|
|
220
218
|
* @param jwt - Authentication token (passkey or Firebase JWT)
|
|
221
|
-
* @param options - Business authentication options
|
|
222
|
-
* @param options.businessId - The business ID to authenticate as
|
|
223
|
-
* - If user has single business membership, auto-selected
|
|
224
|
-
* - If user has multiple memberships without businessId, throws MULTIPLE_CONTEXT_SELECTION_REQUIRED
|
|
219
|
+
* @param options - Business authentication options (businessId for multi-business users)
|
|
225
220
|
* @returns Session response with business context and role baked into JWT
|
|
226
221
|
* @throws MultipleContextSelectionRequiredError when businessId is required but not provided
|
|
227
222
|
*
|
|
@@ -1112,13 +1107,15 @@ class PersApiClient {
|
|
|
1112
1107
|
* @internal
|
|
1113
1108
|
*/
|
|
1114
1109
|
emitErrorEvent(errorDetails, errorMessage, endpoint, method, status, error) {
|
|
1115
|
-
console.log('[PersApiClient] emitErrorEvent called', {
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1110
|
+
/* console.log('[PersApiClient] emitErrorEvent called', {
|
|
1111
|
+
hasEvents: !!this._events,
|
|
1112
|
+
instanceId: this._events?.instanceId ?? 'none',
|
|
1113
|
+
subscriberCount: this._events?.subscriberCount ?? 0,
|
|
1114
|
+
domain: errorDetails.domain,
|
|
1115
|
+
code: errorDetails.code,
|
|
1116
|
+
status: status,
|
|
1117
|
+
message: errorDetails.message || errorMessage
|
|
1118
|
+
}); */
|
|
1122
1119
|
this._events?.emitError({
|
|
1123
1120
|
domain: errorDetails.domain || 'external',
|
|
1124
1121
|
type: errorDetails.code || 'API_ERROR',
|
|
@@ -1653,8 +1650,7 @@ class AuthManager {
|
|
|
1653
1650
|
* throws `MULTIPLE_CONTEXT_SELECTION_REQUIRED` error with available options
|
|
1654
1651
|
*
|
|
1655
1652
|
* @param jwtToken - JWT token from auth provider (passkey, Firebase, etc.)
|
|
1656
|
-
* @param options - Business authentication options
|
|
1657
|
-
* @param options.businessId - The business ID to authenticate as (required for multi-business users)
|
|
1653
|
+
* @param options - Business authentication options (businessId for multi-business users)
|
|
1658
1654
|
* @returns Promise resolving to authentication response with business context and role in JWT
|
|
1659
1655
|
* @throws Error with code `MULTIPLE_CONTEXT_SELECTION_REQUIRED` when businessId is needed
|
|
1660
1656
|
*
|
|
@@ -2081,26 +2077,49 @@ class UserManager {
|
|
|
2081
2077
|
* requires administrator privileges and returns full user profiles including
|
|
2082
2078
|
* private information.
|
|
2083
2079
|
*
|
|
2084
|
-
* @
|
|
2080
|
+
* @param options - Pagination options (page, limit, sortBy, sortOrder)
|
|
2081
|
+
* @param search - Optional search query to filter users
|
|
2082
|
+
* @returns Promise resolving to paginated users with complete data
|
|
2085
2083
|
* @throws {PersApiError} When not authenticated as admin
|
|
2086
2084
|
*
|
|
2087
|
-
* @example
|
|
2085
|
+
* @example Basic Usage
|
|
2088
2086
|
* ```typescript
|
|
2089
2087
|
* // Admin operation - requires admin authentication
|
|
2090
2088
|
* try {
|
|
2091
|
-
* const
|
|
2092
|
-
* console.log(`Total users: ${
|
|
2089
|
+
* const result = await sdk.users.getAllUsers();
|
|
2090
|
+
* console.log(`Total users: ${result.pagination.total}`);
|
|
2093
2091
|
*
|
|
2094
|
-
*
|
|
2095
|
-
* console.log(`${user.
|
|
2092
|
+
* result.data.forEach(user => {
|
|
2093
|
+
* console.log(`${user.firstName} - ${user.email} - Active: ${user.isActive}`);
|
|
2096
2094
|
* });
|
|
2097
2095
|
* } catch (error) {
|
|
2098
2096
|
* console.log('Admin access required');
|
|
2099
2097
|
* }
|
|
2100
2098
|
* ```
|
|
2099
|
+
*
|
|
2100
|
+
* @example With Sorting
|
|
2101
|
+
* ```typescript
|
|
2102
|
+
* import { SortOrder } from '@explorins/pers-sdk';
|
|
2103
|
+
*
|
|
2104
|
+
* // Get users sorted by email ascending
|
|
2105
|
+
* const result = await sdk.users.getAllUsers({
|
|
2106
|
+
* page: 1,
|
|
2107
|
+
* limit: 20,
|
|
2108
|
+
* sortBy: 'email',
|
|
2109
|
+
* sortOrder: SortOrder.ASC
|
|
2110
|
+
* });
|
|
2111
|
+
*
|
|
2112
|
+
* // Get users sorted by creation date (newest first)
|
|
2113
|
+
* const recent = await sdk.users.getAllUsers({
|
|
2114
|
+
* page: 1,
|
|
2115
|
+
* limit: 10,
|
|
2116
|
+
* sortBy: 'createdAt',
|
|
2117
|
+
* sortOrder: SortOrder.DESC
|
|
2118
|
+
* });
|
|
2119
|
+
* ```
|
|
2101
2120
|
*/
|
|
2102
|
-
async getAllUsers(options) {
|
|
2103
|
-
return this.userService.getAllRemoteUsers(options);
|
|
2121
|
+
async getAllUsers(options, search) {
|
|
2122
|
+
return this.userService.getAllRemoteUsers(options, search);
|
|
2104
2123
|
}
|
|
2105
2124
|
/**
|
|
2106
2125
|
* Business/Admin: Create or update a user
|
|
@@ -3265,6 +3284,7 @@ class CampaignManager {
|
|
|
3265
3284
|
* business partnerships, eligibility criteria, and claiming requirements.
|
|
3266
3285
|
*
|
|
3267
3286
|
* @param campaignId - Unique campaign identifier
|
|
3287
|
+
* @param include - Relations to include: 'triggerSources', 'businesses'
|
|
3268
3288
|
* @returns Promise resolving to campaign data with complete details
|
|
3269
3289
|
* @throws {PersApiError} When campaign with specified ID is not found
|
|
3270
3290
|
*
|
|
@@ -3293,9 +3313,17 @@ class CampaignManager {
|
|
|
3293
3313
|
* console.log('Campaign not found:', error.message);
|
|
3294
3314
|
* }
|
|
3295
3315
|
* ```
|
|
3316
|
+
*
|
|
3317
|
+
* @example With Include Relations
|
|
3318
|
+
* ```typescript
|
|
3319
|
+
* // Get campaign with trigger sources and businesses included
|
|
3320
|
+
* const campaign = await sdk.campaigns.getCampaignById('campaign-123', ['triggerSources', 'businesses']);
|
|
3321
|
+
* console.log('Trigger sources:', campaign.included?.triggerSources);
|
|
3322
|
+
* console.log('Businesses:', campaign.included?.businesses);
|
|
3323
|
+
* ```
|
|
3296
3324
|
*/
|
|
3297
|
-
async getCampaignById(campaignId) {
|
|
3298
|
-
return this.campaignService.getCampaignById(campaignId);
|
|
3325
|
+
async getCampaignById(campaignId, include) {
|
|
3326
|
+
return this.campaignService.getCampaignById(campaignId, include);
|
|
3299
3327
|
}
|
|
3300
3328
|
/**
|
|
3301
3329
|
* Claim a campaign reward
|
|
@@ -3401,7 +3429,8 @@ class CampaignManager {
|
|
|
3401
3429
|
* ```
|
|
3402
3430
|
*/
|
|
3403
3431
|
async getUserClaims(options) {
|
|
3404
|
-
|
|
3432
|
+
const { include, ...paginationOptions } = options || {};
|
|
3433
|
+
return this.campaignService.getClaimsForLoggedUser(paginationOptions, include);
|
|
3405
3434
|
}
|
|
3406
3435
|
/**
|
|
3407
3436
|
* Get campaigns with pagination support
|
|
@@ -3409,13 +3438,7 @@ class CampaignManager {
|
|
|
3409
3438
|
* Returns campaigns with pagination metadata for efficient data loading.
|
|
3410
3439
|
* Intelligent access: Public gets active only, Business gets own campaigns, Admin gets all.
|
|
3411
3440
|
*
|
|
3412
|
-
* @param options - Pagination and filter options
|
|
3413
|
-
* @param options.active - Filter by active status (true/false/undefined for all)
|
|
3414
|
-
* @param options.businessId - Filter by business engagement
|
|
3415
|
-
* @param options.page - Page number (1-based, default: 1)
|
|
3416
|
-
* @param options.limit - Items per page (default: 50)
|
|
3417
|
-
* @param options.sortBy - Sort field ('name', 'createdAt', 'startDate')
|
|
3418
|
-
* @param options.sortOrder - Sort direction ('ASC' or 'DESC')
|
|
3441
|
+
* @param options - Pagination and filter options (page, limit, sortBy, sortOrder, active, businessId, include)
|
|
3419
3442
|
* @returns Promise resolving to paginated campaigns with metadata
|
|
3420
3443
|
*
|
|
3421
3444
|
* @example
|
|
@@ -3440,6 +3463,11 @@ class CampaignManager {
|
|
|
3440
3463
|
* page: 1,
|
|
3441
3464
|
* limit: 25
|
|
3442
3465
|
* });
|
|
3466
|
+
*
|
|
3467
|
+
* // Include related data (trigger sources and businesses)
|
|
3468
|
+
* const campaignsWithRelations = await sdk.campaigns.getCampaigns({
|
|
3469
|
+
* include: ['triggerSources', 'businesses']
|
|
3470
|
+
* });
|
|
3443
3471
|
* ```
|
|
3444
3472
|
*/
|
|
3445
3473
|
async getCampaigns(options) {
|
|
@@ -3557,57 +3585,188 @@ class CampaignManager {
|
|
|
3557
3585
|
async toggleCampaignTestnet(campaignId) {
|
|
3558
3586
|
return this.campaignService.toggleCampaignTestnet(campaignId);
|
|
3559
3587
|
}
|
|
3588
|
+
// ==========================================
|
|
3589
|
+
// CAMPAIGN TRIGGER OPERATIONS
|
|
3590
|
+
// Rules & limits for campaign activation
|
|
3591
|
+
// ==========================================
|
|
3560
3592
|
/**
|
|
3561
|
-
* Admin: Get campaign triggers
|
|
3593
|
+
* Admin: Get all campaign triggers (paginated)
|
|
3562
3594
|
*
|
|
3563
|
-
* Retrieves all
|
|
3564
|
-
*
|
|
3565
|
-
* Requires administrator privileges.
|
|
3595
|
+
* Retrieves all campaign trigger rules that define rate limits, geo-validation,
|
|
3596
|
+
* conditions, and trigger types for campaign activation.
|
|
3566
3597
|
*
|
|
3567
|
-
* @
|
|
3598
|
+
* @param options - Pagination options
|
|
3599
|
+
* @returns Promise resolving to paginated list of campaign triggers
|
|
3568
3600
|
*
|
|
3569
3601
|
* @example
|
|
3570
3602
|
* ```typescript
|
|
3571
|
-
*
|
|
3572
|
-
*
|
|
3573
|
-
*
|
|
3574
|
-
*
|
|
3575
|
-
* triggers.forEach(trigger => {
|
|
3576
|
-
* console.log(`- ${trigger.name}: ${trigger.description}`);
|
|
3577
|
-
* console.log(` Type: ${trigger.type}`);
|
|
3578
|
-
* console.log(` Parameters: ${JSON.stringify(trigger.parameters)}`);
|
|
3603
|
+
* const triggers = await sdk.campaigns.getCampaignTriggers({ page: 1, limit: 20 });
|
|
3604
|
+
* console.log(`Found ${triggers.total} triggers`);
|
|
3605
|
+
* triggers.data.forEach(trigger => {
|
|
3606
|
+
* console.log(`- ${trigger.name}: max ${trigger.maxPerDayPerUser}/day`);
|
|
3579
3607
|
* });
|
|
3580
3608
|
* ```
|
|
3581
3609
|
*/
|
|
3582
3610
|
async getCampaignTriggers(options) {
|
|
3583
|
-
return this.campaignService.getCampaignTriggers();
|
|
3611
|
+
return this.campaignService.getCampaignTriggers(options);
|
|
3612
|
+
}
|
|
3613
|
+
/**
|
|
3614
|
+
* Admin: Get campaign trigger by ID
|
|
3615
|
+
*
|
|
3616
|
+
* @param triggerId - The campaign trigger ID
|
|
3617
|
+
* @returns Promise resolving to the campaign trigger
|
|
3618
|
+
*
|
|
3619
|
+
* @example
|
|
3620
|
+
* ```typescript
|
|
3621
|
+
* const trigger = await sdk.campaigns.getCampaignTriggerById('trigger-123');
|
|
3622
|
+
* console.log('Max per day:', trigger.maxPerDayPerUser);
|
|
3623
|
+
* ```
|
|
3624
|
+
*/
|
|
3625
|
+
async getCampaignTriggerById(triggerId) {
|
|
3626
|
+
return this.campaignService.getCampaignTriggerById(triggerId);
|
|
3627
|
+
}
|
|
3628
|
+
/**
|
|
3629
|
+
* Admin: Create a new campaign trigger
|
|
3630
|
+
*
|
|
3631
|
+
* Creates a trigger rule that defines rate limits, geo-validation, and conditions
|
|
3632
|
+
* for campaign activation. Triggers are created independently and then assigned
|
|
3633
|
+
* to campaigns via `setCampaignTrigger()`.
|
|
3634
|
+
*
|
|
3635
|
+
* @param data - Trigger configuration
|
|
3636
|
+
* @returns Promise resolving to created trigger
|
|
3637
|
+
*
|
|
3638
|
+
* @example
|
|
3639
|
+
* ```typescript
|
|
3640
|
+
* const trigger = await sdk.campaigns.createCampaignTrigger({
|
|
3641
|
+
* name: 'Daily Check-in',
|
|
3642
|
+
* maxPerDayPerUser: 1,
|
|
3643
|
+
* maxPerUser: 100,
|
|
3644
|
+
* minCooldownSeconds: 3600,
|
|
3645
|
+
* maxGeoDistanceInMeters: 50,
|
|
3646
|
+
* triggerType: 'CLAIM_BY_USER'
|
|
3647
|
+
* });
|
|
3648
|
+
*
|
|
3649
|
+
* // Then assign to campaign
|
|
3650
|
+
* await sdk.campaigns.setCampaignTrigger(campaignId, trigger.id);
|
|
3651
|
+
* ```
|
|
3652
|
+
*/
|
|
3653
|
+
async createCampaignTrigger(data) {
|
|
3654
|
+
const result = await this.campaignService.createCampaignTrigger(data);
|
|
3655
|
+
this.events?.emitSuccess({
|
|
3656
|
+
domain: 'campaign',
|
|
3657
|
+
type: 'CAMPAIGN_TRIGGER_CREATED',
|
|
3658
|
+
userMessage: `Trigger "${data.name}" created successfully`,
|
|
3659
|
+
details: { triggerId: result.id, name: data.name }
|
|
3660
|
+
});
|
|
3661
|
+
return result;
|
|
3662
|
+
}
|
|
3663
|
+
/**
|
|
3664
|
+
* Admin: Update an existing campaign trigger
|
|
3665
|
+
*
|
|
3666
|
+
* @param triggerId - The campaign trigger ID
|
|
3667
|
+
* @param data - Updated trigger configuration (partial)
|
|
3668
|
+
* @returns Promise resolving to updated trigger
|
|
3669
|
+
*
|
|
3670
|
+
* @example
|
|
3671
|
+
* ```typescript
|
|
3672
|
+
* const updated = await sdk.campaigns.updateCampaignTrigger('trigger-123', {
|
|
3673
|
+
* maxPerDayPerUser: 5,
|
|
3674
|
+
* minCooldownSeconds: 1800
|
|
3675
|
+
* });
|
|
3676
|
+
* ```
|
|
3677
|
+
*/
|
|
3678
|
+
async updateCampaignTrigger(triggerId, data) {
|
|
3679
|
+
const result = await this.campaignService.updateCampaignTrigger(triggerId, data);
|
|
3680
|
+
this.events?.emitSuccess({
|
|
3681
|
+
domain: 'campaign',
|
|
3682
|
+
type: 'CAMPAIGN_TRIGGER_UPDATED',
|
|
3683
|
+
userMessage: 'Trigger updated successfully',
|
|
3684
|
+
details: { triggerId, updates: Object.keys(data) }
|
|
3685
|
+
});
|
|
3686
|
+
return result;
|
|
3584
3687
|
}
|
|
3585
3688
|
/**
|
|
3586
|
-
* Admin:
|
|
3689
|
+
* Admin: Delete a campaign trigger
|
|
3587
3690
|
*
|
|
3588
|
-
*
|
|
3589
|
-
*
|
|
3691
|
+
* @param triggerId - The campaign trigger ID
|
|
3692
|
+
* @returns Promise resolving to success status
|
|
3693
|
+
*
|
|
3694
|
+
* @example
|
|
3695
|
+
* ```typescript
|
|
3696
|
+
* await sdk.campaigns.deleteCampaignTrigger('trigger-123');
|
|
3697
|
+
* ```
|
|
3698
|
+
*/
|
|
3699
|
+
async deleteCampaignTrigger(triggerId) {
|
|
3700
|
+
const result = await this.campaignService.deleteCampaignTrigger(triggerId);
|
|
3701
|
+
this.events?.emitSuccess({
|
|
3702
|
+
domain: 'campaign',
|
|
3703
|
+
type: 'CAMPAIGN_TRIGGER_DELETED',
|
|
3704
|
+
userMessage: 'Trigger deleted successfully',
|
|
3705
|
+
details: { triggerId }
|
|
3706
|
+
});
|
|
3707
|
+
return result;
|
|
3708
|
+
}
|
|
3709
|
+
/**
|
|
3710
|
+
* Admin: Assign a trigger to a campaign
|
|
3711
|
+
*
|
|
3712
|
+
* Associates a trigger rule with a campaign. A campaign can have only one trigger
|
|
3713
|
+
* at a time. Assigning a new trigger replaces any existing trigger.
|
|
3590
3714
|
*
|
|
3591
3715
|
* @param campaignId - ID of the campaign
|
|
3592
3716
|
* @param triggerId - ID of the trigger to associate
|
|
3593
|
-
* @returns Promise resolving to updated campaign
|
|
3594
|
-
* @throws {PersApiError} When not authenticated as admin or entities not found
|
|
3717
|
+
* @returns Promise resolving to updated campaign
|
|
3595
3718
|
*
|
|
3596
3719
|
* @example
|
|
3597
3720
|
* ```typescript
|
|
3598
|
-
* // Admin operation - set up automatic campaign trigger
|
|
3599
3721
|
* const updated = await sdk.campaigns.setCampaignTrigger(
|
|
3600
|
-
* '
|
|
3601
|
-
* '
|
|
3722
|
+
* 'campaign-123',
|
|
3723
|
+
* 'trigger-456'
|
|
3602
3724
|
* );
|
|
3603
|
-
*
|
|
3604
|
-
* console.log('Trigger set for campaign:', updated.title);
|
|
3605
|
-
* console.log('Trigger will activate on user registration');
|
|
3725
|
+
* console.log('Trigger assigned:', updated.trigger?.name);
|
|
3606
3726
|
* ```
|
|
3607
3727
|
*/
|
|
3608
3728
|
async setCampaignTrigger(campaignId, triggerId) {
|
|
3609
|
-
|
|
3729
|
+
const result = await this.campaignService.setCampaignTrigger(campaignId, triggerId);
|
|
3730
|
+
this.events?.emitSuccess({
|
|
3731
|
+
domain: 'campaign',
|
|
3732
|
+
type: 'CAMPAIGN_TRIGGER_ASSIGNED',
|
|
3733
|
+
userMessage: 'Trigger assigned to campaign',
|
|
3734
|
+
details: { campaignId, triggerId }
|
|
3735
|
+
});
|
|
3736
|
+
return result;
|
|
3737
|
+
}
|
|
3738
|
+
/**
|
|
3739
|
+
* Admin: Remove a trigger from a campaign
|
|
3740
|
+
*
|
|
3741
|
+
* Removes the trigger rule from a campaign. The trigger itself is not deleted
|
|
3742
|
+
* and can be reassigned to other campaigns.
|
|
3743
|
+
*
|
|
3744
|
+
* @param campaignId - ID of the campaign
|
|
3745
|
+
* @param triggerId - ID of the trigger to remove
|
|
3746
|
+
* @returns Promise resolving to updated campaign
|
|
3747
|
+
*
|
|
3748
|
+
* @example
|
|
3749
|
+
* ```typescript
|
|
3750
|
+
* const updated = await sdk.campaigns.removeCampaignTrigger(
|
|
3751
|
+
* 'campaign-123',
|
|
3752
|
+
* 'trigger-456'
|
|
3753
|
+
* );
|
|
3754
|
+
* console.log('Trigger removed:', updated.trigger === null);
|
|
3755
|
+
* ```
|
|
3756
|
+
*/
|
|
3757
|
+
async removeCampaignTrigger(campaignId, triggerId) {
|
|
3758
|
+
const result = await this.campaignService.removeCampaignTrigger(campaignId, triggerId);
|
|
3759
|
+
this.events?.emitSuccess({
|
|
3760
|
+
domain: 'campaign',
|
|
3761
|
+
type: 'CAMPAIGN_TRIGGER_REMOVED',
|
|
3762
|
+
userMessage: 'Trigger removed from campaign',
|
|
3763
|
+
details: { campaignId, triggerId }
|
|
3764
|
+
});
|
|
3765
|
+
return result;
|
|
3610
3766
|
}
|
|
3767
|
+
// ==========================================
|
|
3768
|
+
// TOKEN UNIT OPERATIONS
|
|
3769
|
+
// ==========================================
|
|
3611
3770
|
/**
|
|
3612
3771
|
* Admin: Create campaign token unit
|
|
3613
3772
|
*
|
|
@@ -3816,8 +3975,8 @@ class CampaignManager {
|
|
|
3816
3975
|
* });
|
|
3817
3976
|
* ```
|
|
3818
3977
|
*/
|
|
3819
|
-
async getCampaignClaims(filters) {
|
|
3820
|
-
return this.campaignService.getCampaignClaims(filters);
|
|
3978
|
+
async getCampaignClaims(filters, include) {
|
|
3979
|
+
return this.campaignService.getCampaignClaims(filters, include);
|
|
3821
3980
|
}
|
|
3822
3981
|
/**
|
|
3823
3982
|
* Admin: Get campaign claims by user ID
|
|
@@ -3852,8 +4011,8 @@ class CampaignManager {
|
|
|
3852
4011
|
* console.log(`\nTotal rewards earned: ${totalRewards}`);
|
|
3853
4012
|
* ```
|
|
3854
4013
|
*/
|
|
3855
|
-
async getCampaignClaimsByUserId(userId, options) {
|
|
3856
|
-
return this.campaignService.getCampaignClaimsByUserId(userId);
|
|
4014
|
+
async getCampaignClaimsByUserId(userId, options, include) {
|
|
4015
|
+
return this.campaignService.getCampaignClaimsByUserId(userId, options, include);
|
|
3857
4016
|
}
|
|
3858
4017
|
/**
|
|
3859
4018
|
* Admin: Get campaign claims by business ID
|
|
@@ -3893,8 +4052,79 @@ class CampaignManager {
|
|
|
3893
4052
|
* console.log(`\nTotal rewards distributed: ${totalRewardsDistributed}`);
|
|
3894
4053
|
* ```
|
|
3895
4054
|
*/
|
|
3896
|
-
async getCampaignClaimsByBusinessId(businessId, options) {
|
|
3897
|
-
return this.campaignService.getCampaignClaimsByBusinessId(businessId);
|
|
4055
|
+
async getCampaignClaimsByBusinessId(businessId, options, include) {
|
|
4056
|
+
return this.campaignService.getCampaignClaimsByBusinessId(businessId, options, include);
|
|
4057
|
+
}
|
|
4058
|
+
// ==========================================
|
|
4059
|
+
// TRIGGER SOURCE ASSIGNMENT
|
|
4060
|
+
// Note: TriggerSource CRUD is in TriggerSourceManager (sdk.triggerSources)
|
|
4061
|
+
// ==========================================
|
|
4062
|
+
/**
|
|
4063
|
+
* Admin: Assign a trigger source to a campaign
|
|
4064
|
+
*
|
|
4065
|
+
* Associates a trigger source with a campaign, enabling the trigger source
|
|
4066
|
+
* to activate campaign rewards when triggered. A campaign can have multiple
|
|
4067
|
+
* trigger sources. Requires administrator privileges.
|
|
4068
|
+
*
|
|
4069
|
+
* Note: To create/update/delete trigger sources, use `sdk.triggerSources`.
|
|
4070
|
+
*
|
|
4071
|
+
* @param campaignId - Campaign UUID
|
|
4072
|
+
* @param triggerSourceId - Trigger source UUID
|
|
4073
|
+
* @returns Promise resolving to updated campaign with trigger source assigned
|
|
4074
|
+
* @throws {PersApiError} When not authenticated as admin or entities not found
|
|
4075
|
+
*
|
|
4076
|
+
* @example
|
|
4077
|
+
* ```typescript
|
|
4078
|
+
* // Create trigger source first
|
|
4079
|
+
* const source = await sdk.triggerSources.create({
|
|
4080
|
+
* type: 'QR_CODE',
|
|
4081
|
+
* name: 'Store Entrance QR'
|
|
4082
|
+
* });
|
|
4083
|
+
*
|
|
4084
|
+
* // Then assign to campaign
|
|
4085
|
+
* const updated = await sdk.campaigns.assignTriggerSource(
|
|
4086
|
+
* 'campaign-123',
|
|
4087
|
+
* source.id
|
|
4088
|
+
* );
|
|
4089
|
+
*
|
|
4090
|
+
* console.log('Trigger source assigned:', updated.triggerSourceIds.length);
|
|
4091
|
+
* ```
|
|
4092
|
+
*/
|
|
4093
|
+
async assignTriggerSource(campaignId, triggerSourceId) {
|
|
4094
|
+
const result = await this.campaignService.assignTriggerSourceToCampaign(campaignId, triggerSourceId);
|
|
4095
|
+
this.events?.emitSuccess({
|
|
4096
|
+
domain: 'campaign',
|
|
4097
|
+
type: 'TRIGGER_SOURCE_ASSIGNED',
|
|
4098
|
+
userMessage: 'Trigger source assigned to campaign',
|
|
4099
|
+
details: { campaignId, triggerSourceId }
|
|
4100
|
+
});
|
|
4101
|
+
return result;
|
|
4102
|
+
}
|
|
4103
|
+
/**
|
|
4104
|
+
* Admin: Remove a trigger source from a campaign
|
|
4105
|
+
*
|
|
4106
|
+
* Removes the association between a trigger source and a campaign. The trigger
|
|
4107
|
+
* source itself is not deleted and can be reassigned to other campaigns.
|
|
4108
|
+
* Requires administrator privileges.
|
|
4109
|
+
*
|
|
4110
|
+
* @param campaignId - Campaign UUID
|
|
4111
|
+
* @param triggerSourceId - Trigger source UUID
|
|
4112
|
+
* @returns Promise resolving to updated campaign with trigger source removed
|
|
4113
|
+
* @throws {PersApiError} When not authenticated as admin or entities not found
|
|
4114
|
+
*
|
|
4115
|
+
* @example
|
|
4116
|
+
* ```typescript
|
|
4117
|
+
* // Remove a trigger source from a campaign
|
|
4118
|
+
* const updated = await sdk.campaigns.removeTriggerSource(
|
|
4119
|
+
* 'campaign-123',
|
|
4120
|
+
* 'source-456'
|
|
4121
|
+
* );
|
|
4122
|
+
*
|
|
4123
|
+
* console.log('Remaining trigger source IDs:', updated.triggerSourceIds.length);
|
|
4124
|
+
* ```
|
|
4125
|
+
*/
|
|
4126
|
+
async removeTriggerSource(campaignId, triggerSourceId) {
|
|
4127
|
+
return this.campaignService.removeTriggerSourceFromCampaign(campaignId, triggerSourceId);
|
|
3898
4128
|
}
|
|
3899
4129
|
/**
|
|
3900
4130
|
* Get the full campaign service for advanced operations
|
|
@@ -4278,8 +4508,57 @@ class RedemptionManager {
|
|
|
4278
4508
|
* });
|
|
4279
4509
|
* ```
|
|
4280
4510
|
*/
|
|
4281
|
-
async getUserRedemptions(options) {
|
|
4282
|
-
return this.redemptionService.getUserRedeems(options);
|
|
4511
|
+
async getUserRedemptions(options, include) {
|
|
4512
|
+
return this.redemptionService.getUserRedeems(options, include);
|
|
4513
|
+
}
|
|
4514
|
+
/**
|
|
4515
|
+
* Admin: Get all redemption redeems with filtering and enriched data
|
|
4516
|
+
*
|
|
4517
|
+
* Retrieves all redemption redeems across the platform with filtering capabilities.
|
|
4518
|
+
* This is an admin-level operation that allows monitoring and analytics of redemption
|
|
4519
|
+
* activity. Supports filtering by user, redemption offer, and enrichment of related entities.
|
|
4520
|
+
*
|
|
4521
|
+
* @param filters - Filter options (userId, redemptionId, pagination)
|
|
4522
|
+
* @param include - Optional relations to include for enrichment
|
|
4523
|
+
* @returns Promise resolving to paginated list of redemption redeems
|
|
4524
|
+
* @throws {PersApiError} When not authenticated as admin
|
|
4525
|
+
*
|
|
4526
|
+
* @example Get All Redeems
|
|
4527
|
+
* ```typescript
|
|
4528
|
+
* // Admin operation - get all redemption redeems
|
|
4529
|
+
* const { data: allRedeems, pagination } = await sdk.redemptions.getRedemptionRedeems();
|
|
4530
|
+
*
|
|
4531
|
+
* console.log(`Total redeems: ${pagination.total}`);
|
|
4532
|
+
* console.log(`Page ${pagination.page} of ${pagination.pages}`);
|
|
4533
|
+
* ```
|
|
4534
|
+
*
|
|
4535
|
+
* @example Filter by User
|
|
4536
|
+
* ```typescript
|
|
4537
|
+
* // Get redeems for specific user
|
|
4538
|
+
* const { data: userRedeems } = await sdk.redemptions.getRedemptionRedeems({
|
|
4539
|
+
* userId: 'user-123',
|
|
4540
|
+
* limit: 50
|
|
4541
|
+
* });
|
|
4542
|
+
*
|
|
4543
|
+
* console.log(`User has ${userRedeems.length} redemptions`);
|
|
4544
|
+
* ```
|
|
4545
|
+
*
|
|
4546
|
+
* @example With Enriched Data
|
|
4547
|
+
* ```typescript
|
|
4548
|
+
* const { data: redeems } = await sdk.redemptions.getRedemptionRedeems(
|
|
4549
|
+
* { page: 1, limit: 20 },
|
|
4550
|
+
* ['redemption', 'user', 'business']
|
|
4551
|
+
* );
|
|
4552
|
+
*
|
|
4553
|
+
* redeems.forEach(redeem => {
|
|
4554
|
+
* const redemptionName = redeem.included?.redemption?.name || 'Unknown';
|
|
4555
|
+
* const userEmail = redeem.included?.user?.email || redeem.userId;
|
|
4556
|
+
* console.log(`${redemptionName} - ${userEmail}`);
|
|
4557
|
+
* });
|
|
4558
|
+
* ```
|
|
4559
|
+
*/
|
|
4560
|
+
async getRedemptionRedeems(filters, include) {
|
|
4561
|
+
return this.redemptionService.getRedemptionRedeems(filters, include);
|
|
4283
4562
|
}
|
|
4284
4563
|
/**
|
|
4285
4564
|
* Admin: Create new redemption offer
|
|
@@ -4522,8 +4801,8 @@ class RedemptionManager {
|
|
|
4522
4801
|
*
|
|
4523
4802
|
* @example Administrative Reporting
|
|
4524
4803
|
* ```typescript
|
|
4525
|
-
* // Admin: Get
|
|
4526
|
-
* const allTransactions = await sdk.transactions.
|
|
4804
|
+
* // Admin: Get paginated transactions for analysis
|
|
4805
|
+
* const allTransactions = await sdk.transactions.getPaginatedTransactions({ page: 1, limit: 100 });
|
|
4527
4806
|
*
|
|
4528
4807
|
* // Export transaction data
|
|
4529
4808
|
* const csvBlob = await sdk.transactions.exportTransactionsCSV();
|
|
@@ -4546,13 +4825,18 @@ class TransactionManager {
|
|
|
4546
4825
|
* Provides complete transaction audit trail and verification data.
|
|
4547
4826
|
*
|
|
4548
4827
|
* @param transactionId - Unique transaction identifier
|
|
4828
|
+
* @param include - Optional relations to include (sender, recipient, business) for enriched entity data
|
|
4549
4829
|
* @returns Promise resolving to complete transaction data
|
|
4550
4830
|
* @throws {PersApiError} When transaction with specified ID is not found or access denied
|
|
4551
4831
|
*
|
|
4552
4832
|
* @example
|
|
4553
4833
|
* ```typescript
|
|
4554
4834
|
* try {
|
|
4555
|
-
*
|
|
4835
|
+
* // Get transaction with enriched sender/recipient data
|
|
4836
|
+
* const transaction = await sdk.transactions.getTransactionById(
|
|
4837
|
+
* 'txn-abc123',
|
|
4838
|
+
* ['sender', 'recipient', 'business']
|
|
4839
|
+
* );
|
|
4556
4840
|
*
|
|
4557
4841
|
* console.log('Transaction Details:');
|
|
4558
4842
|
* console.log('ID:', transaction.id);
|
|
@@ -4565,16 +4849,19 @@ class TransactionManager {
|
|
|
4565
4849
|
* console.log('Description:', transaction.description);
|
|
4566
4850
|
* }
|
|
4567
4851
|
*
|
|
4568
|
-
*
|
|
4569
|
-
*
|
|
4852
|
+
* // Access enriched sender data
|
|
4853
|
+
* if (transaction.included?.sender) {
|
|
4854
|
+
* console.log('Sender:', transaction.included.sender);
|
|
4570
4855
|
* }
|
|
4571
4856
|
*
|
|
4572
|
-
* //
|
|
4573
|
-
* if (transaction.
|
|
4574
|
-
* console.log('
|
|
4575
|
-
*
|
|
4576
|
-
*
|
|
4577
|
-
*
|
|
4857
|
+
* // Access enriched recipient data
|
|
4858
|
+
* if (transaction.included?.recipient) {
|
|
4859
|
+
* console.log('Recipient:', transaction.included.recipient);
|
|
4860
|
+
* }
|
|
4861
|
+
*
|
|
4862
|
+
* // Access enriched business data
|
|
4863
|
+
* if (transaction.included?.engagedBusiness) {
|
|
4864
|
+
* console.log('Business:', transaction.included.engagedBusiness.displayName);
|
|
4578
4865
|
* }
|
|
4579
4866
|
*
|
|
4580
4867
|
* // Show blockchain confirmation
|
|
@@ -4587,8 +4874,8 @@ class TransactionManager {
|
|
|
4587
4874
|
* }
|
|
4588
4875
|
* ```
|
|
4589
4876
|
*/
|
|
4590
|
-
async getTransactionById(transactionId) {
|
|
4591
|
-
return this.transactionService.getTransactionById(transactionId);
|
|
4877
|
+
async getTransactionById(transactionId, include) {
|
|
4878
|
+
return this.transactionService.getTransactionById(transactionId, include);
|
|
4592
4879
|
}
|
|
4593
4880
|
/**
|
|
4594
4881
|
* Create a new transaction
|
|
@@ -4682,150 +4969,62 @@ class TransactionManager {
|
|
|
4682
4969
|
/**
|
|
4683
4970
|
* Get user's transaction history
|
|
4684
4971
|
*
|
|
4685
|
-
* Retrieves transaction history for the authenticated user
|
|
4686
|
-
*
|
|
4972
|
+
* Retrieves transaction history for the authenticated user with comprehensive
|
|
4973
|
+
* filtering options. Provides chronological view of all user's loyalty
|
|
4687
4974
|
* activities including purchases, rewards, redemptions, and transfers.
|
|
4975
|
+
* Optionally enrich with related entities (sender, recipient, business).
|
|
4688
4976
|
*
|
|
4689
|
-
* @param
|
|
4690
|
-
* @
|
|
4691
|
-
* @returns Promise resolving to array of user's transactions
|
|
4977
|
+
* @param options - Query options including filters, pagination, and include relations
|
|
4978
|
+
* @returns Promise resolving to paginated transaction data with optional included entities
|
|
4692
4979
|
*
|
|
4693
4980
|
* @example All Transactions
|
|
4694
4981
|
* ```typescript
|
|
4695
|
-
* const
|
|
4982
|
+
* const result = await sdk.transactions.getUserTransactionHistory();
|
|
4696
4983
|
*
|
|
4697
|
-
* console.log(`
|
|
4984
|
+
* console.log(`Transaction History (${result.data.length} of ${result.pagination.total} transactions)`);
|
|
4698
4985
|
*
|
|
4699
|
-
*
|
|
4986
|
+
* result.data.forEach((transaction, index) => {
|
|
4700
4987
|
* const date = new Date(transaction.createdAt).toLocaleDateString();
|
|
4701
4988
|
* console.log(`\n${index + 1}. ${transaction.type} - ${date}`);
|
|
4702
4989
|
* console.log(` ${transaction.description || 'No description'}`);
|
|
4703
4990
|
* console.log(` Status: ${transaction.status}`);
|
|
4704
|
-
*
|
|
4705
|
-
* if (transaction.amount && transaction.currency) {
|
|
4706
|
-
* console.log(` Amount: ${transaction.amount} ${transaction.currency}`);
|
|
4707
|
-
* }
|
|
4708
|
-
*
|
|
4709
|
-
* if (transaction.business) {
|
|
4710
|
-
* console.log(` Business: ${transaction.business.displayName}`);
|
|
4711
|
-
* }
|
|
4712
4991
|
* });
|
|
4713
4992
|
* ```
|
|
4714
4993
|
*
|
|
4715
|
-
* @example
|
|
4994
|
+
* @example Filter by Role and Status
|
|
4716
4995
|
* ```typescript
|
|
4717
|
-
* // Get only
|
|
4718
|
-
* const
|
|
4719
|
-
*
|
|
4720
|
-
*
|
|
4721
|
-
*
|
|
4722
|
-
*
|
|
4723
|
-
*
|
|
4724
|
-
* if (purchase.amount) {
|
|
4725
|
-
* totalSpent += purchase.amount;
|
|
4726
|
-
* }
|
|
4727
|
-
*
|
|
4728
|
-
* if (purchase.tokensEarned?.length) {
|
|
4729
|
-
* purchase.tokensEarned.forEach(reward => {
|
|
4730
|
-
* totalRewards += reward.amount;
|
|
4731
|
-
* });
|
|
4732
|
-
* }
|
|
4996
|
+
* // Get only completed sent transactions
|
|
4997
|
+
* const sent = await sdk.transactions.getUserTransactionHistory({
|
|
4998
|
+
* role: TransactionRole.SENDER,
|
|
4999
|
+
* status: TransactionStatus.COMPLETED,
|
|
5000
|
+
* include: ['recipient', 'business'],
|
|
5001
|
+
* page: 1,
|
|
5002
|
+
* limit: 50
|
|
4733
5003
|
* });
|
|
4734
5004
|
*
|
|
4735
|
-
*
|
|
4736
|
-
*
|
|
4737
|
-
* console.log(`Total spent: $${totalSpent.toFixed(2)}`);
|
|
4738
|
-
* console.log(`Total rewards earned: ${totalRewards} points`);
|
|
4739
|
-
* ```
|
|
4740
|
-
*
|
|
4741
|
-
* @example Recent Activity
|
|
4742
|
-
* ```typescript
|
|
4743
|
-
* const recentTransactions = await sdk.transactions.getUserTransactionHistory('ALL');
|
|
4744
|
-
*
|
|
4745
|
-
* // Filter to last 30 days
|
|
4746
|
-
* const thirtyDaysAgo = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000);
|
|
4747
|
-
* const recentActivity = recentTransactions.filter(t =>
|
|
4748
|
-
* new Date(t.createdAt) > thirtyDaysAgo
|
|
4749
|
-
* );
|
|
4750
|
-
*
|
|
4751
|
-
* console.log(`Recent Activity (${recentActivity.length} transactions in last 30 days):`);
|
|
4752
|
-
*
|
|
4753
|
-
* // Group by type
|
|
4754
|
-
* const activityByType = recentActivity.reduce((acc, t) => {
|
|
4755
|
-
* acc[t.type] = (acc[t.type] || 0) + 1;
|
|
4756
|
-
* return acc;
|
|
4757
|
-
* }, {});
|
|
4758
|
-
*
|
|
4759
|
-
* Object.entries(activityByType).forEach(([type, count]) => {
|
|
4760
|
-
* console.log(`${type}: ${count} transactions`);
|
|
5005
|
+
* sent.data.forEach(tx => {
|
|
5006
|
+
* console.log(`Sent to: ${tx.included?.recipient?.displayName || tx.recipientAddress}`);
|
|
4761
5007
|
* });
|
|
4762
5008
|
* ```
|
|
4763
|
-
*/
|
|
4764
|
-
async getUserTransactionHistory(role, options) {
|
|
4765
|
-
return this.transactionService.getUserTransactionHistory(role, options);
|
|
4766
|
-
}
|
|
4767
|
-
/**
|
|
4768
|
-
* Admin: Get all tenant transactions
|
|
4769
5009
|
*
|
|
4770
|
-
*
|
|
4771
|
-
* comprehensive reporting and analysis. This operation requires administrator
|
|
4772
|
-
* privileges and provides system-wide transaction visibility.
|
|
4773
|
-
*
|
|
4774
|
-
* @param limit - Maximum number of transactions to return (default: 1000)
|
|
4775
|
-
* @returns Promise resolving to array of all tenant transactions
|
|
4776
|
-
* @throws {PersApiError} When not authenticated as administrator
|
|
4777
|
-
*
|
|
4778
|
-
* @example
|
|
5010
|
+
* @example Filter by Trigger Process (Campaign/Redemption)
|
|
4779
5011
|
* ```typescript
|
|
4780
|
-
* //
|
|
4781
|
-
* const
|
|
4782
|
-
*
|
|
4783
|
-
*
|
|
4784
|
-
* console.log(`Total transactions: ${allTransactions.length}`);
|
|
4785
|
-
*
|
|
4786
|
-
* // Analyze by status
|
|
4787
|
-
* const statusCounts = allTransactions.reduce((acc, t) => {
|
|
4788
|
-
* acc[t.status] = (acc[t.status] || 0) + 1;
|
|
4789
|
-
* return acc;
|
|
4790
|
-
* }, {});
|
|
4791
|
-
*
|
|
4792
|
-
* console.log('\nBy status:');
|
|
4793
|
-
* Object.entries(statusCounts).forEach(([status, count]) => {
|
|
4794
|
-
* console.log(`${status}: ${count} transactions`);
|
|
5012
|
+
* // Get all transactions triggered by a specific campaign claim
|
|
5013
|
+
* const claimTxs = await sdk.transactions.getUserTransactionHistory({
|
|
5014
|
+
* triggerProcessId: 'claim-abc123',
|
|
5015
|
+
* include: ['sender', 'recipient', 'business']
|
|
4795
5016
|
* });
|
|
4796
5017
|
*
|
|
4797
|
-
*
|
|
4798
|
-
*
|
|
4799
|
-
*
|
|
4800
|
-
*
|
|
4801
|
-
*
|
|
4802
|
-
*
|
|
4803
|
-
* console.log('\nBy type:');
|
|
4804
|
-
* Object.entries(typeCounts).forEach(([type, count]) => {
|
|
4805
|
-
* console.log(`${type}: ${count} transactions`);
|
|
5018
|
+
* claimTxs.data.forEach(tx => {
|
|
5019
|
+
* console.log('Transaction from claim:', tx.id);
|
|
5020
|
+
* if (tx.included?.engagedBusiness) {
|
|
5021
|
+
* console.log('Business:', tx.included.engagedBusiness.displayName);
|
|
5022
|
+
* }
|
|
4806
5023
|
* });
|
|
4807
|
-
*
|
|
4808
|
-
* // Calculate volume metrics
|
|
4809
|
-
* const totalVolume = allTransactions.reduce((sum, t) =>
|
|
4810
|
-
* sum + (t.amount || 0), 0
|
|
4811
|
-
* );
|
|
4812
|
-
*
|
|
4813
|
-
* const avgTransactionSize = totalVolume / allTransactions.length;
|
|
4814
|
-
*
|
|
4815
|
-
* console.log('\nVolume metrics:');
|
|
4816
|
-
* console.log(`Total volume: $${totalVolume.toFixed(2)}`);
|
|
4817
|
-
* console.log(`Average transaction: $${avgTransactionSize.toFixed(2)}`);
|
|
4818
|
-
*
|
|
4819
|
-
* // Recent activity analysis
|
|
4820
|
-
* const last24Hours = allTransactions.filter(t =>
|
|
4821
|
-
* new Date(t.createdAt) > new Date(Date.now() - 24 * 60 * 60 * 1000)
|
|
4822
|
-
* );
|
|
4823
|
-
*
|
|
4824
|
-
* console.log(`\n⏰ Last 24 hours: ${last24Hours.length} transactions`);
|
|
4825
5024
|
* ```
|
|
4826
5025
|
*/
|
|
4827
|
-
async
|
|
4828
|
-
return this.transactionService.
|
|
5026
|
+
async getUserTransactionHistory(options) {
|
|
5027
|
+
return this.transactionService.getUserTransactionHistory(options);
|
|
4829
5028
|
}
|
|
4830
5029
|
/**
|
|
4831
5030
|
* Admin: Get paginated transactions
|
|
@@ -4834,7 +5033,7 @@ class TransactionManager {
|
|
|
4834
5033
|
* handling. This operation requires administrator privileges and is used for
|
|
4835
5034
|
* detailed transaction analysis and reporting interfaces.
|
|
4836
5035
|
*
|
|
4837
|
-
* @param
|
|
5036
|
+
* @param options - Pagination, filtering parameters, and optional include relations
|
|
4838
5037
|
* @returns Promise resolving to paginated transaction results with metadata
|
|
4839
5038
|
* @throws {PersApiError} When not authenticated as administrator
|
|
4840
5039
|
*
|
|
@@ -4889,9 +5088,24 @@ class TransactionManager {
|
|
|
4889
5088
|
* console.log(`$${transaction.amount} - ${transaction.business?.displayName}`);
|
|
4890
5089
|
* });
|
|
4891
5090
|
* ```
|
|
5091
|
+
*
|
|
5092
|
+
* @example With Included Relations
|
|
5093
|
+
* ```typescript
|
|
5094
|
+
* // Include sender and recipient entities
|
|
5095
|
+
* const result = await sdk.transactions.getPaginatedTransactions({
|
|
5096
|
+
* page: 1,
|
|
5097
|
+
* limit: 50,
|
|
5098
|
+
* include: ['sender', 'recipient', 'business']
|
|
5099
|
+
* });
|
|
5100
|
+
*
|
|
5101
|
+
* result.data.forEach(tx => {
|
|
5102
|
+
* if (tx.included?.sender) console.log('From:', tx.included.sender);
|
|
5103
|
+
* if (tx.included?.recipient) console.log('To:', tx.included.recipient);
|
|
5104
|
+
* });
|
|
5105
|
+
* ```
|
|
4892
5106
|
*/
|
|
4893
|
-
async getPaginatedTransactions(
|
|
4894
|
-
return this.transactionService.getPaginatedTransactions(
|
|
5107
|
+
async getPaginatedTransactions(options) {
|
|
5108
|
+
return this.transactionService.getPaginatedTransactions(options);
|
|
4895
5109
|
}
|
|
4896
5110
|
/**
|
|
4897
5111
|
* Admin: Export transactions as CSV
|
|
@@ -6554,6 +6768,179 @@ class AnalyticsManager {
|
|
|
6554
6768
|
async getTransactionAnalytics(request) {
|
|
6555
6769
|
return this.analyticsService.getTransactionAnalytics(request);
|
|
6556
6770
|
}
|
|
6771
|
+
/**
|
|
6772
|
+
* Get campaign claim analytics with aggregation
|
|
6773
|
+
*
|
|
6774
|
+
* Retrieves aggregated analytics for campaign claims with flexible grouping,
|
|
6775
|
+
* filtering, and metric selection. Provides insights into campaign performance,
|
|
6776
|
+
* claim patterns, and user engagement across the loyalty ecosystem.
|
|
6777
|
+
*
|
|
6778
|
+
* @param request - Analytics request with filters, groupBy, and metrics
|
|
6779
|
+
* @returns Promise resolving to campaign claim analytics data
|
|
6780
|
+
*
|
|
6781
|
+
* @example Claims per campaign
|
|
6782
|
+
* ```typescript
|
|
6783
|
+
* const analytics = await sdk.analytics.getCampaignClaimAnalytics({
|
|
6784
|
+
* filters: { status: 'COMPLETED' },
|
|
6785
|
+
* groupBy: ['campaignId'],
|
|
6786
|
+
* metrics: ['count'],
|
|
6787
|
+
* sortBy: 'count',
|
|
6788
|
+
* sortOrder: 'DESC',
|
|
6789
|
+
* limit: 10
|
|
6790
|
+
* });
|
|
6791
|
+
*
|
|
6792
|
+
* console.log('Top campaigns:', analytics.results);
|
|
6793
|
+
* ```
|
|
6794
|
+
*/
|
|
6795
|
+
async getCampaignClaimAnalytics(request) {
|
|
6796
|
+
return this.analyticsService.getCampaignClaimAnalytics(request);
|
|
6797
|
+
}
|
|
6798
|
+
/**
|
|
6799
|
+
* Get user analytics with engagement metrics
|
|
6800
|
+
*
|
|
6801
|
+
* Retrieves aggregated user statistics including engagement rate, active users,
|
|
6802
|
+
* transaction metrics, and per-active-user averages. Provides comprehensive
|
|
6803
|
+
* insights into user behavior, engagement patterns, and platform adoption metrics.
|
|
6804
|
+
*
|
|
6805
|
+
* NEW: Added per-active-user metrics (averageTransactionsPerActiveUser, etc.) which
|
|
6806
|
+
* show concentrated engagement among active users - more useful than diluted all-user averages.
|
|
6807
|
+
*
|
|
6808
|
+
* Request structure matches TransactionAnalytics and CampaignClaimAnalytics:
|
|
6809
|
+
* - Use filters object for business-specific scoping
|
|
6810
|
+
* - startDate/endDate at root level for date range filtering
|
|
6811
|
+
*
|
|
6812
|
+
* @param request - Analytics request with optional filters and date range
|
|
6813
|
+
* @returns Promise resolving to user analytics data with per-user and per-active-user metrics
|
|
6814
|
+
*
|
|
6815
|
+
* @example Basic user analytics (compare per-user vs per-active-user)
|
|
6816
|
+
* ```typescript
|
|
6817
|
+
* const analytics = await sdk.analytics.getUserAnalytics({});
|
|
6818
|
+
* console.log(`Total users: ${analytics.totalUsers}`);
|
|
6819
|
+
* console.log(`Active users: ${analytics.activeUsers} (${analytics.engagementRate.toFixed(1)}%)`);
|
|
6820
|
+
*
|
|
6821
|
+
* // Per-user averages (includes inactive users - lower numbers)
|
|
6822
|
+
* console.log(`\\nPer-User Averages (all users):`);
|
|
6823
|
+
* console.log(` Transactions: ${analytics.averageTransactionsPerUser.toFixed(2)}`);
|
|
6824
|
+
* console.log(` Claims: ${analytics.averageClaimsPerUser.toFixed(2)}`);
|
|
6825
|
+
* console.log(` Redemptions: ${analytics.averageRedemptionsPerUser.toFixed(2)}`);
|
|
6826
|
+
*
|
|
6827
|
+
* // Per-active-user averages (only engaged users - higher, more meaningful numbers)
|
|
6828
|
+
* console.log(`\\nPer-Active-User Averages (engaged users only):`);
|
|
6829
|
+
* console.log(` Transactions: ${analytics.averageTransactionsPerActiveUser.toFixed(2)}`);
|
|
6830
|
+
* console.log(` Claims: ${analytics.averageClaimsPerActiveUser.toFixed(2)}`);
|
|
6831
|
+
* console.log(` Redemptions: ${analytics.averageRedemptionsPerActiveUser.toFixed(2)}`);
|
|
6832
|
+
* ```
|
|
6833
|
+
*
|
|
6834
|
+
* @example Monthly user analytics with date range
|
|
6835
|
+
* ```typescript
|
|
6836
|
+
* const analytics = await sdk.analytics.getUserAnalytics({
|
|
6837
|
+
* startDate: new Date('2026-02-01'),
|
|
6838
|
+
* endDate: new Date('2026-02-28')
|
|
6839
|
+
* });
|
|
6840
|
+
*
|
|
6841
|
+
* console.log('February 2026 User Metrics:');
|
|
6842
|
+
* console.log(`Total users: ${analytics.totalUsers}`);
|
|
6843
|
+
* console.log(`Active users: ${analytics.activeUsers}`);
|
|
6844
|
+
* console.log(`New users: ${analytics.newUsers}`);
|
|
6845
|
+
* console.log(`Engagement rate: ${analytics.engagementRate.toFixed(2)}%`);
|
|
6846
|
+
* console.log(`Total transaction volume: $${analytics.totalTransactionVolume.toLocaleString()}`);
|
|
6847
|
+
* console.log(`Avg transaction amount: $${analytics.averageTransactionAmount.toFixed(2)}`);
|
|
6848
|
+
* console.log(`\\nFilters applied: ${analytics.metadata.dateRange?.startDate} to ${analytics.metadata.dateRange?.endDate}`);
|
|
6849
|
+
* ```
|
|
6850
|
+
*
|
|
6851
|
+
* @example Business-specific user analytics with filters
|
|
6852
|
+
* ```typescript
|
|
6853
|
+
* const analytics = await sdk.analytics.getUserAnalytics({
|
|
6854
|
+
* filters: { businessId: 'business-123' },
|
|
6855
|
+
* startDate: new Date('2026-01-01'),
|
|
6856
|
+
* endDate: new Date('2026-12-31')
|
|
6857
|
+
* });
|
|
6858
|
+
*
|
|
6859
|
+
* console.log(`Business customer metrics for 2026:`);
|
|
6860
|
+
* console.log(`Active customers: ${analytics.activeUsers} / ${analytics.totalUsers}`);
|
|
6861
|
+
* console.log(`Customer engagement: ${analytics.engagementRate.toFixed(1)}%`);
|
|
6862
|
+
* console.log(`Avg spend per customer: $${analytics.averageTransactionAmount.toFixed(2)}`);
|
|
6863
|
+
* console.log(`Avg spend per active customer: $${(analytics.totalTransactionVolume / analytics.activeUsers).toFixed(2)}`);
|
|
6864
|
+
* console.log(`Avg claims per active customer: ${analytics.averageClaimsPerActiveUser.toFixed(2)}`);
|
|
6865
|
+
* ```
|
|
6866
|
+
*/
|
|
6867
|
+
async getUserAnalytics(request = {}) {
|
|
6868
|
+
return this.analyticsService.getUserAnalytics(request);
|
|
6869
|
+
}
|
|
6870
|
+
/**
|
|
6871
|
+
* Get user transaction ranking with enriched user data
|
|
6872
|
+
*
|
|
6873
|
+
* Retrieves ranked list of users with full user details (email, externalUserId)
|
|
6874
|
+
* and transaction metrics. Data enrichment happens via efficient SQL JOINs + UNION
|
|
6875
|
+
* (handles legacy transactions). Ideal for leaderboards, engagement analysis, and
|
|
6876
|
+
* identifying power users for targeted campaigns.
|
|
6877
|
+
*
|
|
6878
|
+
* Use Cases:
|
|
6879
|
+
* - Admin leaderboards showing top users by activity
|
|
6880
|
+
* - User engagement analysis with full user context
|
|
6881
|
+
* - Identifying power users for campaigns
|
|
6882
|
+
* - Customer segmentation by transaction behavior
|
|
6883
|
+
*
|
|
6884
|
+
* @param request - Ranking request with filters, sorting, and limit
|
|
6885
|
+
* @returns Promise resolving to ranked user list with transaction metrics
|
|
6886
|
+
*
|
|
6887
|
+
* @example Top 50 users by transaction count
|
|
6888
|
+
* ```typescript
|
|
6889
|
+
* const ranking = await sdk.analytics.getUserRanking({
|
|
6890
|
+
* sortBy: 'totalTransactions',
|
|
6891
|
+
* sortOrder: 'DESC',
|
|
6892
|
+
* limit: 50
|
|
6893
|
+
* });
|
|
6894
|
+
*
|
|
6895
|
+
* console.log(`Top ${ranking.totalUsers} users:`);
|
|
6896
|
+
* ranking.results.forEach((user, index) => {
|
|
6897
|
+
* console.log(`#${index + 1}: ${user.email || user.externalUserId}`);
|
|
6898
|
+
* console.log(` Transactions: ${user.totalTransactions}`);
|
|
6899
|
+
* console.log(` Token spent: ${user.tokenSpent}`);
|
|
6900
|
+
* });
|
|
6901
|
+
* ```
|
|
6902
|
+
*
|
|
6903
|
+
* @example Top users by STAMP spending
|
|
6904
|
+
* ```typescript
|
|
6905
|
+
* const ranking = await sdk.analytics.getUserRanking({
|
|
6906
|
+
* filters: { tokenType: 'STAMP' },
|
|
6907
|
+
* sortBy: 'tokenSpent',
|
|
6908
|
+
* sortOrder: 'DESC',
|
|
6909
|
+
* limit: 20
|
|
6910
|
+
* });
|
|
6911
|
+
*
|
|
6912
|
+
* console.log('Top 20 STAMP spenders:');
|
|
6913
|
+
* ranking.results.forEach((user, index) => {
|
|
6914
|
+
* const identifier = user.email || user.externalUserId || user.userId;
|
|
6915
|
+
* console.log(`${index + 1}. ${identifier} - ${user.tokenSpent} STAMP`);
|
|
6916
|
+
* });
|
|
6917
|
+
* ```
|
|
6918
|
+
*/
|
|
6919
|
+
async getUserRanking(request = {}) {
|
|
6920
|
+
return this.analyticsService.getUserRanking(request);
|
|
6921
|
+
}
|
|
6922
|
+
/**
|
|
6923
|
+
* Get business transaction ranking with enriched business data
|
|
6924
|
+
*
|
|
6925
|
+
* Returns ranked list of businesses with full business details and transaction metrics.
|
|
6926
|
+
*
|
|
6927
|
+
* @param request - Ranking request with filters, sorting, and limit
|
|
6928
|
+
* @returns Promise resolving to ranked business list
|
|
6929
|
+
*/
|
|
6930
|
+
async getBusinessRanking(request = {}) {
|
|
6931
|
+
return this.analyticsService.getBusinessRanking(request);
|
|
6932
|
+
}
|
|
6933
|
+
/**
|
|
6934
|
+
* Get monthly user retention analytics
|
|
6935
|
+
*
|
|
6936
|
+
* Returns monthly retention data with user metrics and retention rates.
|
|
6937
|
+
*
|
|
6938
|
+
* @param request - Retention request with monthsBack and filters
|
|
6939
|
+
* @returns Promise resolving to monthly retention data
|
|
6940
|
+
*/
|
|
6941
|
+
async getRetentionAnalytics(request = {}) {
|
|
6942
|
+
return this.analyticsService.getRetentionAnalytics(request);
|
|
6943
|
+
}
|
|
6557
6944
|
/**
|
|
6558
6945
|
* Get the full analytics service for advanced operations
|
|
6559
6946
|
*
|
|
@@ -6648,6 +7035,222 @@ class DonationManager {
|
|
|
6648
7035
|
}
|
|
6649
7036
|
}
|
|
6650
7037
|
|
|
7038
|
+
/**
|
|
7039
|
+
* TriggerSource Manager - Clean, high-level interface for trigger source operations
|
|
7040
|
+
*
|
|
7041
|
+
* Manages trigger sources which are physical or digital activation points for campaigns:
|
|
7042
|
+
* - QR_CODE: Scannable QR codes
|
|
7043
|
+
* - NFC_TAG: NFC tap points
|
|
7044
|
+
* - GPS_GEOFENCE: Location-based triggers
|
|
7045
|
+
* - API_WEBHOOK: External system integration
|
|
7046
|
+
* - TRANSACTION: Purchase/payment based triggers
|
|
7047
|
+
*
|
|
7048
|
+
* Trigger sources are independent entities that can be created, managed, and then
|
|
7049
|
+
* assigned to campaigns. This separation allows reuse and flexible campaign configuration.
|
|
7050
|
+
*
|
|
7051
|
+
* @group Managers
|
|
7052
|
+
* @category TriggerSource Management
|
|
7053
|
+
*
|
|
7054
|
+
* @example Basic TriggerSource Operations
|
|
7055
|
+
* ```typescript
|
|
7056
|
+
* // Get all QR code trigger sources
|
|
7057
|
+
* const qrSources = await sdk.triggerSources.getAll({ type: 'QR_CODE' });
|
|
7058
|
+
*
|
|
7059
|
+
* // Create a new QR code trigger source
|
|
7060
|
+
* const source = await sdk.triggerSources.create({
|
|
7061
|
+
* type: 'QR_CODE',
|
|
7062
|
+
* name: 'Store Entrance QR',
|
|
7063
|
+
* businessId: 'business-123'
|
|
7064
|
+
* });
|
|
7065
|
+
*
|
|
7066
|
+
* // Assign to campaign (via CampaignManager)
|
|
7067
|
+
* await sdk.campaigns.assignTriggerSource('campaign-456', source.id);
|
|
7068
|
+
* ```
|
|
7069
|
+
*/
|
|
7070
|
+
class TriggerSourceManager {
|
|
7071
|
+
constructor(apiClient, events) {
|
|
7072
|
+
this.apiClient = apiClient;
|
|
7073
|
+
this.events = events;
|
|
7074
|
+
const triggerSourceApi = new TriggerSourceApi(apiClient);
|
|
7075
|
+
this.triggerSourceService = new TriggerSourceService(triggerSourceApi);
|
|
7076
|
+
}
|
|
7077
|
+
/**
|
|
7078
|
+
* Get trigger sources with optional filters and pagination
|
|
7079
|
+
*
|
|
7080
|
+
* Retrieves trigger sources (QR codes, NFC tags, GPS geofences, webhooks, etc.)
|
|
7081
|
+
* that can be used to activate campaigns. Supports filtering by type, business,
|
|
7082
|
+
* campaign association, and active status.
|
|
7083
|
+
*
|
|
7084
|
+
* @param options - Filter and pagination options
|
|
7085
|
+
* @returns Promise resolving to paginated trigger sources
|
|
7086
|
+
*
|
|
7087
|
+
* @example
|
|
7088
|
+
* ```typescript
|
|
7089
|
+
* // Get all QR code trigger sources
|
|
7090
|
+
* const qrSources = await sdk.triggerSources.getAll({ type: 'QR_CODE' });
|
|
7091
|
+
*
|
|
7092
|
+
* // Get trigger sources for a specific business
|
|
7093
|
+
* const businessSources = await sdk.triggerSources.getAll({
|
|
7094
|
+
* businessId: 'business-123',
|
|
7095
|
+
* active: true,
|
|
7096
|
+
* page: 1,
|
|
7097
|
+
* limit: 20
|
|
7098
|
+
* });
|
|
7099
|
+
*
|
|
7100
|
+
* // Get trigger sources assigned to a campaign
|
|
7101
|
+
* const campaignSources = await sdk.triggerSources.getAll({
|
|
7102
|
+
* campaignId: 'campaign-456'
|
|
7103
|
+
* });
|
|
7104
|
+
* ```
|
|
7105
|
+
*/
|
|
7106
|
+
async getAll(options) {
|
|
7107
|
+
return this.triggerSourceService.getTriggerSources(options);
|
|
7108
|
+
}
|
|
7109
|
+
/**
|
|
7110
|
+
* Get trigger source by ID
|
|
7111
|
+
*
|
|
7112
|
+
* Retrieves detailed information for a specific trigger source including
|
|
7113
|
+
* its type, location, metadata, and usage analytics.
|
|
7114
|
+
*
|
|
7115
|
+
* @param triggerSourceId - UUID of the trigger source
|
|
7116
|
+
* @returns Promise resolving to trigger source details
|
|
7117
|
+
* @throws {PersApiError} When trigger source with specified ID is not found
|
|
7118
|
+
*
|
|
7119
|
+
* @example
|
|
7120
|
+
* ```typescript
|
|
7121
|
+
* const source = await sdk.triggerSources.getById('source-123');
|
|
7122
|
+
*
|
|
7123
|
+
* console.log('Trigger Source:', source.name);
|
|
7124
|
+
* console.log('Type:', source.type);
|
|
7125
|
+
* console.log('Active:', source.isActive);
|
|
7126
|
+
*
|
|
7127
|
+
* if (source.coordsLatitude && source.coordsLongitude) {
|
|
7128
|
+
* console.log('Location:', source.coordsLatitude, source.coordsLongitude);
|
|
7129
|
+
* }
|
|
7130
|
+
* ```
|
|
7131
|
+
*/
|
|
7132
|
+
async getById(triggerSourceId) {
|
|
7133
|
+
return this.triggerSourceService.getTriggerSourceById(triggerSourceId);
|
|
7134
|
+
}
|
|
7135
|
+
/**
|
|
7136
|
+
* Admin: Create a new trigger source
|
|
7137
|
+
*
|
|
7138
|
+
* Creates a new trigger source (QR code, NFC tag, GPS geofence, webhook, or
|
|
7139
|
+
* transaction-based trigger) that can be assigned to campaigns. Requires
|
|
7140
|
+
* administrator privileges.
|
|
7141
|
+
*
|
|
7142
|
+
* @param triggerSource - Trigger source creation data
|
|
7143
|
+
* @returns Promise resolving to created trigger source
|
|
7144
|
+
* @throws {PersApiError} When not authenticated as admin or validation fails
|
|
7145
|
+
*
|
|
7146
|
+
* @example
|
|
7147
|
+
* ```typescript
|
|
7148
|
+
* // Create a QR code trigger source
|
|
7149
|
+
* const qrSource = await sdk.triggerSources.create({
|
|
7150
|
+
* type: 'QR_CODE',
|
|
7151
|
+
* name: 'Store Entrance QR',
|
|
7152
|
+
* description: 'QR code at main entrance',
|
|
7153
|
+
* businessId: 'business-123',
|
|
7154
|
+
* coordsLatitude: 47.6062,
|
|
7155
|
+
* coordsLongitude: -122.3321
|
|
7156
|
+
* });
|
|
7157
|
+
*
|
|
7158
|
+
* // Create an NFC tag trigger source
|
|
7159
|
+
* const nfcSource = await sdk.triggerSources.create({
|
|
7160
|
+
* type: 'NFC_TAG',
|
|
7161
|
+
* name: 'Product Display NFC',
|
|
7162
|
+
* metadata: { productId: 'SKU-12345' }
|
|
7163
|
+
* });
|
|
7164
|
+
*
|
|
7165
|
+
* // Create a GPS geofence trigger source
|
|
7166
|
+
* const geoSource = await sdk.triggerSources.create({
|
|
7167
|
+
* type: 'GPS_GEOFENCE',
|
|
7168
|
+
* name: 'Store Area',
|
|
7169
|
+
* coordsLatitude: 47.6062,
|
|
7170
|
+
* coordsLongitude: -122.3321,
|
|
7171
|
+
* metadata: { radiusMeters: 100 }
|
|
7172
|
+
* });
|
|
7173
|
+
* ```
|
|
7174
|
+
*/
|
|
7175
|
+
async create(triggerSource) {
|
|
7176
|
+
const result = await this.triggerSourceService.createTriggerSource(triggerSource);
|
|
7177
|
+
this.events?.emitSuccess({
|
|
7178
|
+
domain: 'trigger-source',
|
|
7179
|
+
type: 'TRIGGER_SOURCE_CREATED',
|
|
7180
|
+
userMessage: 'Trigger source created successfully',
|
|
7181
|
+
details: { triggerSourceId: result.id, type: result.type }
|
|
7182
|
+
});
|
|
7183
|
+
return result;
|
|
7184
|
+
}
|
|
7185
|
+
/**
|
|
7186
|
+
* Admin: Update a trigger source
|
|
7187
|
+
*
|
|
7188
|
+
* Updates an existing trigger source's configuration. All fields are optional;
|
|
7189
|
+
* only provided fields will be updated. Requires administrator privileges.
|
|
7190
|
+
*
|
|
7191
|
+
* @param triggerSourceId - UUID of the trigger source to update
|
|
7192
|
+
* @param triggerSource - Updated trigger source data (partial)
|
|
7193
|
+
* @returns Promise resolving to updated trigger source
|
|
7194
|
+
* @throws {PersApiError} When not authenticated as admin or trigger source not found
|
|
7195
|
+
*
|
|
7196
|
+
* @example
|
|
7197
|
+
* ```typescript
|
|
7198
|
+
* // Update trigger source name and location
|
|
7199
|
+
* const updated = await sdk.triggerSources.update('source-123', {
|
|
7200
|
+
* name: 'Updated Store Entrance QR',
|
|
7201
|
+
* description: 'New description',
|
|
7202
|
+
* coordsLatitude: 47.6063,
|
|
7203
|
+
* coordsLongitude: -122.3322
|
|
7204
|
+
* });
|
|
7205
|
+
* ```
|
|
7206
|
+
*/
|
|
7207
|
+
async update(triggerSourceId, triggerSource) {
|
|
7208
|
+
const result = await this.triggerSourceService.updateTriggerSource(triggerSourceId, triggerSource);
|
|
7209
|
+
this.events?.emitSuccess({
|
|
7210
|
+
domain: 'trigger-source',
|
|
7211
|
+
type: 'TRIGGER_SOURCE_UPDATED',
|
|
7212
|
+
userMessage: 'Trigger source updated successfully',
|
|
7213
|
+
details: { triggerSourceId }
|
|
7214
|
+
});
|
|
7215
|
+
return result;
|
|
7216
|
+
}
|
|
7217
|
+
/**
|
|
7218
|
+
* Admin: Delete a trigger source
|
|
7219
|
+
*
|
|
7220
|
+
* Soft deletes a trigger source, making it inactive. The trigger source will
|
|
7221
|
+
* be removed from any campaigns it was assigned to. Requires administrator
|
|
7222
|
+
* privileges.
|
|
7223
|
+
*
|
|
7224
|
+
* @param triggerSourceId - UUID of the trigger source to delete
|
|
7225
|
+
* @returns Promise resolving to success status
|
|
7226
|
+
* @throws {PersApiError} When not authenticated as admin or trigger source not found
|
|
7227
|
+
*
|
|
7228
|
+
* @example
|
|
7229
|
+
* ```typescript
|
|
7230
|
+
* const success = await sdk.triggerSources.delete('source-123');
|
|
7231
|
+
* console.log('Trigger source deleted:', success);
|
|
7232
|
+
* ```
|
|
7233
|
+
*/
|
|
7234
|
+
async delete(triggerSourceId) {
|
|
7235
|
+
const result = await this.triggerSourceService.deleteTriggerSource(triggerSourceId);
|
|
7236
|
+
this.events?.emitSuccess({
|
|
7237
|
+
domain: 'trigger-source',
|
|
7238
|
+
type: 'TRIGGER_SOURCE_DELETED',
|
|
7239
|
+
userMessage: 'Trigger source deleted successfully',
|
|
7240
|
+
details: { triggerSourceId }
|
|
7241
|
+
});
|
|
7242
|
+
return result;
|
|
7243
|
+
}
|
|
7244
|
+
/**
|
|
7245
|
+
* Get the full trigger source service for advanced operations
|
|
7246
|
+
*
|
|
7247
|
+
* @returns TriggerSourceService instance with full API access
|
|
7248
|
+
*/
|
|
7249
|
+
getTriggerSourceService() {
|
|
7250
|
+
return this.triggerSourceService;
|
|
7251
|
+
}
|
|
7252
|
+
}
|
|
7253
|
+
|
|
6651
7254
|
/**
|
|
6652
7255
|
* @fileoverview PERS SDK - Platform-agnostic TypeScript SDK with High-Level Managers
|
|
6653
7256
|
*
|
|
@@ -7134,6 +7737,40 @@ class PersSDK {
|
|
|
7134
7737
|
}
|
|
7135
7738
|
return this._donations;
|
|
7136
7739
|
}
|
|
7740
|
+
/**
|
|
7741
|
+
* TriggerSource manager - High-level trigger source operations (Admin Only)
|
|
7742
|
+
*
|
|
7743
|
+
* Provides CRUD operations for managing trigger sources (QR codes, NFC tags,
|
|
7744
|
+
* GPS geofences, API webhooks). TriggerSources are standalone entities that
|
|
7745
|
+
* can be assigned to campaigns via the campaigns manager.
|
|
7746
|
+
*
|
|
7747
|
+
* @returns TriggerSourceManager instance
|
|
7748
|
+
*
|
|
7749
|
+
* @example TriggerSource Operations
|
|
7750
|
+
* ```typescript
|
|
7751
|
+
* // Create a QR code trigger source
|
|
7752
|
+
* const qrSource = await sdk.triggerSources.create({
|
|
7753
|
+
* name: 'Store Entrance QR',
|
|
7754
|
+
* type: 'QR_CODE',
|
|
7755
|
+
* description: 'QR code at main entrance'
|
|
7756
|
+
* });
|
|
7757
|
+
*
|
|
7758
|
+
* // Get all trigger sources
|
|
7759
|
+
* const sources = await sdk.triggerSources.getAll();
|
|
7760
|
+
*
|
|
7761
|
+
* // Update trigger source
|
|
7762
|
+
* await sdk.triggerSources.update(sourceId, { name: 'Updated Name' });
|
|
7763
|
+
*
|
|
7764
|
+
* // Assign to campaign (via campaigns manager)
|
|
7765
|
+
* await sdk.campaigns.assignTriggerSource(campaignId, qrSource.id);
|
|
7766
|
+
* ```
|
|
7767
|
+
*/
|
|
7768
|
+
get triggerSources() {
|
|
7769
|
+
if (!this._triggerSources) {
|
|
7770
|
+
this._triggerSources = new TriggerSourceManager(this.apiClient, this._events);
|
|
7771
|
+
}
|
|
7772
|
+
return this._triggerSources;
|
|
7773
|
+
}
|
|
7137
7774
|
/**
|
|
7138
7775
|
* Gets the API client for direct PERS API requests
|
|
7139
7776
|
*
|
|
@@ -7183,5 +7820,5 @@ function createPersSDK(httpClient, config) {
|
|
|
7183
7820
|
return new PersSDK(httpClient, config);
|
|
7184
7821
|
}
|
|
7185
7822
|
|
|
7186
|
-
export { AuthStatus as A, BusinessManager as B, CampaignManager as C, DefaultAuthProvider as D, FileManager as F, LocalStorageTokenStorage as L, MemoryTokenStorage as M, PersSDK as P, RedemptionManager as R, SDK_NAME as S, TokenManager as T, UserManager as U, WebDPoPCryptoProvider as W, AuthTokenManager as a, AUTH_STORAGE_KEYS as b, createPersSDK as c, DPOP_STORAGE_KEYS as d, SDK_VERSION as e, SDK_USER_AGENT as f, PersApiClient as g, DEFAULT_PERS_CONFIG as h, buildApiRoot as i, StaticJwtAuthProvider as j, AuthApi as k, AuthService as l, mergeWithDefaults as m, DPoPManager as n, PersEventEmitter as o, AuthManager as p, UserStatusManager as q, TransactionManager as r, PurchaseManager as s, TenantManager as t, ApiKeyManager as u, AnalyticsManager as v, DonationManager as w,
|
|
7187
|
-
//# sourceMappingURL=pers-sdk-
|
|
7823
|
+
export { AuthStatus as A, BusinessManager as B, CampaignManager as C, DefaultAuthProvider as D, ApiKeyApi as E, FileManager as F, LocalStorageTokenStorage as L, MemoryTokenStorage as M, PersSDK as P, RedemptionManager as R, SDK_NAME as S, TokenManager as T, UserManager as U, WebDPoPCryptoProvider as W, AuthTokenManager as a, AUTH_STORAGE_KEYS as b, createPersSDK as c, DPOP_STORAGE_KEYS as d, SDK_VERSION as e, SDK_USER_AGENT as f, PersApiClient as g, DEFAULT_PERS_CONFIG as h, buildApiRoot as i, StaticJwtAuthProvider as j, AuthApi as k, AuthService as l, mergeWithDefaults as m, DPoPManager as n, PersEventEmitter as o, AuthManager as p, UserStatusManager as q, TransactionManager as r, PurchaseManager as s, TenantManager as t, ApiKeyManager as u, AnalyticsManager as v, DonationManager as w, TriggerSourceManager as x, FileApi as y, FileService as z };
|
|
7824
|
+
//# sourceMappingURL=pers-sdk-BtvhucPY.js.map
|