@explorins/pers-sdk 1.6.6 → 1.6.10
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 +90 -367
- package/dist/chunks/{pers-sdk-eO4XUi8w.js → pers-sdk-DOuNyWFC.js} +112 -263
- package/dist/chunks/pers-sdk-DOuNyWFC.js.map +1 -0
- package/dist/chunks/{pers-sdk-CajYwGkL.cjs → pers-sdk-kb7j1DVU.cjs} +111 -263
- package/dist/chunks/pers-sdk-kb7j1DVU.cjs.map +1 -0
- package/dist/chunks/{web3-chain-service-BYkj61DN.cjs → web3-chain-service-D75TcHkh.cjs} +28 -21
- package/dist/chunks/web3-chain-service-D75TcHkh.cjs.map +1 -0
- package/dist/chunks/{web3-chain-service-DN6tJmvK.js → web3-chain-service-Dp5Z8p9I.js} +28 -22
- package/dist/chunks/web3-chain-service-Dp5Z8p9I.js.map +1 -0
- package/dist/core/auth/api/auth-api.d.ts +11 -14
- package/dist/core/auth/api/auth-api.d.ts.map +1 -1
- package/dist/core/auth/auth-provider.interface.d.ts +10 -5
- package/dist/core/auth/auth-provider.interface.d.ts.map +1 -1
- package/dist/core/auth/default-auth-provider.d.ts +3 -6
- package/dist/core/auth/default-auth-provider.d.ts.map +1 -1
- package/dist/core/auth/index.d.ts +2 -6
- package/dist/core/auth/index.d.ts.map +1 -1
- package/dist/core/auth/refresh-manager.d.ts +2 -5
- package/dist/core/auth/refresh-manager.d.ts.map +1 -1
- package/dist/core/auth/services/auth-service.d.ts +9 -20
- package/dist/core/auth/services/auth-service.d.ts.map +1 -1
- package/dist/core/auth/token-storage.d.ts +2 -4
- package/dist/core/auth/token-storage.d.ts.map +1 -1
- package/dist/core/environment.d.ts +2 -4
- package/dist/core/environment.d.ts.map +1 -1
- package/dist/core/index.d.ts +0 -2
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/pers-api-client.d.ts +8 -34
- package/dist/core/pers-api-client.d.ts.map +1 -1
- package/dist/core/pers-config.d.ts +5 -9
- package/dist/core/pers-config.d.ts.map +1 -1
- package/dist/core/utils/jwt.function.d.ts +9 -0
- package/dist/core/utils/jwt.function.d.ts.map +1 -1
- package/dist/core.cjs +3 -4
- package/dist/core.cjs.map +1 -1
- package/dist/core.js +3 -4
- package/dist/core.js.map +1 -1
- package/dist/file/services/file-service.d.ts +0 -4
- package/dist/file/services/file-service.d.ts.map +1 -1
- package/dist/index.cjs +2 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/dist/managers/file-manager.d.ts +9 -9
- package/dist/managers/file-manager.d.ts.map +1 -1
- package/dist/package.json +2 -3
- package/dist/web3-chain.cjs +1 -2
- package/dist/web3-chain.cjs.map +1 -1
- package/dist/web3-chain.js +1 -2
- package/dist/web3-chain.js.map +1 -1
- package/package.json +2 -3
- package/dist/chunks/pers-sdk-CajYwGkL.cjs.map +0 -1
- package/dist/chunks/pers-sdk-eO4XUi8w.js.map +0 -1
- package/dist/chunks/web3-chain-service-BYkj61DN.cjs.map +0 -1
- package/dist/chunks/web3-chain-service-DN6tJmvK.js.map +0 -1
package/README.md
CHANGED
|
@@ -3,18 +3,9 @@
|
|
|
3
3
|
[](https://badge.fury.io/js/%40explorins%2Fpers-sdk)
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
|
|
6
|
-
|
|
6
|
+
Platform-agnostic TypeScript SDK for PERS (Phygital Experience Rewards System) - Modern Manager-Service architecture providing clean, consistent APIs for tourism loyalty applications.
|
|
7
7
|
|
|
8
|
-
##
|
|
9
|
-
|
|
10
|
-
**🎯 Complete Architecture Refactoring**
|
|
11
|
-
- **Clean Manager Pattern**: All 15 domain managers use consistent Service-based architecture
|
|
12
|
-
- **Legacy Pattern Removal**: Eliminated all factory functions for cleaner, predictable patterns
|
|
13
|
-
- **Performance Optimized**: 29% faster builds, reduced bundle size, internal token refresh
|
|
14
|
-
- **Zero Breaking Changes**: Manager interface remains identical for seamless upgrades
|
|
15
|
-
- **Enhanced Documentation**: Comprehensive guides with practical examples
|
|
16
|
-
|
|
17
|
-
## PERS Ecosystem
|
|
8
|
+
## Overview
|
|
18
9
|
|
|
19
10
|
PERS is a comprehensive tourism loyalty platform bridging physical and digital experiences through loyalty programs, campaign management, payments, blockchain integration, business management, and analytics.
|
|
20
11
|
|
|
@@ -24,43 +15,7 @@ PERS is a comprehensive tourism loyalty platform bridging physical and digital e
|
|
|
24
15
|
npm install @explorins/pers-sdk
|
|
25
16
|
```
|
|
26
17
|
|
|
27
|
-
##
|
|
28
|
-
|
|
29
|
-
- **[@explorins/pers-sdk-angular](https://www.npmjs.com/package/@explorins/pers-sdk-angular)** - Angular dependency injection wrapper
|
|
30
|
-
- **[@explorins/pers-sdk-react-native](https://www.npmjs.com/package/@explorins/pers-sdk-react-native)** - React Native providers and hooks
|
|
31
|
-
- **Direct Integration** - Node.js, Vanilla JS, React, Vue, or custom frameworks
|
|
32
|
-
|
|
33
|
-
## 🏗️ Architecture Overview
|
|
34
|
-
|
|
35
|
-
```typescript
|
|
36
|
-
PERS SDK v1.6.6 - Clean Manager Pattern Architecture
|
|
37
|
-
├── 🎯 Manager Layer (Primary Interface)
|
|
38
|
-
│ ├── auth: AuthManager // Authentication & sessions
|
|
39
|
-
│ ├── users: UserManager // User profiles & management
|
|
40
|
-
│ ├── tokens: TokenManager // Token operations & balances
|
|
41
|
-
│ ├── businesses: BusinessManager // Business operations
|
|
42
|
-
│ ├── campaigns: CampaignManager // Marketing campaigns
|
|
43
|
-
│ ├── redemptions: RedemptionManager // Reward redemptions
|
|
44
|
-
│ ├── transactions: TransactionManager // Transaction history
|
|
45
|
-
│ ├── purchases: PurchaseManager // Payment processing
|
|
46
|
-
│ ├── analytics: AnalyticsManager // Reporting & insights
|
|
47
|
-
│ ├── tenants: TenantManager // Multi-tenant config
|
|
48
|
-
│ ├── donations: DonationManager // Charitable giving
|
|
49
|
-
│ ├── files: FileManager // File operations
|
|
50
|
-
│ └── web3: Web3Manager // Blockchain operations
|
|
51
|
-
├── ⚙️ Service Layer (Advanced Access)
|
|
52
|
-
│ ├── Business logic & operations
|
|
53
|
-
│ └── Direct service method access via getXService()
|
|
54
|
-
└── 🚀 Core Infrastructure
|
|
55
|
-
├── PersApiClient (HTTP + auth)
|
|
56
|
-
└── Platform adapters
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
## ⚡ Quick Start
|
|
60
|
-
|
|
61
|
-
### 1. Choose Your Integration Method
|
|
62
|
-
|
|
63
|
-
#### 🎯 **Recommended: Manager Pattern**
|
|
18
|
+
## Quick Start
|
|
64
19
|
|
|
65
20
|
```typescript
|
|
66
21
|
import { PersSDK } from '@explorins/pers-sdk';
|
|
@@ -71,58 +26,49 @@ const sdk = new PersSDK(new BrowserFetchClientAdapter(), {
|
|
|
71
26
|
apiProjectKey: 'your-project-key'
|
|
72
27
|
});
|
|
73
28
|
|
|
74
|
-
//
|
|
29
|
+
// Authentication
|
|
75
30
|
const user = await sdk.auth.getCurrentUser();
|
|
76
|
-
const campaigns = await sdk.campaigns.getActiveCampaigns();
|
|
77
|
-
const tokens = await sdk.tokens.getTokens();
|
|
78
|
-
```
|
|
79
31
|
|
|
80
|
-
|
|
32
|
+
// Business operations
|
|
33
|
+
const businesses = await sdk.businesses.getActiveBusinesses();
|
|
81
34
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
const
|
|
85
|
-
const campaignService = sdk.campaigns.getCampaignService();
|
|
35
|
+
// Campaign management
|
|
36
|
+
const campaigns = await sdk.campaigns.getActiveCampaigns();
|
|
37
|
+
const campaignClaim = await sdk.campaigns.claimCampaign({ campaignId: 'campaign-123', userId: 'user-456' });
|
|
86
38
|
|
|
87
|
-
//
|
|
88
|
-
const
|
|
89
|
-
const
|
|
39
|
+
// Token operations
|
|
40
|
+
const tokens = await sdk.tokens.getTokens();
|
|
41
|
+
const balances = await sdk.tokens.getBalances(userId);
|
|
90
42
|
```
|
|
91
43
|
|
|
92
|
-
|
|
44
|
+
## Platform Integration
|
|
93
45
|
|
|
94
|
-
|
|
46
|
+
### Angular
|
|
95
47
|
|
|
96
48
|
```typescript
|
|
97
|
-
// app.config.ts
|
|
98
|
-
import { provideHttpClient } from '@angular/common/http';
|
|
99
|
-
import { PersSDKService } from 'your-app/services/pers-sdk.service';
|
|
100
|
-
|
|
101
|
-
export const appConfig = {
|
|
102
|
-
providers: [
|
|
103
|
-
provideHttpClient(),
|
|
104
|
-
PersSDKService
|
|
105
|
-
]
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
// pers-sdk.service.ts
|
|
109
49
|
import { Injectable } from '@angular/core';
|
|
110
50
|
import { HttpClient } from '@angular/common/http';
|
|
111
51
|
import { PersSDK } from '@explorins/pers-sdk';
|
|
112
52
|
import { AngularHttpClientAdapter } from '@explorins/pers-sdk/platform-adapters';
|
|
113
53
|
|
|
114
54
|
@Injectable({ providedIn: 'root' })
|
|
115
|
-
export class PersSDKService
|
|
55
|
+
export class PersSDKService {
|
|
56
|
+
private sdk: PersSDK;
|
|
57
|
+
|
|
116
58
|
constructor(httpClient: HttpClient) {
|
|
117
|
-
|
|
59
|
+
this.sdk = new PersSDK(new AngularHttpClientAdapter(httpClient), {
|
|
118
60
|
environment: 'production',
|
|
119
61
|
apiProjectKey: 'your-project-key'
|
|
120
62
|
});
|
|
121
63
|
}
|
|
64
|
+
|
|
65
|
+
getSDK(): PersSDK {
|
|
66
|
+
return this.sdk;
|
|
67
|
+
}
|
|
122
68
|
}
|
|
123
69
|
```
|
|
124
70
|
|
|
125
|
-
|
|
71
|
+
### React/Browser
|
|
126
72
|
|
|
127
73
|
```typescript
|
|
128
74
|
import { PersSDK } from '@explorins/pers-sdk';
|
|
@@ -132,14 +78,9 @@ const sdk = new PersSDK(new BrowserFetchClientAdapter(), {
|
|
|
132
78
|
environment: 'production',
|
|
133
79
|
apiProjectKey: 'your-project-key'
|
|
134
80
|
});
|
|
135
|
-
|
|
136
|
-
// React Hook example
|
|
137
|
-
export function usePersSDK() {
|
|
138
|
-
return sdk;
|
|
139
|
-
}
|
|
140
81
|
```
|
|
141
82
|
|
|
142
|
-
|
|
83
|
+
### Node.js
|
|
143
84
|
|
|
144
85
|
```typescript
|
|
145
86
|
import { PersSDK } from '@explorins/pers-sdk';
|
|
@@ -151,207 +92,77 @@ const sdk = new PersSDK(new NodeHttpClientAdapter(), {
|
|
|
151
92
|
});
|
|
152
93
|
```
|
|
153
94
|
|
|
154
|
-
##
|
|
155
|
-
|
|
156
|
-
### 🔐 Authentication Manager
|
|
157
|
-
|
|
158
|
-
```typescript
|
|
159
|
-
// Login with external JWT (Firebase, Auth0, etc.)
|
|
160
|
-
const authResult = await sdk.auth.loginWithToken(jwtToken, 'user');
|
|
161
|
-
const adminResult = await sdk.auth.loginWithToken(adminJWT, 'admin');
|
|
162
|
-
|
|
163
|
-
// Check authentication status
|
|
164
|
-
const isAuthenticated = await sdk.auth.isAuthenticated();
|
|
165
|
-
const hasValidAuth = sdk.auth.hasValidAuth();
|
|
166
|
-
|
|
167
|
-
// User management
|
|
168
|
-
const currentUser = await sdk.auth.getCurrentUser();
|
|
169
|
-
|
|
170
|
-
// Token management
|
|
171
|
-
const newTokens = await sdk.auth.refreshTokens();
|
|
172
|
-
await sdk.auth.clearAuth();
|
|
173
|
-
```
|
|
174
|
-
|
|
175
|
-
### 👤 User Manager
|
|
176
|
-
|
|
177
|
-
```typescript
|
|
178
|
-
// Current user operations
|
|
179
|
-
const user = await sdk.users.getCurrentUser();
|
|
180
|
-
await sdk.users.updateCurrentUser(userData);
|
|
181
|
-
|
|
182
|
-
// User lookup
|
|
183
|
-
const userById = await sdk.users.getUserById(identifier);
|
|
184
|
-
const publicProfiles = await sdk.users.getAllUsersPublic();
|
|
185
|
-
|
|
186
|
-
// Admin operations
|
|
187
|
-
const allUsers = await sdk.users.getAllUsers();
|
|
188
|
-
await sdk.users.updateUser(userId, userData);
|
|
189
|
-
await sdk.users.toggleUserStatus(user);
|
|
190
|
-
```
|
|
191
|
-
|
|
192
|
-
### 🪙 Token Manager
|
|
193
|
-
|
|
194
|
-
```typescript
|
|
195
|
-
// Token operations
|
|
196
|
-
const tokens = await sdk.tokens.getTokens();
|
|
197
|
-
const creditToken = await sdk.tokens.getActiveCreditToken();
|
|
198
|
-
const rewardTokens = await sdk.tokens.getRewardTokens();
|
|
199
|
-
|
|
200
|
-
// Balance operations
|
|
201
|
-
const balances = await sdk.tokens.getBalances(userId);
|
|
202
|
-
await sdk.tokens.transferTokens(transferData);
|
|
203
|
-
```
|
|
204
|
-
|
|
205
|
-
### 🏢 Business Manager
|
|
206
|
-
|
|
207
|
-
```typescript
|
|
208
|
-
// Public business operations
|
|
209
|
-
const businesses = await sdk.businesses.getActiveBusinesses();
|
|
210
|
-
const business = await sdk.businesses.getBusinessById(id);
|
|
211
|
-
const types = await sdk.businesses.getBusinessTypes();
|
|
212
|
-
|
|
213
|
-
// Admin operations
|
|
214
|
-
const allBusinesses = await sdk.businesses.getBusinesses();
|
|
215
|
-
await sdk.businesses.createBusiness(businessData);
|
|
216
|
-
await sdk.businesses.updateBusiness(id, businessData);
|
|
217
|
-
```
|
|
218
|
-
|
|
219
|
-
### 🎯 Campaign Manager
|
|
220
|
-
|
|
221
|
-
```typescript
|
|
222
|
-
// Public campaign operations
|
|
223
|
-
const campaigns = await sdk.campaigns.getActiveCampaigns();
|
|
224
|
-
const campaign = await sdk.campaigns.getCampaignById(id);
|
|
225
|
-
|
|
226
|
-
// User operations
|
|
227
|
-
await sdk.campaigns.claimCampaign(claimData);
|
|
228
|
-
const userClaims = await sdk.campaigns.getUserClaims();
|
|
229
|
-
|
|
230
|
-
// Admin operations
|
|
231
|
-
const allCampaigns = await sdk.campaigns.getAllCampaigns();
|
|
232
|
-
await sdk.campaigns.createCampaign(campaignData);
|
|
233
|
-
await sdk.campaigns.toggleCampaignStatus(campaignId);
|
|
234
|
-
|
|
235
|
-
// Advanced operations
|
|
236
|
-
const triggers = await sdk.campaigns.getCampaignTriggers();
|
|
237
|
-
await sdk.campaigns.setCampaignTrigger(campaignId, triggerId);
|
|
238
|
-
```
|
|
239
|
-
|
|
240
|
-
### 🎁 Redemption Manager
|
|
241
|
-
|
|
242
|
-
```typescript
|
|
243
|
-
// Public redemption operations
|
|
244
|
-
const redemptions = await sdk.redemptions.getActiveRedemptions();
|
|
245
|
-
const types = await sdk.redemptions.getRedemptionTypes();
|
|
246
|
-
|
|
247
|
-
// User operations
|
|
248
|
-
await sdk.redemptions.redeemOffer(redemptionId);
|
|
249
|
-
const userRedemptions = await sdk.redemptions.getUserRedemptions();
|
|
250
|
-
|
|
251
|
-
// Admin operations
|
|
252
|
-
const allRedemptions = await sdk.redemptions.getAllRedemptions();
|
|
253
|
-
await sdk.redemptions.createRedemption(redemptionData);
|
|
254
|
-
await sdk.redemptions.toggleRedemptionStatus(redemptionId);
|
|
255
|
-
```
|
|
95
|
+
## Architecture
|
|
256
96
|
|
|
257
|
-
|
|
97
|
+
The SDK uses a clean Manager-Service pattern:
|
|
258
98
|
|
|
259
99
|
```typescript
|
|
260
|
-
//
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
100
|
+
// Manager Layer (Primary Interface)
|
|
101
|
+
sdk.auth // Authentication & sessions
|
|
102
|
+
sdk.users // User profiles & management
|
|
103
|
+
sdk.tokens // Token operations & balances
|
|
104
|
+
sdk.businesses // Business operations
|
|
105
|
+
sdk.campaigns // Marketing campaigns
|
|
106
|
+
sdk.redemptions // Reward redemptions
|
|
107
|
+
sdk.transactions // Transaction history
|
|
108
|
+
sdk.payments // Payment processing
|
|
109
|
+
sdk.analytics // Reporting & insights
|
|
110
|
+
sdk.tenants // Multi-tenant configuration
|
|
111
|
+
sdk.donations // Charitable giving
|
|
112
|
+
sdk.files // File operations
|
|
113
|
+
sdk.web3 // Blockchain operations
|
|
265
114
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
// Transaction operations
|
|
270
|
-
const transaction = await sdk.transactions.getTransactionById(id);
|
|
271
|
-
await sdk.transactions.createTransaction(transactionData);
|
|
272
|
-
const history = await sdk.transactions.getUserTransactionHistory('all');
|
|
115
|
+
// Service Layer (Advanced Access)
|
|
116
|
+
sdk.users.getUserService() // Direct service access
|
|
117
|
+
sdk.campaigns.getCampaignService()
|
|
273
118
|
```
|
|
274
119
|
|
|
275
|
-
|
|
120
|
+
## Core Features
|
|
276
121
|
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
const loginToken = await sdk.tenants.getLoginToken();
|
|
282
|
-
|
|
283
|
-
// Admin operations
|
|
284
|
-
await sdk.tenants.updateTenant(tenantData);
|
|
285
|
-
const admins = await sdk.tenants.getAdmins();
|
|
286
|
-
await sdk.tenants.createAdmin(adminData);
|
|
287
|
-
```
|
|
122
|
+
### Authentication
|
|
123
|
+
- External JWT integration (Firebase, Auth0, etc.)
|
|
124
|
+
- Native token validation and refresh
|
|
125
|
+
- User and admin authentication flows
|
|
288
126
|
|
|
289
|
-
###
|
|
127
|
+
### Business Management
|
|
128
|
+
- Business registration and profiles
|
|
129
|
+
- Business type management
|
|
130
|
+
- Public business discovery
|
|
290
131
|
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
endDate: '2024-12-31',
|
|
296
|
-
groupBy: 'month'
|
|
297
|
-
});
|
|
298
|
-
```
|
|
132
|
+
### Campaign System
|
|
133
|
+
- Marketing campaign management
|
|
134
|
+
- User campaign claims and participation
|
|
135
|
+
- Advanced campaign triggers and automation
|
|
299
136
|
|
|
300
|
-
###
|
|
137
|
+
### Token Economy
|
|
138
|
+
- Token balance management
|
|
139
|
+
- Token transfers and transactions
|
|
140
|
+
- Multiple token type support
|
|
301
141
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
142
|
+
### Reward Redemptions
|
|
143
|
+
- Redemption offer management
|
|
144
|
+
- User redemption tracking
|
|
145
|
+
- Multiple redemption types
|
|
306
146
|
|
|
307
|
-
|
|
147
|
+
### Payment Processing
|
|
148
|
+
- Payment intent creation
|
|
149
|
+
- Purchase token management
|
|
150
|
+
- Transaction history
|
|
308
151
|
|
|
309
|
-
|
|
152
|
+
## Configuration
|
|
310
153
|
|
|
311
154
|
```typescript
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
async post<T>(url: string, data?: unknown, options?: RequestOptions): Promise<T> {
|
|
320
|
-
// Your custom implementation
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
async put<T>(url: string, data?: unknown, options?: RequestOptions): Promise<T> {
|
|
324
|
-
// Your custom implementation
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
async delete<T>(url: string, options?: RequestOptions): Promise<T> {
|
|
328
|
-
// Your custom implementation
|
|
329
|
-
}
|
|
155
|
+
interface PersConfig {
|
|
156
|
+
environment?: 'development' | 'staging' | 'production';
|
|
157
|
+
apiVersion?: 'v2';
|
|
158
|
+
apiProjectKey: string;
|
|
159
|
+
timeout?: number;
|
|
160
|
+
retries?: number;
|
|
161
|
+
authProvider?: PersAuthProvider;
|
|
330
162
|
}
|
|
331
|
-
|
|
332
|
-
const sdk = new PersSDK(new CustomHttpClient(), config);
|
|
333
|
-
```
|
|
334
|
-
|
|
335
|
-
### Direct API Access
|
|
336
|
-
|
|
337
|
-
```typescript
|
|
338
|
-
// For operations not covered by managers
|
|
339
|
-
const apiClient = sdk.api();
|
|
340
|
-
|
|
341
|
-
// Custom endpoints
|
|
342
|
-
const customData = await apiClient.get<CustomType>('/custom-endpoint');
|
|
343
|
-
await apiClient.post('/custom-endpoint', customData);
|
|
344
|
-
|
|
345
|
-
// Direct authentication methods (advanced usage)
|
|
346
|
-
const userSession = await apiClient.loginUser(firebaseJWT);
|
|
347
|
-
const adminSession = await apiClient.loginAdmin(adminJWT);
|
|
348
|
-
|
|
349
|
-
// Advanced auth operations
|
|
350
|
-
const isExpired = await apiClient.isTokenExpired(120);
|
|
351
|
-
const allExpired = await apiClient.areAllTokensExpired();
|
|
352
163
|
```
|
|
353
164
|
|
|
354
|
-
|
|
165
|
+
## Error Handling
|
|
355
166
|
|
|
356
167
|
```typescript
|
|
357
168
|
import { PersApiError } from '@explorins/pers-sdk/core';
|
|
@@ -361,120 +172,32 @@ try {
|
|
|
361
172
|
} catch (error) {
|
|
362
173
|
if (error instanceof PersApiError) {
|
|
363
174
|
console.error('PERS API Error:', error.message, error.statusCode);
|
|
364
|
-
} else {
|
|
365
|
-
console.error('Unknown error:', error);
|
|
366
175
|
}
|
|
367
176
|
}
|
|
368
177
|
```
|
|
369
178
|
|
|
370
|
-
##
|
|
371
|
-
|
|
372
|
-
### Core Modules
|
|
373
|
-
- `/core` - Core API client and authentication
|
|
374
|
-
- `/platform-adapters` - Ready-to-use HTTP client adapters
|
|
179
|
+
## Bundle Size
|
|
375
180
|
|
|
376
|
-
|
|
377
|
-
-
|
|
378
|
-
-
|
|
379
|
-
-
|
|
380
|
-
- `/token` - Token balances and transfers
|
|
381
|
-
- `/transaction` - Payment and transaction history
|
|
382
|
-
- `/payment` - Payment processing
|
|
383
|
-
- `/user` - User profile management
|
|
384
|
-
- `/analytics` - Reporting and analytics
|
|
385
|
-
- `/tenant` - Multi-tenant management
|
|
386
|
-
- `/donation` - Donation management
|
|
387
|
-
- `/web3` - Blockchain and wallet integration
|
|
388
|
-
- `/web3-chain` - Web3 chain operations
|
|
181
|
+
- Core SDK: ~85 KB (minified)
|
|
182
|
+
- Tree-shaking friendly
|
|
183
|
+
- Zero external authentication dependencies
|
|
184
|
+
- Native browser API implementation
|
|
389
185
|
|
|
390
|
-
##
|
|
391
|
-
|
|
392
|
-
```typescript
|
|
393
|
-
interface PersConfig {
|
|
394
|
-
environment: 'development' | 'staging' | 'production';
|
|
395
|
-
apiVersion?: 'v1' | 'v1.8' | 'v1.9' | 'v2';
|
|
396
|
-
apiProjectKey: string;
|
|
397
|
-
timeout?: number; // Request timeout (default: 30s)
|
|
398
|
-
retries?: number; // Retry attempts (default: 3)
|
|
399
|
-
authProvider?: PersAuthProvider; // Custom auth provider
|
|
400
|
-
}
|
|
401
|
-
```
|
|
186
|
+
## Documentation
|
|
402
187
|
|
|
403
|
-
|
|
188
|
+
For comprehensive documentation, examples, and advanced usage:
|
|
404
189
|
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
**Before (Legacy):**
|
|
408
|
-
```typescript
|
|
409
|
-
const businessSDK = createBusinessSDK(apiClient);
|
|
410
|
-
const businesses = await businessSDK.getActiveBusinesses();
|
|
411
|
-
```
|
|
412
|
-
|
|
413
|
-
**After (Manager Pattern):**
|
|
414
|
-
```typescript
|
|
415
|
-
const sdk = new PersSDK(httpClient, config);
|
|
416
|
-
const businesses = await sdk.businesses.getActiveBusinesses();
|
|
417
|
-
```
|
|
418
|
-
|
|
419
|
-
### Authentication API Changes (v1.6+)
|
|
420
|
-
|
|
421
|
-
**Manager API (Recommended):**
|
|
422
|
-
```typescript
|
|
423
|
-
// Unified authentication method
|
|
424
|
-
const authResult = await sdk.auth.loginWithToken(jwtToken, 'user');
|
|
425
|
-
const adminResult = await sdk.auth.loginWithToken(jwtToken, 'admin');
|
|
426
|
-
```
|
|
427
|
-
|
|
428
|
-
**Core API (Advanced):**
|
|
429
|
-
```typescript
|
|
430
|
-
// Separate methods still available for direct API access
|
|
431
|
-
const userResult = await sdk.api().loginUser(jwtToken);
|
|
432
|
-
const adminResult = await sdk.api().loginAdmin(jwtToken);
|
|
433
|
-
```
|
|
434
|
-
|
|
435
|
-
**Benefits:**
|
|
436
|
-
- ✅ Cleaner API surface at manager level
|
|
437
|
-
- ✅ Better TypeScript inference
|
|
438
|
-
- ✅ Consistent error handling
|
|
439
|
-
- ✅ Easier testing and mocking
|
|
440
|
-
- ✅ Future-proof architecture
|
|
441
|
-
- ✅ Backward compatibility maintained in core API
|
|
442
|
-
|
|
443
|
-
## 📊 Bundle Size
|
|
444
|
-
|
|
445
|
-
- **Core SDK**: ~90 KB (minified)
|
|
446
|
-
- **Individual domains**: 2-20 KB each
|
|
447
|
-
- **Manager pattern**: Minimal overhead (~5 KB)
|
|
448
|
-
- **Tree-shaking friendly**: Import only what you need
|
|
449
|
-
|
|
450
|
-
## 🧪 Testing
|
|
451
|
-
|
|
452
|
-
```typescript
|
|
453
|
-
// Mock manager for testing
|
|
454
|
-
const mockUserManager = {
|
|
455
|
-
getCurrentUser: jest.fn().mockResolvedValue(mockUser),
|
|
456
|
-
updateCurrentUser: jest.fn().mockResolvedValue(updatedUser)
|
|
457
|
-
};
|
|
458
|
-
|
|
459
|
-
const sdk = {
|
|
460
|
-
users: mockUserManager
|
|
461
|
-
} as jest.Mocked<PersSDK>;
|
|
462
|
-
```
|
|
190
|
+
**[https://docs.pers.ninja/1.intro](https://docs.pers.ninja/1.intro)**
|
|
463
191
|
|
|
464
|
-
|
|
192
|
+
For detailed API reference:
|
|
465
193
|
|
|
466
|
-
|
|
467
|
-
- **`jwt-decode`** (^4.0.0) - JWT token parsing
|
|
468
|
-
- **`@explorins/pers-shared`** (*) - Shared types (peer dependency)
|
|
469
|
-
- **`ethers`** (^6.15.0) - Ethereum integration (peer dependency)
|
|
194
|
+
**[https://docs.pers.ninja/sdk](https://docs.pers.ninja/sdk)** (Interactive API Documentation)
|
|
470
195
|
|
|
471
196
|
## Related Packages
|
|
472
197
|
|
|
473
|
-
- [@explorins/pers-sdk-
|
|
474
|
-
- [@explorins/pers-
|
|
475
|
-
- [@explorins/pers-shared](https://www.npmjs.com/package/@explorins/pers-shared) - Shared types and DTOs
|
|
476
|
-
- [@explorins/web3-ts](https://www.npmjs.com/package/@explorins/web3-ts) - Web3 utilities
|
|
198
|
+
- [@explorins/pers-sdk-react-native](https://www.npmjs.com/package/@explorins/pers-sdk-react-native) - React Native integration
|
|
199
|
+
- [@explorins/pers-shared](https://www.npmjs.com/package/@explorins/pers-shared) - Shared types and utilities
|
|
477
200
|
|
|
478
201
|
## License
|
|
479
202
|
|
|
480
|
-
MIT License
|
|
203
|
+
MIT License
|