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