@explorins/pers-sdk 1.6.45 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +288 -0
- package/dist/analytics.cjs +12 -0
- package/dist/analytics.cjs.map +1 -1
- package/dist/analytics.js +1 -1
- package/dist/api-key/api/api-key-api.d.ts +5 -2
- package/dist/api-key/api/api-key-api.d.ts.map +1 -1
- package/dist/business/api/business-api.d.ts +30 -11
- package/dist/business/api/business-api.d.ts.map +1 -1
- package/dist/business/api/business-membership-api.d.ts +205 -0
- package/dist/business/api/business-membership-api.d.ts.map +1 -0
- package/dist/business/index.d.ts +2 -0
- package/dist/business/index.d.ts.map +1 -1
- package/dist/business/services/business-membership-service.d.ts +180 -0
- package/dist/business/services/business-membership-service.d.ts.map +1 -0
- package/dist/business/services/business-service.d.ts +11 -7
- package/dist/business/services/business-service.d.ts.map +1 -1
- package/dist/business.cjs +767 -9
- package/dist/business.cjs.map +1 -1
- package/dist/business.js +751 -2
- package/dist/business.js.map +1 -1
- package/dist/campaign/api/campaign-api.d.ts +56 -22
- package/dist/campaign/api/campaign-api.d.ts.map +1 -1
- package/dist/campaign/services/campaign-service.d.ts +28 -16
- package/dist/campaign/services/campaign-service.d.ts.map +1 -1
- package/dist/campaign.cjs +14 -1
- package/dist/campaign.cjs.map +1 -1
- package/dist/campaign.js +3 -2
- package/dist/campaign.js.map +1 -1
- package/dist/chunks/{base-token-service-BSXDwrcq.js → base-token-service-DsD6lSdq.js} +2 -48
- package/dist/chunks/base-token-service-DsD6lSdq.js.map +1 -0
- package/dist/chunks/{base-token-service-CYuqPPs0.cjs → base-token-service-_64IWVES.cjs} +2 -48
- package/dist/chunks/base-token-service-_64IWVES.cjs.map +1 -0
- package/dist/chunks/{campaign-service-B1tQMNqA.cjs → campaign-service-Ae164xl8.cjs} +102 -84
- package/dist/chunks/campaign-service-Ae164xl8.cjs.map +1 -0
- package/dist/chunks/{campaign-service-CJPXgFBe.js → campaign-service-rlK4WeSY.js} +102 -84
- package/dist/chunks/campaign-service-rlK4WeSY.js.map +1 -0
- package/dist/chunks/{donation-service-D-xFrONi.cjs → donation-service--6cnTvWq.cjs} +9 -5
- package/dist/chunks/donation-service--6cnTvWq.cjs.map +1 -0
- package/dist/chunks/{donation-service-CyJS4DIZ.js → donation-service-xiXZ2Eto.js} +9 -5
- package/dist/chunks/donation-service-xiXZ2Eto.js.map +1 -0
- package/dist/chunks/pagination-utils-9vQ-Npkr.js +166 -0
- package/dist/chunks/pagination-utils-9vQ-Npkr.js.map +1 -0
- package/dist/chunks/pagination-utils-B2jRHMSO.cjs +173 -0
- package/dist/chunks/pagination-utils-B2jRHMSO.cjs.map +1 -0
- package/dist/chunks/{pers-sdk-DzS7mkm7.cjs → pers-sdk-CrffRkya.cjs} +1096 -323
- package/dist/chunks/pers-sdk-CrffRkya.cjs.map +1 -0
- package/dist/chunks/{pers-sdk-VGEG59g3.js → pers-sdk-omI-Fl0m.js} +1086 -317
- package/dist/chunks/pers-sdk-omI-Fl0m.js.map +1 -0
- package/dist/chunks/{token-service-CpVwC5Eb.js → token-service-Bfj6C0yz.js} +62 -30
- package/dist/chunks/token-service-Bfj6C0yz.js.map +1 -0
- package/dist/chunks/{token-service-BWScn8Qa.cjs → token-service-BlbXrxnS.cjs} +62 -30
- package/dist/chunks/token-service-BlbXrxnS.cjs.map +1 -0
- package/dist/chunks/transaction-request.builder-DltmruUC.js +296 -0
- package/dist/chunks/transaction-request.builder-DltmruUC.js.map +1 -0
- package/dist/chunks/transaction-request.builder-DrqTWcyC.cjs +303 -0
- package/dist/chunks/transaction-request.builder-DrqTWcyC.cjs.map +1 -0
- package/dist/chunks/{transaction-service-CXjTHCFu.cjs → transaction-service-BcJfyCcq.cjs} +68 -31
- package/dist/chunks/transaction-service-BcJfyCcq.cjs.map +1 -0
- package/dist/chunks/{transaction-service-B7h_4Hg3.js → transaction-service-CnOD3scu.js} +68 -31
- package/dist/chunks/transaction-service-CnOD3scu.js.map +1 -0
- package/dist/chunks/{user-service-D6mTa_WZ.js → user-service-BGP3SZpk.js} +82 -20
- package/dist/chunks/user-service-BGP3SZpk.js.map +1 -0
- package/dist/chunks/{user-service-D1Rn4U8u.cjs → user-service-gITOx4qj.cjs} +82 -20
- package/dist/chunks/user-service-gITOx4qj.cjs.map +1 -0
- package/dist/chunks/{web3-chain-service-BLFxB5TA.cjs → web3-chain-service-6vsVHPjl.cjs} +116 -16
- package/dist/chunks/web3-chain-service-6vsVHPjl.cjs.map +1 -0
- package/dist/chunks/{web3-chain-service-JRSwxr-s.js → web3-chain-service-BcUeeujC.js} +111 -17
- package/dist/chunks/web3-chain-service-BcUeeujC.js.map +1 -0
- package/dist/core/auth/api/auth-api.d.ts +35 -0
- package/dist/core/auth/api/auth-api.d.ts.map +1 -1
- package/dist/core/auth/auth-provider.interface.d.ts +7 -1
- package/dist/core/auth/auth-provider.interface.d.ts.map +1 -1
- package/dist/core/auth/services/auth-service.d.ts +26 -1
- package/dist/core/auth/services/auth-service.d.ts.map +1 -1
- package/dist/core/auth/token-storage.d.ts +3 -2
- package/dist/core/auth/token-storage.d.ts.map +1 -1
- package/dist/core/errors/index.d.ts +75 -6
- package/dist/core/errors/index.d.ts.map +1 -1
- package/dist/core/events/event-emitter.d.ts +106 -0
- package/dist/core/events/event-emitter.d.ts.map +1 -0
- package/dist/core/events/event-types.d.ts +127 -0
- package/dist/core/events/event-types.d.ts.map +1 -0
- package/dist/core/events/index.d.ts +22 -0
- package/dist/core/events/index.d.ts.map +1 -0
- package/dist/core/index.d.ts +3 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/pers-api-client.d.ts +12 -0
- package/dist/core/pers-api-client.d.ts.map +1 -1
- package/dist/core/version.d.ts +15 -0
- package/dist/core/version.d.ts.map +1 -0
- package/dist/core.cjs +26 -12
- package/dist/core.cjs.map +1 -1
- package/dist/core.js +13 -12
- package/dist/core.js.map +1 -1
- package/dist/donation/api/donation-api.d.ts +3 -1
- package/dist/donation/api/donation-api.d.ts.map +1 -1
- package/dist/donation/services/donation-service.d.ts +3 -1
- package/dist/donation/services/donation-service.d.ts.map +1 -1
- package/dist/donation.cjs +14 -1
- package/dist/donation.cjs.map +1 -1
- package/dist/donation.js +3 -2
- package/dist/donation.js.map +1 -1
- package/dist/index.cjs +63 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +15 -13
- package/dist/index.js.map +1 -1
- package/dist/managers/analytics-manager.d.ts +9 -9
- package/dist/managers/api-key-manager.d.ts +8 -6
- package/dist/managers/api-key-manager.d.ts.map +1 -1
- package/dist/managers/auth-manager.d.ts +77 -4
- package/dist/managers/auth-manager.d.ts.map +1 -1
- package/dist/managers/business-manager.d.ts +198 -8
- package/dist/managers/business-manager.d.ts.map +1 -1
- package/dist/managers/campaign-manager.d.ts +67 -83
- package/dist/managers/campaign-manager.d.ts.map +1 -1
- package/dist/managers/donation-manager.d.ts +4 -2
- package/dist/managers/donation-manager.d.ts.map +1 -1
- package/dist/managers/file-manager.d.ts +2 -2
- package/dist/managers/purchase-manager.d.ts +26 -24
- package/dist/managers/purchase-manager.d.ts.map +1 -1
- package/dist/managers/redemption-manager.d.ts +106 -92
- package/dist/managers/redemption-manager.d.ts.map +1 -1
- package/dist/managers/tenant-manager.d.ts +5 -2
- package/dist/managers/tenant-manager.d.ts.map +1 -1
- package/dist/managers/token-manager.d.ts +6 -4
- package/dist/managers/token-manager.d.ts.map +1 -1
- package/dist/managers/transaction-manager.d.ts +22 -19
- package/dist/managers/transaction-manager.d.ts.map +1 -1
- package/dist/managers/user-manager.d.ts +61 -3
- package/dist/managers/user-manager.d.ts.map +1 -1
- package/dist/managers/user-status-manager.d.ts +6 -4
- package/dist/managers/user-status-manager.d.ts.map +1 -1
- package/dist/managers/web3-manager.d.ts.map +1 -1
- package/dist/package.json +2 -2
- package/dist/payment/api/payment-api.d.ts +15 -18
- package/dist/payment/api/payment-api.d.ts.map +1 -1
- package/dist/payment/services/payment-service.d.ts +6 -4
- package/dist/payment/services/payment-service.d.ts.map +1 -1
- package/dist/payment.cjs +225 -9
- package/dist/payment.cjs.map +1 -1
- package/dist/payment.js +210 -2
- package/dist/payment.js.map +1 -1
- package/dist/pers-sdk.d.ts +49 -0
- package/dist/pers-sdk.d.ts.map +1 -1
- package/dist/redemption/api/redemption-api.d.ts +22 -11
- package/dist/redemption/api/redemption-api.d.ts.map +1 -1
- package/dist/redemption/services/redemption-service.d.ts +11 -9
- package/dist/redemption/services/redemption-service.d.ts.map +1 -1
- package/dist/redemption.cjs +353 -9
- package/dist/redemption.cjs.map +1 -1
- package/dist/redemption.js +338 -2
- package/dist/redemption.js.map +1 -1
- package/dist/shared/index.d.ts +1 -0
- package/dist/shared/index.d.ts.map +1 -1
- package/dist/shared/interfaces/pers-shared-lib.interfaces.d.ts +2 -1
- package/dist/shared/interfaces/pers-shared-lib.interfaces.d.ts.map +1 -1
- package/dist/shared/utils/pagination-utils.d.ts +184 -0
- package/dist/shared/utils/pagination-utils.d.ts.map +1 -0
- package/dist/tenant/api/tenant-api.d.ts +6 -1
- package/dist/tenant/api/tenant-api.d.ts.map +1 -1
- package/dist/tenant/services/tenant-service.d.ts +5 -2
- package/dist/tenant/services/tenant-service.d.ts.map +1 -1
- package/dist/tenant.cjs +177 -9
- package/dist/tenant.cjs.map +1 -1
- package/dist/tenant.js +162 -2
- package/dist/tenant.js.map +1 -1
- package/dist/token/api/token-api.d.ts +24 -7
- package/dist/token/api/token-api.d.ts.map +1 -1
- package/dist/token/base/base-token-service.d.ts +5 -4
- package/dist/token/base/base-token-service.d.ts.map +1 -1
- package/dist/token/services/token-service.d.ts +10 -8
- package/dist/token/services/token-service.d.ts.map +1 -1
- package/dist/token/token-sdk.d.ts +5 -34
- package/dist/token/token-sdk.d.ts.map +1 -1
- package/dist/token.cjs +15 -2
- package/dist/token.cjs.map +1 -1
- package/dist/token.js +4 -3
- package/dist/token.js.map +1 -1
- package/dist/transaction/api/transaction-api.d.ts +48 -6
- package/dist/transaction/api/transaction-api.d.ts.map +1 -1
- package/dist/transaction/models/index.d.ts +2 -0
- package/dist/transaction/models/index.d.ts.map +1 -1
- package/dist/transaction/models/transaction-request.builder.d.ts +256 -0
- package/dist/transaction/models/transaction-request.builder.d.ts.map +1 -0
- package/dist/transaction/services/transaction-service.d.ts +12 -4
- package/dist/transaction/services/transaction-service.d.ts.map +1 -1
- package/dist/transaction.cjs +9 -1
- package/dist/transaction.cjs.map +1 -1
- package/dist/transaction.js +3 -1
- package/dist/transaction.js.map +1 -1
- package/dist/user/api/user-api.d.ts +32 -9
- package/dist/user/api/user-api.d.ts.map +1 -1
- package/dist/user/services/user-service.d.ts +25 -2
- package/dist/user/services/user-service.d.ts.map +1 -1
- package/dist/user-status/api/user-status-api.d.ts +6 -4
- package/dist/user-status/api/user-status-api.d.ts.map +1 -1
- package/dist/user-status/index.d.ts +4 -2
- package/dist/user-status/index.d.ts.map +1 -1
- package/dist/user-status/services/user-status-service.d.ts +4 -2
- package/dist/user-status/services/user-status-service.d.ts.map +1 -1
- package/dist/user-status.cjs +34 -14
- package/dist/user-status.cjs.map +1 -1
- package/dist/user-status.js +23 -15
- package/dist/user-status.js.map +1 -1
- package/dist/user.cjs +14 -1
- package/dist/user.cjs.map +1 -1
- package/dist/user.js +3 -2
- package/dist/user.js.map +1 -1
- package/dist/web3-chain.cjs +13 -1
- package/dist/web3-chain.cjs.map +1 -1
- package/dist/web3-chain.js +2 -2
- package/package.json +2 -2
- package/dist/chunks/base-token-service-BSXDwrcq.js.map +0 -1
- package/dist/chunks/base-token-service-CYuqPPs0.cjs.map +0 -1
- package/dist/chunks/business-service-8Xd3d5oY.js +0 -238
- package/dist/chunks/business-service-8Xd3d5oY.js.map +0 -1
- package/dist/chunks/business-service-P9o4cwQL.cjs +0 -241
- package/dist/chunks/business-service-P9o4cwQL.cjs.map +0 -1
- package/dist/chunks/campaign-service-B1tQMNqA.cjs.map +0 -1
- package/dist/chunks/campaign-service-CJPXgFBe.js.map +0 -1
- package/dist/chunks/donation-service-CyJS4DIZ.js.map +0 -1
- package/dist/chunks/donation-service-D-xFrONi.cjs.map +0 -1
- package/dist/chunks/payment-service-B4qx0qiE.cjs +0 -220
- package/dist/chunks/payment-service-B4qx0qiE.cjs.map +0 -1
- package/dist/chunks/payment-service-DfCBFosx.js +0 -217
- package/dist/chunks/payment-service-DfCBFosx.js.map +0 -1
- package/dist/chunks/pers-sdk-DzS7mkm7.cjs.map +0 -1
- package/dist/chunks/pers-sdk-VGEG59g3.js.map +0 -1
- package/dist/chunks/redemption-service-7qbeQxEM.cjs +0 -330
- package/dist/chunks/redemption-service-7qbeQxEM.cjs.map +0 -1
- package/dist/chunks/redemption-service-BT0J5Iy7.js +0 -327
- package/dist/chunks/redemption-service-BT0J5Iy7.js.map +0 -1
- package/dist/chunks/tenant-service-DME24vr1.cjs +0 -157
- package/dist/chunks/tenant-service-DME24vr1.cjs.map +0 -1
- package/dist/chunks/tenant-service-DxtHAlaa.js +0 -154
- package/dist/chunks/tenant-service-DxtHAlaa.js.map +0 -1
- package/dist/chunks/token-service-BWScn8Qa.cjs.map +0 -1
- package/dist/chunks/token-service-CpVwC5Eb.js.map +0 -1
- package/dist/chunks/transaction-service-B7h_4Hg3.js.map +0 -1
- package/dist/chunks/transaction-service-CXjTHCFu.cjs.map +0 -1
- package/dist/chunks/user-service-D1Rn4U8u.cjs.map +0 -1
- package/dist/chunks/user-service-D6mTa_WZ.js.map +0 -1
- package/dist/chunks/web3-chain-service-BLFxB5TA.cjs.map +0 -1
- package/dist/chunks/web3-chain-service-JRSwxr-s.js.map +0 -1
package/README.md
CHANGED
|
@@ -16,11 +16,20 @@ Platform-agnostic TypeScript SDK for PERS (Phygital Experience Rewards System) -
|
|
|
16
16
|
- [Platform Integration](#platform-integration)
|
|
17
17
|
- [Architecture](#architecture)
|
|
18
18
|
- [Core Features](#core-features)
|
|
19
|
+
- [Event System](#event-system)
|
|
20
|
+
- [Authentication](#authentication)
|
|
21
|
+
- [Business Management](#business-management)
|
|
22
|
+
- [Campaign System](#campaign-system)
|
|
23
|
+
- [Token Management](#token-management)
|
|
24
|
+
- [User Token Balances](#user-token-balances-on-chain)
|
|
25
|
+
- [Transaction Request Building](#transaction-request-building)
|
|
26
|
+
- [Purchase/Payment Processing](#purchasepayment-processing)
|
|
19
27
|
- [Configuration](#configuration)
|
|
20
28
|
- [Advanced Authentication](#advanced-authentication)
|
|
21
29
|
- [Error Handling](#error-handling)
|
|
22
30
|
- [Bundle Size](#bundle-size)
|
|
23
31
|
- [TypeScript Types](#typescript-types)
|
|
32
|
+
- [Migration Guide](#migration-guide)
|
|
24
33
|
- [Documentation](#documentation)
|
|
25
34
|
- [Related Packages](#related-packages)
|
|
26
35
|
- [License](#license)
|
|
@@ -332,6 +341,85 @@ await apiClient.post('/custom-endpoint', { data: 'value' });
|
|
|
332
341
|
|
|
333
342
|
## Core Features
|
|
334
343
|
|
|
344
|
+
### Event System
|
|
345
|
+
|
|
346
|
+
The SDK provides a platform-agnostic event system for subscribing to SDK-wide events. All events have a `userMessage` field ready for UI display.
|
|
347
|
+
|
|
348
|
+
```typescript
|
|
349
|
+
// Subscribe to ALL events - one handler
|
|
350
|
+
const unsubscribe = sdk.events.subscribe((event) => {
|
|
351
|
+
showNotification(event.userMessage, event.level);
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
// Filter by domain and level
|
|
355
|
+
sdk.events.subscribe((event) => {
|
|
356
|
+
logToSentry(event);
|
|
357
|
+
}, { level: 'error' });
|
|
358
|
+
|
|
359
|
+
// Only transaction successes
|
|
360
|
+
sdk.events.subscribe((event) => {
|
|
361
|
+
playSuccessSound();
|
|
362
|
+
confetti();
|
|
363
|
+
}, { domain: 'transaction', level: 'success' });
|
|
364
|
+
|
|
365
|
+
// One-time event (auto-unsubscribe)
|
|
366
|
+
sdk.events.once((event) => {
|
|
367
|
+
console.log('First event:', event.type);
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
// Cleanup
|
|
371
|
+
unsubscribe();
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
#### Event Domains
|
|
375
|
+
|
|
376
|
+
| Domain | Manager | Events |
|
|
377
|
+
|--------|---------|--------|
|
|
378
|
+
| `authentication` | `sdk.auth` | `LOGIN_SUCCESS` |
|
|
379
|
+
| `user` | `sdk.users` | `PROFILE_UPDATED` |
|
|
380
|
+
| `business` | `sdk.businesses` | `BUSINESS_CREATED`, `BUSINESS_UPDATED`, `MEMBERSHIP_UPDATED` |
|
|
381
|
+
| `campaign` | `sdk.campaigns` | `CAMPAIGN_CLAIMED` |
|
|
382
|
+
| `redemption` | `sdk.redemptions` | `REDEMPTION_COMPLETED` |
|
|
383
|
+
| `transaction` | `sdk.transactions` | `TRANSACTION_CREATED`, `TRANSACTION_SUBMITTED` |
|
|
384
|
+
|
|
385
|
+
#### Event Types
|
|
386
|
+
|
|
387
|
+
```typescript
|
|
388
|
+
import type {
|
|
389
|
+
PersEvent, // Base event type (discriminated union)
|
|
390
|
+
SuccessEvent, // Success events (business domains)
|
|
391
|
+
ErrorEvent, // Error events (all domains including technical)
|
|
392
|
+
EventFilter, // Filter for subscriptions
|
|
393
|
+
EventHandler // Handler type (sync or async)
|
|
394
|
+
} from '@explorins/pers-sdk/core';
|
|
395
|
+
|
|
396
|
+
// Event structure
|
|
397
|
+
interface PersEvent {
|
|
398
|
+
id: string; // Unique event ID
|
|
399
|
+
timestamp: number; // Unix timestamp (ms)
|
|
400
|
+
domain: string; // Event domain
|
|
401
|
+
type: string; // Event type within domain
|
|
402
|
+
level: 'success' | 'error';
|
|
403
|
+
userMessage: string; // Ready for UI display
|
|
404
|
+
action?: string; // Suggested action
|
|
405
|
+
code?: string; // Backend error code
|
|
406
|
+
details?: object; // Additional data for logging
|
|
407
|
+
}
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
#### Async Handler Support
|
|
411
|
+
|
|
412
|
+
Event handlers can be synchronous or asynchronous. Async errors are caught automatically:
|
|
413
|
+
|
|
414
|
+
```typescript
|
|
415
|
+
sdk.events.subscribe(async (event) => {
|
|
416
|
+
await saveToDatabase(event); // Async operations supported
|
|
417
|
+
await sendAnalytics(event);
|
|
418
|
+
});
|
|
419
|
+
```
|
|
420
|
+
|
|
421
|
+
---
|
|
422
|
+
|
|
335
423
|
### Authentication
|
|
336
424
|
|
|
337
425
|
The SDK uses **external JWT tokens** for authentication. You provide a JWT from your authentication provider (Firebase, Auth0, Cognito, etc.), and the SDK exchanges it for PERS access tokens.
|
|
@@ -538,6 +626,104 @@ async function loadUserTokenBalances(sdk: PersSDK) {
|
|
|
538
626
|
}
|
|
539
627
|
```
|
|
540
628
|
|
|
629
|
+
### Transaction Request Building
|
|
630
|
+
|
|
631
|
+
The SDK provides factory functions for building transaction request DTOs. These are tree-shakeable and provide type-safe transaction creation:
|
|
632
|
+
|
|
633
|
+
```typescript
|
|
634
|
+
import {
|
|
635
|
+
buildMintRequest,
|
|
636
|
+
buildBurnRequest,
|
|
637
|
+
buildTransferRequest,
|
|
638
|
+
buildPOSTransferRequest,
|
|
639
|
+
buildSubmissionRequest
|
|
640
|
+
} from '@explorins/pers-sdk/transaction';
|
|
641
|
+
import { AccountOwnerType } from '@explorins/pers-shared';
|
|
642
|
+
|
|
643
|
+
// Mint tokens to a recipient
|
|
644
|
+
const mintRequest = buildMintRequest({
|
|
645
|
+
amount: 100,
|
|
646
|
+
contractAddress: '0x...',
|
|
647
|
+
chainId: 137,
|
|
648
|
+
recipientAccountId: 'user-123',
|
|
649
|
+
recipientAccountType: AccountOwnerType.USER
|
|
650
|
+
});
|
|
651
|
+
|
|
652
|
+
// Burn tokens
|
|
653
|
+
const burnRequest = buildBurnRequest({
|
|
654
|
+
amount: 50,
|
|
655
|
+
contractAddress: '0x...',
|
|
656
|
+
chainId: 137,
|
|
657
|
+
senderAccountId: 'user-123',
|
|
658
|
+
senderAccountType: AccountOwnerType.USER
|
|
659
|
+
});
|
|
660
|
+
|
|
661
|
+
// Transfer tokens between accounts
|
|
662
|
+
const transferRequest = buildTransferRequest({
|
|
663
|
+
amount: 100,
|
|
664
|
+
contractAddress: '0x...',
|
|
665
|
+
chainId: 137,
|
|
666
|
+
senderAccountId: 'user-123',
|
|
667
|
+
senderAccountType: AccountOwnerType.USER,
|
|
668
|
+
recipientAccountId: 'business-456',
|
|
669
|
+
recipientAccountType: AccountOwnerType.BUSINESS
|
|
670
|
+
});
|
|
671
|
+
|
|
672
|
+
// Submit the transaction
|
|
673
|
+
const result = await sdk.transactions.createTransaction(mintRequest);
|
|
674
|
+
```
|
|
675
|
+
|
|
676
|
+
#### POS Transaction Flow
|
|
677
|
+
|
|
678
|
+
For Point-of-Sale scenarios where a **business submits a transaction on behalf of a user**, use `buildPOSTransferRequest`:
|
|
679
|
+
|
|
680
|
+
```typescript
|
|
681
|
+
import { buildPOSTransferRequest } from '@explorins/pers-sdk/transaction';
|
|
682
|
+
|
|
683
|
+
// POS flow: User pays business, business authorized to submit
|
|
684
|
+
const posRequest = buildPOSTransferRequest({
|
|
685
|
+
amount: 100,
|
|
686
|
+
contractAddress: '0x...',
|
|
687
|
+
chainId: 137,
|
|
688
|
+
userAccountId: 'user-123', // User sending tokens
|
|
689
|
+
businessAccountId: 'business-456' // Business receiving & authorized to submit
|
|
690
|
+
});
|
|
691
|
+
|
|
692
|
+
// This automatically sets:
|
|
693
|
+
// - engagedBusinessId: 'business-456' (for reporting)
|
|
694
|
+
// - authorizedSubmitterId: 'business-456' (can submit the signed tx)
|
|
695
|
+
// - authorizedSubmitterType: AccountOwnerType.BUSINESS
|
|
696
|
+
|
|
697
|
+
const result = await sdk.transactions.createTransaction(posRequest);
|
|
698
|
+
```
|
|
699
|
+
|
|
700
|
+
For custom authorization scenarios, use `buildTransferRequest` with manual POS fields:
|
|
701
|
+
|
|
702
|
+
```typescript
|
|
703
|
+
import { buildTransferRequest, type POSAuthorizationOptions } from '@explorins/pers-sdk/transaction';
|
|
704
|
+
|
|
705
|
+
const customPOSRequest = buildTransferRequest({
|
|
706
|
+
amount: 100,
|
|
707
|
+
contractAddress: '0x...',
|
|
708
|
+
chainId: 137,
|
|
709
|
+
senderAccountId: 'user-123',
|
|
710
|
+
senderAccountType: AccountOwnerType.USER,
|
|
711
|
+
recipientAccountId: 'business-456',
|
|
712
|
+
recipientAccountType: AccountOwnerType.BUSINESS,
|
|
713
|
+
// POS authorization fields
|
|
714
|
+
engagedBusinessId: 'business-456',
|
|
715
|
+
authorizedSubmitterId: 'business-456',
|
|
716
|
+
authorizedSubmitterType: AccountOwnerType.BUSINESS
|
|
717
|
+
});
|
|
718
|
+
```
|
|
719
|
+
|
|
720
|
+
| POS Field | Type | Description |
|
|
721
|
+
|-----------|------|-------------|
|
|
722
|
+
| `engagedBusinessId` | `string` | Business commercially involved (for stats/reporting) |
|
|
723
|
+
| `authorizedSubmitterId` | `string` | Entity authorized to submit the signed transaction |
|
|
724
|
+
| `authorizedSubmitterType` | `AccountOwnerType` | Type of authorized submitter (`USER` or `BUSINESS`) |
|
|
725
|
+
```
|
|
726
|
+
|
|
541
727
|
### Purchase/Payment Processing
|
|
542
728
|
|
|
543
729
|
```typescript
|
|
@@ -825,6 +1011,108 @@ const claim = await sdk.campaigns.claimCampaign(claimRequest);
|
|
|
825
1011
|
|
|
826
1012
|
---
|
|
827
1013
|
|
|
1014
|
+
## Migration Guide
|
|
1015
|
+
|
|
1016
|
+
### v2.0.0 Breaking Changes - Pagination
|
|
1017
|
+
|
|
1018
|
+
**Version 2.0.0 introduces standardized pagination** across all list endpoints. Previously, endpoints returned raw arrays. Now they return `PaginatedResponseDTO<T>` with pagination metadata.
|
|
1019
|
+
|
|
1020
|
+
#### What Changed
|
|
1021
|
+
|
|
1022
|
+
All methods returning lists now return paginated responses:
|
|
1023
|
+
|
|
1024
|
+
```typescript
|
|
1025
|
+
// ❌ OLD (v1.x) - Direct array
|
|
1026
|
+
const businesses: BusinessDTO[] = await sdk.businesses.getActiveBusinesses();
|
|
1027
|
+
|
|
1028
|
+
// ✅ NEW (v2.x) - Paginated response
|
|
1029
|
+
const response: PaginatedResponseDTO<BusinessDTO> = await sdk.businesses.getActiveBusinesses();
|
|
1030
|
+
const businesses: BusinessDTO[] = response.data;
|
|
1031
|
+
```
|
|
1032
|
+
|
|
1033
|
+
#### Affected Methods
|
|
1034
|
+
|
|
1035
|
+
| Manager | Method | Return Type |
|
|
1036
|
+
|---------|--------|-------------|
|
|
1037
|
+
| `businesses` | `getActiveBusinesses()` | `PaginatedResponseDTO<BusinessDTO>` |
|
|
1038
|
+
| `businesses` | `getBusinessTypes()` | `PaginatedResponseDTO<BusinessTypeDTO>` |
|
|
1039
|
+
| `campaigns` | `getActiveCampaigns()` | `PaginatedResponseDTO<CampaignDTO>` |
|
|
1040
|
+
| `campaigns` | `getUserClaims()` | `PaginatedResponseDTO<CampaignClaimDTO>` |
|
|
1041
|
+
| `tokens` | `getTokens()` | `PaginatedResponseDTO<TokenDTO>` |
|
|
1042
|
+
| `tokens` | `getRewardTokens()` | `PaginatedResponseDTO<TokenDTO>` |
|
|
1043
|
+
| `tokens` | `getStatusTokens()` | `PaginatedResponseDTO<TokenDTO>` |
|
|
1044
|
+
| `redemptions` | `getRedemptions()` | `PaginatedResponseDTO<RedemptionDTO>` |
|
|
1045
|
+
| `redemptions` | `getUserRedemptions()` | `PaginatedResponseDTO<RedemptionDTO>` |
|
|
1046
|
+
| `transactions` | `getTransactionHistory()` | `PaginatedResponseDTO<TransactionDTO>` |
|
|
1047
|
+
| `purchases` | `getAllUserPurchases()` | `PaginatedResponseDTO<PurchaseDTO>` |
|
|
1048
|
+
| `purchases` | `getActivePurchaseTokens()` | `PaginatedResponseDTO<PurchaseTokenDTO>` |
|
|
1049
|
+
| `donations` | `getDonationTypes()` | `PaginatedResponseDTO<DonationTypeDTO>` |
|
|
1050
|
+
|
|
1051
|
+
#### PaginatedResponseDTO Structure
|
|
1052
|
+
|
|
1053
|
+
```typescript
|
|
1054
|
+
import type { PaginatedResponseDTO } from '@explorins/pers-shared';
|
|
1055
|
+
|
|
1056
|
+
interface PaginatedResponseDTO<T> {
|
|
1057
|
+
data: T[]; // Array of results
|
|
1058
|
+
pagination: {
|
|
1059
|
+
currentPage: number; // Current page number (1-indexed)
|
|
1060
|
+
pageSize: number; // Items per page
|
|
1061
|
+
totalItems: number; // Total number of items across all pages
|
|
1062
|
+
totalPages: number; // Total number of pages
|
|
1063
|
+
};
|
|
1064
|
+
}
|
|
1065
|
+
```
|
|
1066
|
+
|
|
1067
|
+
#### Migration Examples
|
|
1068
|
+
|
|
1069
|
+
**Before (v1.x):**
|
|
1070
|
+
```typescript
|
|
1071
|
+
const businesses = await sdk.businesses.getActiveBusinesses();
|
|
1072
|
+
console.log('Business count:', businesses.length);
|
|
1073
|
+
businesses.forEach(b => console.log(b.name));
|
|
1074
|
+
```
|
|
1075
|
+
|
|
1076
|
+
**After (v2.x):**
|
|
1077
|
+
```typescript
|
|
1078
|
+
const response = await sdk.businesses.getActiveBusinesses();
|
|
1079
|
+
console.log('Business count:', response.data.length);
|
|
1080
|
+
console.log('Total businesses:', response.pagination.totalItems);
|
|
1081
|
+
response.data.forEach(b => console.log(b.name));
|
|
1082
|
+
```
|
|
1083
|
+
|
|
1084
|
+
**With Pagination Parameters:**
|
|
1085
|
+
```typescript
|
|
1086
|
+
// Fetch page 2 with 20 items per page
|
|
1087
|
+
const response = await sdk.businesses.getActiveBusinesses({
|
|
1088
|
+
page: 2,
|
|
1089
|
+
pageSize: 20
|
|
1090
|
+
});
|
|
1091
|
+
|
|
1092
|
+
console.log(`Page ${response.pagination.currentPage} of ${response.pagination.totalPages}`);
|
|
1093
|
+
console.log(`Showing ${response.data.length} businesses`);
|
|
1094
|
+
```
|
|
1095
|
+
|
|
1096
|
+
#### Quick Fix for Existing Code
|
|
1097
|
+
|
|
1098
|
+
If you want minimal code changes, extract `.data` immediately:
|
|
1099
|
+
|
|
1100
|
+
```typescript
|
|
1101
|
+
// Quick adaptation
|
|
1102
|
+
const businesses = (await sdk.businesses.getActiveBusinesses()).data;
|
|
1103
|
+
const campaigns = (await sdk.campaigns.getActiveCampaigns()).data;
|
|
1104
|
+
const tokens = (await sdk.tokens.getTokens()).data;
|
|
1105
|
+
```
|
|
1106
|
+
|
|
1107
|
+
#### Benefits of Pagination
|
|
1108
|
+
|
|
1109
|
+
- **Performance**: Load only what you need, not entire datasets
|
|
1110
|
+
- **Consistency**: All list endpoints follow the same pattern
|
|
1111
|
+
- **Metadata**: Access total counts without loading all items
|
|
1112
|
+
- **UX**: Build proper pagination UI components
|
|
1113
|
+
|
|
1114
|
+
---
|
|
1115
|
+
|
|
828
1116
|
## Documentation
|
|
829
1117
|
|
|
830
1118
|
- **Getting Started Guide**: [https://docs.pers.ninja/1.intro](https://docs.pers.ninja/1.intro)
|
package/dist/analytics.cjs
CHANGED
|
@@ -15,8 +15,20 @@ Object.defineProperty(exports, "ApiKeyType", {
|
|
|
15
15
|
enumerable: true,
|
|
16
16
|
get: function () { return persShared.ApiKeyType; }
|
|
17
17
|
});
|
|
18
|
+
Object.defineProperty(exports, "MEMBERSHIP_ROLE_HIERARCHY", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () { return persShared.MEMBERSHIP_ROLE_HIERARCHY; }
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(exports, "MembershipRole", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function () { return persShared.MembershipRole; }
|
|
25
|
+
});
|
|
18
26
|
Object.defineProperty(exports, "NativeTokenTypes", {
|
|
19
27
|
enumerable: true,
|
|
20
28
|
get: function () { return persShared.NativeTokenTypes; }
|
|
21
29
|
});
|
|
30
|
+
Object.defineProperty(exports, "hasMinimumRole", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () { return persShared.hasMinimumRole; }
|
|
33
|
+
});
|
|
22
34
|
//# sourceMappingURL=analytics.cjs.map
|
package/dist/analytics.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"analytics.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"analytics.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/analytics.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { A as AnalyticsApi, a as AnalyticsService } from './chunks/analytics-service-CxyrOwel.js';
|
|
2
|
-
export { AccountOwnerType, ApiKeyType, NativeTokenTypes } from '@explorins/pers-shared';
|
|
2
|
+
export { AccountOwnerType, ApiKeyType, MEMBERSHIP_ROLE_HIERARCHY, MembershipRole, NativeTokenTypes, hasMinimumRole } from '@explorins/pers-shared';
|
|
3
3
|
//# sourceMappingURL=analytics.js.map
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { PersApiClient } from '../../core/pers-api-client';
|
|
2
2
|
import { ApiKeyDTO, ApiKeyCreatedDTO, ApiKeyRequestDTO, ApiKeyVerificationDTO, IntegrationApiKeyType } from '../../shared/interfaces/pers-shared-lib.interfaces';
|
|
3
|
+
import { PaginatedResponseDTO } from '@explorins/pers-shared';
|
|
4
|
+
import { PaginationOptions } from '../../shared';
|
|
3
5
|
/**
|
|
4
6
|
* Platform-Agnostic API Key API Client
|
|
5
7
|
*
|
|
@@ -15,9 +17,10 @@ export declare class ApiKeyApi {
|
|
|
15
17
|
*
|
|
16
18
|
* @param type Optional filter by integration API key type (database-stored tokens that can be revoked)
|
|
17
19
|
* @param includeRevoked Include revoked API keys in results (default: false)
|
|
18
|
-
* @
|
|
20
|
+
* @param options Pagination options (page, limit, sortBy, sortOrder)
|
|
21
|
+
* @returns Paginated response with API keys for the current tenant
|
|
19
22
|
*/
|
|
20
|
-
getTenantApiKeys(type?: IntegrationApiKeyType, includeRevoked?: boolean): Promise<ApiKeyDTO
|
|
23
|
+
getTenantApiKeys(type?: IntegrationApiKeyType, includeRevoked?: boolean, options?: PaginationOptions): Promise<PaginatedResponseDTO<ApiKeyDTO>>;
|
|
21
24
|
/**
|
|
22
25
|
* ADMIN: Create new API key
|
|
23
26
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-key-api.d.ts","sourceRoot":"","sources":["../../../src/api-key/api/api-key-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,qBAAqB,EACtB,MAAM,oDAAoD,CAAC;
|
|
1
|
+
{"version":3,"file":"api-key-api.d.ts","sourceRoot":"","sources":["../../../src/api-key/api/api-key-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,gBAAgB,EAChB,qBAAqB,EACrB,qBAAqB,EACtB,MAAM,oDAAoD,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,iBAAiB,EAA6D,MAAM,cAAc,CAAC;AAE5G;;;;;GAKG;AACH,qBAAa,SAAS;IAGR,OAAO,CAAC,SAAS;IAF7B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAe;gBAEpB,SAAS,EAAE,aAAa;IAE5C;;;;;;;OAOG;IACG,gBAAgB,CAAC,IAAI,CAAC,EAAE,qBAAqB,EAAE,cAAc,GAAE,OAAe,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,oBAAoB,CAAC,SAAS,CAAC,CAAC;IAS5J;;;;;OAKG;IACG,YAAY,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAIpE;;;;;OAKG;IACG,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,qBAAqB,CAAC;CAGrE"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { PersApiClient } from '../../core/pers-api-client';
|
|
2
2
|
import { BusinessDTO, BusinessTypeDTO, BusinessUpdateRequestDTO, BusinessCreateRequestDTO, BusinessToggleActiveRequestDTO, BusinessApiKeyDTO, BusinessTokenBalancesDTO, BusinessTypeCreateRequestDTO } from '../../shared/interfaces/pers-shared-lib.interfaces';
|
|
3
|
+
import { PaginationOptions } from '../../shared/utils/pagination-utils';
|
|
4
|
+
import { PaginatedResponseDTO, SortOrder } from '@explorins/pers-shared';
|
|
3
5
|
/**
|
|
4
6
|
* Platform-Agnostic Business API Client
|
|
5
7
|
*
|
|
@@ -17,8 +19,11 @@ export declare class BusinessApi {
|
|
|
17
19
|
*
|
|
18
20
|
* Endpoint: GET /business-types
|
|
19
21
|
* Auth: @ApiSecurity('projectKey')
|
|
22
|
+
*
|
|
23
|
+
* @param options Pagination options (page, limit, sortBy, sortOrder)
|
|
24
|
+
* @returns Paginated response with business types
|
|
20
25
|
*/
|
|
21
|
-
getBusinessTypes(): Promise<BusinessTypeDTO
|
|
26
|
+
getBusinessTypes(options?: PaginationOptions): Promise<PaginatedResponseDTO<BusinessTypeDTO>>;
|
|
22
27
|
/**
|
|
23
28
|
* ADMIN: Create business type
|
|
24
29
|
*
|
|
@@ -48,25 +53,39 @@ export declare class BusinessApi {
|
|
|
48
53
|
*/
|
|
49
54
|
getCurrentBusiness(): Promise<BusinessTokenBalancesDTO>;
|
|
50
55
|
/**
|
|
51
|
-
* Get all businesses with role-based filtering
|
|
56
|
+
* Get all businesses with role-based filtering and pagination
|
|
52
57
|
*
|
|
53
|
-
* Endpoint: GET /businesses?active={boolean}&sanitize={mode}
|
|
58
|
+
* Endpoint: GET /businesses?active={boolean}&sanitize={mode}&page={number}&limit={number}
|
|
54
59
|
* Auth: @ApiSecurity('projectKey') (enhanced with role-based filtering)
|
|
60
|
+
*
|
|
55
61
|
* Note:
|
|
56
62
|
* - Project API Key users: Active businesses only (automatically filtered)
|
|
57
63
|
* - Admin JWT users: Full access with all query parameters
|
|
64
|
+
*
|
|
65
|
+
* @param options - Filter and pagination options
|
|
66
|
+
* @returns Paginated list of businesses
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* // Get first page of active businesses
|
|
71
|
+
* const page1 = await businessApi.getBusinesses({ active: true });
|
|
72
|
+
*
|
|
73
|
+
* // Get all businesses (admin only) with pagination
|
|
74
|
+
* const page2 = await businessApi.getBusinesses({
|
|
75
|
+
* page: 2,
|
|
76
|
+
* limit: 25,
|
|
77
|
+
* sanitize: 'soft'
|
|
78
|
+
* });
|
|
79
|
+
* ```
|
|
58
80
|
*/
|
|
59
81
|
getBusinesses(options?: {
|
|
60
82
|
active?: boolean;
|
|
61
83
|
sanitize?: 'soft' | 'hard';
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
* Auth: @ApiSecurity('projectKey')
|
|
68
|
-
*/
|
|
69
|
-
getActiveBusinesses(): Promise<BusinessDTO[]>;
|
|
84
|
+
page?: number;
|
|
85
|
+
limit?: number;
|
|
86
|
+
sortBy?: string;
|
|
87
|
+
sortOrder?: SortOrder;
|
|
88
|
+
}): Promise<PaginatedResponseDTO<BusinessDTO>>;
|
|
70
89
|
/**
|
|
71
90
|
* Get business by ID
|
|
72
91
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"business-api.d.ts","sourceRoot":"","sources":["../../../src/business/api/business-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EACL,WAAW,EACX,eAAe,EACf,wBAAwB,EACxB,wBAAwB,EACxB,8BAA8B,EAC9B,iBAAiB,EACjB,wBAAwB,EACxB,4BAA4B,EAC7B,MAAM,oDAAoD,CAAC;
|
|
1
|
+
{"version":3,"file":"business-api.d.ts","sourceRoot":"","sources":["../../../src/business/api/business-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EACL,WAAW,EACX,eAAe,EACf,wBAAwB,EACxB,wBAAwB,EACxB,8BAA8B,EAC9B,iBAAiB,EACjB,wBAAwB,EACxB,4BAA4B,EAC7B,MAAM,oDAAoD,CAAC;AAC5D,OAAO,EAAE,iBAAiB,EAA6D,MAAM,qCAAqC,CAAC;AACnI,OAAO,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEzE;;;;;;GAMG;AACH,qBAAa,WAAW;IACV,OAAO,CAAC,SAAS;gBAAT,SAAS,EAAE,aAAa;IAE5C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAiB;IAC1C,OAAO,CAAC,QAAQ,CAAC,iBAAiB,CAAuB;IAMzD;;;;;;;;OAQG;IACG,gBAAgB,CAAC,OAAO,CAAC,EAAE,iBAAiB,GAAG,OAAO,CAAC,oBAAoB,CAAC,eAAe,CAAC,CAAC;IAMnG;;;;;OAKG;IACG,kBAAkB,CAAC,GAAG,EAAE,4BAA4B,GAAG,OAAO,CAAC,eAAe,CAAC;IAIrF;;;;;OAKG;IACG,kBAAkB,CAAC,GAAG,EAAE,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC;IAIxE;;;;;OAKG;IACG,kBAAkB,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAQtD;;;;;OAKG;IACG,kBAAkB,IAAI,OAAO,CAAC,wBAAwB,CAAC;IAI7D;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACG,aAAa,CAAC,OAAO,CAAC,EAAE;QAC5B,MAAM,CAAC,EAAE,OAAO,CAAC;QACjB,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;QAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,SAAS,CAAC;KACvB,GAAG,OAAO,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC;IAkB9C;;;;;OAKG;IACG,eAAe,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAI/D;;;;;OAKG;IACG,oBAAoB,CAAC,cAAc,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAQxE;;;;;;OAMG;IACG,cAAc,CAAC,GAAG,EAAE,wBAAwB,GAAG,OAAO,CAAC,iBAAiB,GAAG,wBAAwB,CAAC;IAI1G;;OAEG;IACG,2BAA2B,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,GAAG,wBAAwB,CAAC;IAQ7G;;;;;OAKG;IACG,uBAAuB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAIlE;;;;;OAKG;IACG,cAAc,CAAC,EAAE,EAAE,MAAM,EAAE,YAAY,EAAE,wBAAwB,GAAG,OAAO,CAAC,WAAW,CAAC;IAI9F;;;;;OAKG;IACG,oBAAoB,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,8BAA8B,GAAG,OAAO,CAAC,WAAW,CAAC;CAiBlG"}
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
import { PersApiClient } from '../../core/pers-api-client';
|
|
2
|
+
import { BusinessMembershipDTO, AddBusinessMemberRequestDTO, UpdateBusinessMembershipRequestDTO, MembershipRole } from '../../shared/interfaces/pers-shared-lib.interfaces';
|
|
3
|
+
import { PaginatedResponseDTO, SortOrder } from '@explorins/pers-shared';
|
|
4
|
+
/**
|
|
5
|
+
* Business Membership API Client
|
|
6
|
+
*
|
|
7
|
+
* Platform-agnostic API client for managing business memberships.
|
|
8
|
+
* Handles user access to businesses with role-based permissions.
|
|
9
|
+
*
|
|
10
|
+
* Base Path: /businesses/:businessId/members
|
|
11
|
+
*
|
|
12
|
+
* Required Headers:
|
|
13
|
+
* - Authorization: Bearer <business_jwt_token>
|
|
14
|
+
* - X-Project-Key: <project_key>
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* const membershipApi = new BusinessMembershipApi(apiClient);
|
|
19
|
+
*
|
|
20
|
+
* // List all members of a business
|
|
21
|
+
* const members = await membershipApi.getMembers('business-123');
|
|
22
|
+
*
|
|
23
|
+
* // Add a new member
|
|
24
|
+
* const newMember = await membershipApi.addMember('business-123', {
|
|
25
|
+
* userId: 'user-456',
|
|
26
|
+
* role: MembershipRole.EDITOR
|
|
27
|
+
* });
|
|
28
|
+
* ```
|
|
29
|
+
*
|
|
30
|
+
* @version 2.0.0
|
|
31
|
+
*/
|
|
32
|
+
export declare class BusinessMembershipApi {
|
|
33
|
+
private apiClient;
|
|
34
|
+
constructor(apiClient: PersApiClient);
|
|
35
|
+
/**
|
|
36
|
+
* Build the membership endpoint path for a business
|
|
37
|
+
*/
|
|
38
|
+
private getMembersPath;
|
|
39
|
+
/**
|
|
40
|
+
* Build the membership endpoint path for a specific member
|
|
41
|
+
*/
|
|
42
|
+
private getMemberPath;
|
|
43
|
+
/**
|
|
44
|
+
* List all members of a business with pagination
|
|
45
|
+
*
|
|
46
|
+
* Endpoint: GET /businesses/:businessId/members
|
|
47
|
+
* Min Role: VIEWER (any member can view)
|
|
48
|
+
*
|
|
49
|
+
* @param businessId - The business UUID
|
|
50
|
+
* @param options - Pagination and filter options
|
|
51
|
+
* @returns Paginated array of business memberships with user and role details
|
|
52
|
+
*
|
|
53
|
+
* @throws {AuthenticationError} 401 - Not authenticated
|
|
54
|
+
* @throws {PersApiError} 403 - businessId in path doesn't match JWT's business
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* // Get first page of members
|
|
59
|
+
* const page1 = await membershipApi.getMembers('business-123');
|
|
60
|
+
* page1.data.forEach(m => console.log(`${m.userId}: ${m.role}`));
|
|
61
|
+
*
|
|
62
|
+
* // Filter by role
|
|
63
|
+
* const admins = await membershipApi.getMembers('business-123', {
|
|
64
|
+
* role: MembershipRole.ADMIN,
|
|
65
|
+
* page: 1,
|
|
66
|
+
* limit: 50
|
|
67
|
+
* });
|
|
68
|
+
*
|
|
69
|
+
* // Paginate through all members
|
|
70
|
+
* const page2 = await membershipApi.getMembers('business-123', { page: 2 });
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
getMembers(businessId: string, options?: {
|
|
74
|
+
page?: number;
|
|
75
|
+
limit?: number;
|
|
76
|
+
role?: MembershipRole;
|
|
77
|
+
sortBy?: string;
|
|
78
|
+
sortOrder?: SortOrder;
|
|
79
|
+
}): Promise<PaginatedResponseDTO<BusinessMembershipDTO>>;
|
|
80
|
+
/**
|
|
81
|
+
* Add a member to a business
|
|
82
|
+
*
|
|
83
|
+
* Endpoint: POST /businesses/:businessId/members
|
|
84
|
+
* Min Role: ADMIN
|
|
85
|
+
*
|
|
86
|
+
* @param businessId - The business UUID
|
|
87
|
+
* @param request - The add member request with userId and optional role
|
|
88
|
+
* @returns The created business membership
|
|
89
|
+
*
|
|
90
|
+
* @throws {AuthenticationError} 401 - Not authenticated
|
|
91
|
+
* @throws {PersApiError} 403 - Insufficient role (requires ADMIN or higher)
|
|
92
|
+
* @throws {PersApiError} 404 - User not found
|
|
93
|
+
* @throws {PersApiError} 409 - User is already a member
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const newMember = await membershipApi.addMember('business-123', {
|
|
98
|
+
* userId: 'user-456',
|
|
99
|
+
* role: MembershipRole.EDITOR
|
|
100
|
+
* });
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
addMember(businessId: string, request: AddBusinessMemberRequestDTO): Promise<BusinessMembershipDTO>;
|
|
104
|
+
/**
|
|
105
|
+
* Add a member to a business with explicit parameters
|
|
106
|
+
*
|
|
107
|
+
* Convenience method that constructs the request DTO internally.
|
|
108
|
+
*
|
|
109
|
+
* @param businessId - The business UUID
|
|
110
|
+
* @param userId - The user UUID to add
|
|
111
|
+
* @param role - The role to assign (defaults to VIEWER)
|
|
112
|
+
* @returns The created business membership
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```typescript
|
|
116
|
+
* const member = await membershipApi.addMemberByUserId(
|
|
117
|
+
* 'business-123',
|
|
118
|
+
* 'user-456',
|
|
119
|
+
* MembershipRole.EDITOR
|
|
120
|
+
* );
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
addMemberByUserId(businessId: string, userId: string, role?: MembershipRole): Promise<BusinessMembershipDTO>;
|
|
124
|
+
/**
|
|
125
|
+
* Update a member's role in a business
|
|
126
|
+
*
|
|
127
|
+
* Endpoint: PUT /businesses/:businessId/members/:userId
|
|
128
|
+
* Min Role: ADMIN
|
|
129
|
+
*
|
|
130
|
+
* Business Rules:
|
|
131
|
+
* - Cannot demote the last OWNER (must transfer ownership first)
|
|
132
|
+
* - Can only assign roles up to your own level (ADMIN cannot create OWNER)
|
|
133
|
+
*
|
|
134
|
+
* @param businessId - The business UUID
|
|
135
|
+
* @param userId - The user UUID to update
|
|
136
|
+
* @param request - The update request with new role
|
|
137
|
+
* @returns The updated business membership
|
|
138
|
+
*
|
|
139
|
+
* @throws {AuthenticationError} 401 - Not authenticated
|
|
140
|
+
* @throws {PersApiError} 403 - Insufficient role (requires ADMIN or higher)
|
|
141
|
+
* @throws {PersApiError} 404 - Membership not found
|
|
142
|
+
* @throws {PersApiError} 400 - Cannot demote last OWNER
|
|
143
|
+
*
|
|
144
|
+
* @example
|
|
145
|
+
* ```typescript
|
|
146
|
+
* const updated = await membershipApi.updateMemberRole(
|
|
147
|
+
* 'business-123',
|
|
148
|
+
* 'user-456',
|
|
149
|
+
* { role: MembershipRole.ADMIN }
|
|
150
|
+
* );
|
|
151
|
+
* ```
|
|
152
|
+
*/
|
|
153
|
+
updateMemberRole(businessId: string, userId: string, request: UpdateBusinessMembershipRequestDTO): Promise<BusinessMembershipDTO>;
|
|
154
|
+
/**
|
|
155
|
+
* Update a member's role with explicit parameters
|
|
156
|
+
*
|
|
157
|
+
* Convenience method that constructs the request DTO internally.
|
|
158
|
+
*
|
|
159
|
+
* @param businessId - The business UUID
|
|
160
|
+
* @param userId - The user UUID to update
|
|
161
|
+
* @param role - The new role to assign
|
|
162
|
+
* @returns The updated business membership
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* const updated = await membershipApi.setMemberRole(
|
|
167
|
+
* 'business-123',
|
|
168
|
+
* 'user-456',
|
|
169
|
+
* MembershipRole.ADMIN
|
|
170
|
+
* );
|
|
171
|
+
* ```
|
|
172
|
+
*/
|
|
173
|
+
setMemberRole(businessId: string, userId: string, role: MembershipRole): Promise<BusinessMembershipDTO>;
|
|
174
|
+
/**
|
|
175
|
+
* Remove a member from a business
|
|
176
|
+
*
|
|
177
|
+
* Endpoint: DELETE /businesses/:businessId/members/:userId
|
|
178
|
+
* Min Role: ADMIN
|
|
179
|
+
*
|
|
180
|
+
* Business Rules:
|
|
181
|
+
* - Cannot remove the last OWNER
|
|
182
|
+
* - Cannot remove yourself (use leave endpoint or transfer ownership)
|
|
183
|
+
*
|
|
184
|
+
* @param businessId - The business UUID
|
|
185
|
+
* @param userId - The user UUID to remove
|
|
186
|
+
* @returns Success confirmation
|
|
187
|
+
*
|
|
188
|
+
* @throws {AuthenticationError} 401 - Not authenticated
|
|
189
|
+
* @throws {PersApiError} 403 - Insufficient role (requires ADMIN or higher)
|
|
190
|
+
* @throws {PersApiError} 404 - Membership not found
|
|
191
|
+
* @throws {PersApiError} 400 - Cannot remove last OWNER
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```typescript
|
|
195
|
+
* const result = await membershipApi.removeMember('business-123', 'user-456');
|
|
196
|
+
* if (result.success) {
|
|
197
|
+
* console.log('Member removed successfully');
|
|
198
|
+
* }
|
|
199
|
+
* ```
|
|
200
|
+
*/
|
|
201
|
+
removeMember(businessId: string, userId: string): Promise<{
|
|
202
|
+
success: boolean;
|
|
203
|
+
}>;
|
|
204
|
+
}
|
|
205
|
+
//# sourceMappingURL=business-membership-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"business-membership-api.d.ts","sourceRoot":"","sources":["../../../src/business/api/business-membership-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EACL,qBAAqB,EACrB,2BAA2B,EAC3B,kCAAkC,EAClC,cAAc,EACf,MAAM,oDAAoD,CAAC;AAE5D,OAAO,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAEzE;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,qBAAa,qBAAqB;IACpB,OAAO,CAAC,SAAS;gBAAT,SAAS,EAAE,aAAa;IAE5C;;OAEG;IACH,OAAO,CAAC,cAAc;IAItB;;OAEG;IACH,OAAO,CAAC,aAAa;IAQrB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACG,UAAU,CACd,UAAU,EAAE,MAAM,EAClB,OAAO,CAAC,EAAE;QACR,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,IAAI,CAAC,EAAE,cAAc,CAAC;QACtB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,SAAS,CAAC,EAAE,SAAS,CAAC;KACvB,GACA,OAAO,CAAC,oBAAoB,CAAC,qBAAqB,CAAC,CAAC;IAkBvD;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACG,SAAS,CACb,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,qBAAqB,CAAC;IAOjC;;;;;;;;;;;;;;;;;;OAkBG;IACG,iBAAiB,CACrB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,IAAI,GAAE,cAAsC,GAC3C,OAAO,CAAC,qBAAqB,CAAC;IAQjC;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACG,gBAAgB,CACpB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,kCAAkC,GAC1C,OAAO,CAAC,qBAAqB,CAAC;IAOjC;;;;;;;;;;;;;;;;;;OAkBG;IACG,aAAa,CACjB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,cAAc,GACnB,OAAO,CAAC,qBAAqB,CAAC;IAQjC;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACG,YAAY,CAChB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM,GACb,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAA;KAAE,CAAC;CAKjC"}
|
package/dist/business/index.d.ts
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
* Focuses on non-admin business operations
|
|
6
6
|
*/
|
|
7
7
|
export { BusinessApi } from './api/business-api';
|
|
8
|
+
export { BusinessMembershipApi } from './api/business-membership-api';
|
|
8
9
|
export { BusinessService } from './services/business-service';
|
|
10
|
+
export { BusinessMembershipService } from './services/business-membership-service';
|
|
9
11
|
export * from '../shared/interfaces/pers-shared-lib.interfaces';
|
|
10
12
|
//# sourceMappingURL=index.d.ts.map
|