@explorins/pers-sdk 1.1.0-beta.0 → 1.1.2
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/config/domains.js +22 -0
- package/package.json +100 -15
- package/rollup.config.js +44 -54
- package/scripts/copy-declarations.js +147 -0
- package/src/analytics/api/analytics-api.ts +24 -0
- package/src/analytics/index.ts +52 -0
- package/src/analytics/models/index.ts +74 -0
- package/src/analytics/services/analytics-service.ts +28 -0
- package/src/auth-admin/api/auth-admin-api.ts +42 -0
- package/src/auth-admin/index.ts +47 -0
- package/src/auth-admin/services/auth-admin-service.ts +36 -0
- package/src/business/api/business-api.ts +181 -19
- package/src/business/index.ts +4 -3
- package/src/business/models/index.ts +4 -4
- package/src/business/services/business-service.ts +1 -1
- package/src/campaign/api/campaign-api.ts +376 -0
- package/src/campaign/index.ts +67 -0
- package/src/campaign/services/campaign-service.ts +164 -0
- package/src/core/abstractions/http-client.ts +1 -0
- package/src/core/auth/auth-provider.interface.ts +2 -2
- package/src/core/auth/create-auth-provider.ts +6 -6
- package/src/core/index.ts +33 -0
- package/src/core/pers-api-client.ts +211 -19
- package/src/core/pers-config.ts +34 -7
- package/src/core/utils/jwt.function.ts +24 -0
- package/src/donation/api/donation-api.ts +24 -0
- package/src/donation/index.ts +47 -0
- package/src/donation/models/index.ts +11 -0
- package/src/donation/services/donation-service.ts +25 -0
- package/src/index.ts +40 -1
- package/src/payment/api/payment-api.ts +185 -0
- package/src/payment/index.ts +64 -0
- package/src/payment/models/index.ts +29 -0
- package/src/payment/services/payment-service.ts +70 -0
- package/src/redemption/api/redemption-api.ts +241 -0
- package/src/redemption/index.ts +60 -0
- package/src/redemption/models/index.ts +17 -0
- package/src/redemption/services/redemption-service.ts +103 -0
- package/src/shared/interfaces/pers-shared-lib.interfaces.ts +99 -0
- package/src/tenant/api/tenant-api.ts +92 -0
- package/src/tenant/index.ts +61 -0
- package/src/tenant/models/index.ts +20 -0
- package/src/tenant/services/tenant-service.ts +78 -0
- package/src/token/api/token-api.ts +129 -0
- package/src/token/base/base-token-service.ts +167 -0
- package/src/token/index.ts +38 -0
- package/src/token/models/index.ts +30 -0
- package/src/token/services/token-service.ts +125 -0
- package/src/token/token-sdk.ts +231 -0
- package/src/transaction/api/transaction-api.ts +296 -0
- package/src/transaction/index.ts +65 -0
- package/src/transaction/models/index.ts +60 -0
- package/src/transaction/services/transaction-service.ts +104 -0
- package/src/user/api/user-api.ts +98 -0
- package/src/user/index.ts +62 -0
- package/src/user/models/index.ts +10 -0
- package/src/user/services/user-service.ts +75 -0
- package/src/user-status/api/user-status-api.ts +78 -0
- package/src/user-status/index.ts +55 -0
- package/src/user-status/models/index.ts +11 -0
- package/src/user-status/services/user-status-service.ts +51 -0
- package/src/web3/api/web3-api.ts +68 -0
- package/src/web3/index.ts +38 -0
- package/src/web3/models/index.ts +150 -0
- package/src/web3/services/web3-service.ts +338 -0
- package/src/web3-chain/api/web3-chain-api.ts +42 -0
- package/src/web3-chain/index.ts +27 -0
- package/src/web3-chain/models/index.ts +45 -0
- package/src/web3-chain/services/getWeb3FCD.service.ts +47 -0
- package/src/web3-chain/services/provider.service.ts +123 -0
- package/src/web3-chain/services/public-http-provider.service.ts +26 -0
- package/src/web3-chain/services/web3-chain-service.ts +131 -0
- package/src/business/business/tsconfig.json +0 -18
- package/src/core/abstractions/core-interfaces.ts +0 -56
- package/src/core/core.ts +0 -30
- package/src/core.ts +0 -30
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { PersApiClient } from '../../core/pers-api-client';
|
|
2
|
+
import {
|
|
3
|
+
TransactionDTO,
|
|
4
|
+
TransactionRequestDTO,
|
|
5
|
+
ClientTransactionRequestDTO,
|
|
6
|
+
ClientTransactionRequestResponseDto,
|
|
7
|
+
AccountSelectorDTO
|
|
8
|
+
} from '../../shared/interfaces/pers-shared-lib.interfaces';
|
|
9
|
+
import { TransactionPaginationParams, TransactionPaginationResponse, UserBurnTokenRequestDTO } from '../models';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Platform-Agnostic Transaction API Client (UPDATED FOR NEW RESTful ENDPOINTS)
|
|
13
|
+
*
|
|
14
|
+
* Handles transaction operations using the PERS backend.
|
|
15
|
+
* Uses @explorins/pers-shared DTOs for consistency with backend.
|
|
16
|
+
*
|
|
17
|
+
* MIGRATION NOTES:
|
|
18
|
+
* - All endpoints changed from /transaction to /transactions
|
|
19
|
+
* - Role-based paths removed (no more /auth, /admin, /business in URLs)
|
|
20
|
+
* - New RESTful resource-based structure
|
|
21
|
+
* - Added new client-side transaction flow methods
|
|
22
|
+
* - Enhanced admin query capabilities
|
|
23
|
+
*/
|
|
24
|
+
export class TransactionApi {
|
|
25
|
+
constructor(private apiClient: PersApiClient) {}
|
|
26
|
+
|
|
27
|
+
private readonly basePath = '/transactions';
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Get transaction by ID (public endpoint)
|
|
31
|
+
*
|
|
32
|
+
* UPDATED: /transaction/{id} → /transactions/{id}
|
|
33
|
+
*/
|
|
34
|
+
async getTransactionById(transactionId: string): Promise<TransactionDTO> {
|
|
35
|
+
return this.apiClient.get<TransactionDTO>(`${this.basePath}/${transactionId}`);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// ==========================================
|
|
39
|
+
// AUTHENTICATED USER OPERATIONS
|
|
40
|
+
// ==========================================
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* AUTH: Create authenticated user transaction
|
|
44
|
+
*
|
|
45
|
+
* UPDATED: /transaction/auth/transaction → /transactions/user
|
|
46
|
+
*/
|
|
47
|
+
async createAuthTransaction(request: TransactionRequestDTO): Promise<TransactionDTO> {
|
|
48
|
+
return this.apiClient.post<TransactionDTO>(`${this.basePath}/user`, request);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* AUTH: Get user's sent transactions
|
|
53
|
+
*
|
|
54
|
+
* UPDATED: /transaction/auth/sender → /transactions/me/sent
|
|
55
|
+
*/
|
|
56
|
+
async getUserSentTransactions(): Promise<TransactionDTO[]> {
|
|
57
|
+
const params = new URLSearchParams({
|
|
58
|
+
timestamp: Date.now().toString()
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
return this.apiClient.get<TransactionDTO[]>(`${this.basePath}/me/sent?${params.toString()}`);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* AUTH: Get user's received transactions
|
|
66
|
+
*
|
|
67
|
+
* UPDATED: /transaction/auth/recipient → /transactions/me/received
|
|
68
|
+
*/
|
|
69
|
+
async getUserReceivedTransactions(): Promise<TransactionDTO[]> {
|
|
70
|
+
const params = new URLSearchParams({
|
|
71
|
+
timestamp: Date.now().toString()
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
return this.apiClient.get<TransactionDTO[]>(`${this.basePath}/me/received?${params.toString()}`);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* AUTH: Get user transaction history by type (backwards compatibility)
|
|
79
|
+
*
|
|
80
|
+
* UPDATED: Maps to appropriate /transactions/me/* endpoints
|
|
81
|
+
*/
|
|
82
|
+
async getUserTransactionHistory(type: string): Promise<TransactionDTO[]> {
|
|
83
|
+
const params = new URLSearchParams({
|
|
84
|
+
timestamp: Date.now().toString()
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
// Map legacy type parameter to new endpoints
|
|
88
|
+
switch (type.toLowerCase()) {
|
|
89
|
+
case 'sender':
|
|
90
|
+
case 'sent':
|
|
91
|
+
return this.apiClient.get<TransactionDTO[]>(`${this.basePath}/me/sent?${params.toString()}`);
|
|
92
|
+
case 'recipient':
|
|
93
|
+
case 'received':
|
|
94
|
+
return this.apiClient.get<TransactionDTO[]>(`${this.basePath}/me/received?${params.toString()}`);
|
|
95
|
+
default:
|
|
96
|
+
// Default to sent transactions for backwards compatibility
|
|
97
|
+
return this.apiClient.get<TransactionDTO[]>(`${this.basePath}/me/sent?${params.toString()}`);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* AUTH: Prepare client signed transaction
|
|
103
|
+
*
|
|
104
|
+
* UPDATED: /transaction/auth/prepare-signing → /transactions/prepare
|
|
105
|
+
*/
|
|
106
|
+
async prepareClientSignedTransaction(request: ClientTransactionRequestDTO): Promise<ClientTransactionRequestResponseDto> {
|
|
107
|
+
return this.apiClient.post<ClientTransactionRequestResponseDto>(`${this.basePath}/prepare`, request);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* AUTH: Prepare existing transaction for client-side signing
|
|
112
|
+
*
|
|
113
|
+
* NEW ENDPOINT: GET /transactions/{id}/prepare
|
|
114
|
+
*/
|
|
115
|
+
async prepareExistingTransaction(transactionId: string): Promise<ClientTransactionRequestResponseDto> {
|
|
116
|
+
return this.apiClient.get<ClientTransactionRequestResponseDto>(`${this.basePath}/${transactionId}/prepare`);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* AUTH: Submit client-side signed transaction
|
|
121
|
+
*
|
|
122
|
+
* NEW ENDPOINT: POST /transactions/{id}/submit
|
|
123
|
+
*/
|
|
124
|
+
async submitSignedTransaction(transactionId: string, signedData: any): Promise<TransactionDTO> {
|
|
125
|
+
return this.apiClient.post<TransactionDTO>(`${this.basePath}/${transactionId}/submit`, signedData);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* AUTH: Burn user tokens
|
|
130
|
+
*
|
|
131
|
+
* UPDATED: Uses new user transaction endpoint with burn-specific parameters
|
|
132
|
+
* Note: This might need backend confirmation on burn functionality implementation
|
|
133
|
+
*/
|
|
134
|
+
async burnUserTokens(request: UserBurnTokenRequestDTO): Promise<TransactionDTO> {
|
|
135
|
+
// Map burn request to TransactionRequestDTO format for new endpoint
|
|
136
|
+
const transactionRequest: TransactionRequestDTO = {
|
|
137
|
+
...request,
|
|
138
|
+
// Add any specific burn transaction parameters here
|
|
139
|
+
} as any;
|
|
140
|
+
|
|
141
|
+
return this.apiClient.post<TransactionDTO>(`${this.basePath}/user`, transactionRequest);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
// ==========================================
|
|
145
|
+
// BUSINESS OPERATIONS
|
|
146
|
+
// ==========================================
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* BUSINESS: Create business transaction
|
|
150
|
+
*
|
|
151
|
+
* UPDATED: /transaction/business/transaction → /transactions/business
|
|
152
|
+
*/
|
|
153
|
+
async createBusinessTransaction(request: TransactionRequestDTO): Promise<TransactionDTO> {
|
|
154
|
+
return this.apiClient.post<TransactionDTO>(`${this.basePath}/business`, request);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// ==========================================
|
|
158
|
+
// ADMIN OPERATIONS
|
|
159
|
+
// ==========================================
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* ADMIN: Create admin transaction
|
|
163
|
+
*
|
|
164
|
+
* UPDATED: /transaction/admin/transaction → /transactions/admin
|
|
165
|
+
*/
|
|
166
|
+
async createAdminTransaction(request: TransactionRequestDTO): Promise<TransactionDTO> {
|
|
167
|
+
return this.apiClient.post<TransactionDTO>(`${this.basePath}/system`, request);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* ADMIN: Get all tenant transactions
|
|
172
|
+
*
|
|
173
|
+
* UPDATED: /transaction/admin → /transactions
|
|
174
|
+
*/
|
|
175
|
+
async getTenantTransactions(): Promise<TransactionDTO[]> {
|
|
176
|
+
const result = await this.apiClient.get<TransactionPaginationResponse>(`${this.basePath}`);
|
|
177
|
+
// If the new endpoint returns paginated response, extract the data array
|
|
178
|
+
if ('data' in result) {
|
|
179
|
+
return result.data;
|
|
180
|
+
}
|
|
181
|
+
// Fallback for direct array response
|
|
182
|
+
return result as any as TransactionDTO[];
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* ADMIN: Get paginated transactions with filtering and sorting
|
|
187
|
+
*
|
|
188
|
+
* UPDATED: /transaction/admin → /transactions (same endpoint, better structure)
|
|
189
|
+
*/
|
|
190
|
+
async getPaginatedTransactions(params: TransactionPaginationParams): Promise<TransactionPaginationResponse> {
|
|
191
|
+
// Build query parameters
|
|
192
|
+
const queryParams: Record<string, string> = {
|
|
193
|
+
page: params.page.toString(),
|
|
194
|
+
limit: params.limit.toString()
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
// Add sorting parameters if provided
|
|
198
|
+
if (params.sortBy) {
|
|
199
|
+
queryParams['sortBy'] = params.sortBy;
|
|
200
|
+
}
|
|
201
|
+
if (params.sortOrder) {
|
|
202
|
+
queryParams['sortOrder'] = params.sortOrder;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// Add user-specific filtering if provided
|
|
206
|
+
if (params.participantId) {
|
|
207
|
+
queryParams['participantId'] = params.participantId;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
// Add status filtering if provided
|
|
211
|
+
if (params.status) {
|
|
212
|
+
queryParams['status'] = params.status;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// Add additional filters if provided
|
|
216
|
+
if (params.filters) {
|
|
217
|
+
if (params.filters.startDate) {
|
|
218
|
+
queryParams['startDate'] = params.filters.startDate;
|
|
219
|
+
}
|
|
220
|
+
if (params.filters.endDate) {
|
|
221
|
+
queryParams['endDate'] = params.filters.endDate;
|
|
222
|
+
}
|
|
223
|
+
if (params.filters.type && params.filters.type.length > 0) {
|
|
224
|
+
queryParams['type'] = params.filters.type.join(',');
|
|
225
|
+
}
|
|
226
|
+
if (params.filters.tokenType && params.filters.tokenType.length > 0) {
|
|
227
|
+
queryParams['tokenType'] = params.filters.tokenType.join(',');
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// Build query string
|
|
232
|
+
const queryString = Object.entries(queryParams)
|
|
233
|
+
.map(([key, value]) => `${key}=${encodeURIComponent(value)}`)
|
|
234
|
+
.join('&');
|
|
235
|
+
|
|
236
|
+
return this.apiClient.get<TransactionPaginationResponse>(`${this.basePath}?${queryString}`);
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* ADMIN: Export transactions to CSV
|
|
241
|
+
*
|
|
242
|
+
* UPDATED: /transaction/admin/export/csv → /transactions/export/csv
|
|
243
|
+
*/
|
|
244
|
+
async exportTransactionsCSV(): Promise<Blob> {
|
|
245
|
+
return this.apiClient.get<Blob>(`${this.basePath}/export/csv`, 'blob');
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
// ==========================================
|
|
249
|
+
// NEW ADMIN QUERY METHODS
|
|
250
|
+
// ==========================================
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* ADMIN: Query transactions by sender
|
|
254
|
+
*
|
|
255
|
+
* NEW ENDPOINT: POST /transactions/query-sender
|
|
256
|
+
*/
|
|
257
|
+
async queryTransactionsBySender(accountSelector: AccountSelectorDTO): Promise<TransactionDTO[]> {
|
|
258
|
+
return this.apiClient.post<TransactionDTO[]>(`${this.basePath}/query-sender`, accountSelector);
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* ADMIN: Query transactions by recipient
|
|
263
|
+
*
|
|
264
|
+
* NEW ENDPOINT: POST /transactions/query-recipient
|
|
265
|
+
*/
|
|
266
|
+
async queryTransactionsByRecipient(accountSelector: AccountSelectorDTO): Promise<TransactionDTO[]> {
|
|
267
|
+
return this.apiClient.post<TransactionDTO[]>(`${this.basePath}/query-recipient`, accountSelector);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
/**
|
|
271
|
+
* ADMIN: Get transaction analytics
|
|
272
|
+
*
|
|
273
|
+
* NEW ENDPOINT: POST /transactions/analytics
|
|
274
|
+
*/
|
|
275
|
+
async getTransactionAnalytics(analyticsRequest: any): Promise<any> {
|
|
276
|
+
return this.apiClient.post<any>(`${this.basePath}/analytics`, analyticsRequest);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// ==========================================
|
|
280
|
+
// CONVENIENCE METHODS (BACKWARDS COMPATIBILITY)
|
|
281
|
+
// ==========================================
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Convenience method: Get user sent transactions (alias)
|
|
285
|
+
*/
|
|
286
|
+
async getUserSenderTransactions(): Promise<TransactionDTO[]> {
|
|
287
|
+
return this.getUserSentTransactions();
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Convenience method: Get user received transactions (alias)
|
|
292
|
+
*/
|
|
293
|
+
async getUserRecipientTransactions(): Promise<TransactionDTO[]> {
|
|
294
|
+
return this.getUserReceivedTransactions();
|
|
295
|
+
}
|
|
296
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @explorins/pers-sdk-transaction
|
|
3
|
+
*
|
|
4
|
+
* Platform-agnostic Transaction Domain SDK for PERS ecosystem
|
|
5
|
+
* Handles transaction operations across different authorization levels
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// API Layer
|
|
9
|
+
export { TransactionApi } from './api/transaction-api';
|
|
10
|
+
|
|
11
|
+
// Service Layer
|
|
12
|
+
export { TransactionService } from './services/transaction-service';
|
|
13
|
+
|
|
14
|
+
// Models & Types
|
|
15
|
+
export * from './models';
|
|
16
|
+
export * from '../shared/interfaces/pers-shared-lib.interfaces';
|
|
17
|
+
|
|
18
|
+
// Models & Types
|
|
19
|
+
export * from './models';
|
|
20
|
+
|
|
21
|
+
import { ClientTransactionRequestDTO, TransactionRequestDTO } from '../shared/interfaces/pers-shared-lib.interfaces';
|
|
22
|
+
// Factory function for creating transaction SDK instance
|
|
23
|
+
import { PersApiClient } from '../core/pers-api-client';
|
|
24
|
+
import { TransactionApi } from './api/transaction-api';
|
|
25
|
+
import { TransactionService } from './services/transaction-service';
|
|
26
|
+
import { TransactionPaginationParams, UserBurnTokenRequestDTO } from './models';
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Create a complete Transaction SDK instance
|
|
30
|
+
*
|
|
31
|
+
* @param apiClient - Configured PERS API client
|
|
32
|
+
* @returns Transaction SDK with flattened structure for better DX
|
|
33
|
+
*/
|
|
34
|
+
export function createTransactionSDK(apiClient: PersApiClient) {
|
|
35
|
+
const transactionApi = new TransactionApi(apiClient);
|
|
36
|
+
const transactionService = new TransactionService(transactionApi);
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
// Direct access to service methods (primary interface)
|
|
40
|
+
|
|
41
|
+
// Public methods
|
|
42
|
+
getTransactionById: (transactionId: string) => transactionService.getTransactionById(transactionId),
|
|
43
|
+
|
|
44
|
+
// Auth methods
|
|
45
|
+
createAuthTransaction: (request: TransactionRequestDTO) => transactionService.createAuthTransaction(request),
|
|
46
|
+
getUserTransactionHistory: (type: string) => transactionService.getUserTransactionHistory(type),
|
|
47
|
+
prepareClientSignedTransaction: (request: ClientTransactionRequestDTO) => transactionService.prepareClientSignedTransaction(request),
|
|
48
|
+
burnUserTokens: (request: UserBurnTokenRequestDTO) => transactionService.burnUserTokens(request),
|
|
49
|
+
|
|
50
|
+
// Business methods
|
|
51
|
+
createBusinessTransaction: (request: TransactionRequestDTO) => transactionService.createBusinessTransaction(request),
|
|
52
|
+
|
|
53
|
+
// Admin methods
|
|
54
|
+
createAdminTransaction: (request: TransactionRequestDTO) => transactionService.createAdminTransaction(request),
|
|
55
|
+
getTenantTransactions: () => transactionService.getTenantTransactions(),
|
|
56
|
+
getPaginatedTransactions: (params: TransactionPaginationParams) => transactionService.getPaginatedTransactions(params),
|
|
57
|
+
exportTransactionsCSV: () => transactionService.exportTransactionsCSV(),
|
|
58
|
+
|
|
59
|
+
// Advanced access for edge cases
|
|
60
|
+
api: transactionApi,
|
|
61
|
+
service: transactionService
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export type TransactionSDK = ReturnType<typeof createTransactionSDK>;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transaction Domain Models
|
|
3
|
+
*
|
|
4
|
+
* Re-exports from @explorins/pers-shared for consistency with backend
|
|
5
|
+
* and to provide a single import source for transaction-related types.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// Core transaction entities from centralized pers-shared interfaces
|
|
9
|
+
export type {
|
|
10
|
+
TransactionDTO,
|
|
11
|
+
TransactionRequestDTO,
|
|
12
|
+
ClientTransactionRequestDTO,
|
|
13
|
+
ClientTransactionRequestResponseDto,
|
|
14
|
+
UserToBusinessTokenTransactionCreateRequestDTO
|
|
15
|
+
} from '../../shared/interfaces/pers-shared-lib.interfaces';
|
|
16
|
+
|
|
17
|
+
// Import for local interface usage
|
|
18
|
+
import { TransactionDTO } from '../../shared/interfaces/pers-shared-lib.interfaces';
|
|
19
|
+
|
|
20
|
+
// Local transaction interfaces
|
|
21
|
+
// TODO: Move these to @explorins/pers-shared when standardized across domains
|
|
22
|
+
export interface TransactionPaginationParams {
|
|
23
|
+
page: number;
|
|
24
|
+
limit: number;
|
|
25
|
+
participantId?: string; // User ID for filtering user transactions
|
|
26
|
+
status?: string;
|
|
27
|
+
sortBy?: string; // ✅ ADD: Column to sort by
|
|
28
|
+
sortOrder?: 'ASC' | 'DESC'; // ✅ ADD: Sort direction
|
|
29
|
+
filters?: {
|
|
30
|
+
startDate?: string;
|
|
31
|
+
endDate?: string;
|
|
32
|
+
type?: string[];
|
|
33
|
+
tokenType?: string[];
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export interface TransactionPaginationResponse {
|
|
38
|
+
data: TransactionDTO[];
|
|
39
|
+
pagination: {
|
|
40
|
+
page: string;
|
|
41
|
+
limit: string;
|
|
42
|
+
total: number;
|
|
43
|
+
pages: number;
|
|
44
|
+
hasNext: boolean;
|
|
45
|
+
hasPrev: boolean;
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export interface UserBurnTokenRequestDTO {
|
|
50
|
+
tokenAddress: string;
|
|
51
|
+
tokenMetadataIncrementalId: string;
|
|
52
|
+
chainId: number;
|
|
53
|
+
amount: number;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Transaction account types (domain-specific enum)
|
|
57
|
+
export enum TransactionAccountType {
|
|
58
|
+
// Add specific transaction account types as needed
|
|
59
|
+
// This should match the enum used in the infrastructure layer
|
|
60
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { TransactionDTO } from '../../shared/interfaces/pers-shared-lib.interfaces';
|
|
2
|
+
import { TransactionApi } from '../api/transaction-api';
|
|
3
|
+
import {
|
|
4
|
+
TransactionRequestDTO,
|
|
5
|
+
ClientTransactionRequestDTO,
|
|
6
|
+
ClientTransactionRequestResponseDto,
|
|
7
|
+
TransactionPaginationParams,
|
|
8
|
+
TransactionPaginationResponse,
|
|
9
|
+
UserBurnTokenRequestDTO
|
|
10
|
+
} from '../models';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Platform-Agnostic Transaction Service
|
|
14
|
+
*
|
|
15
|
+
* Contains transaction business logic and operations that work across platforms.
|
|
16
|
+
* No framework dependencies - pure TypeScript business logic.
|
|
17
|
+
*
|
|
18
|
+
* Focuses only on actual backend capabilities.
|
|
19
|
+
*/
|
|
20
|
+
export class TransactionService {
|
|
21
|
+
constructor(private transactionApi: TransactionApi) {}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Get transaction by ID
|
|
25
|
+
*/
|
|
26
|
+
async getTransactionById(transactionId: string): Promise<TransactionDTO> {
|
|
27
|
+
return this.transactionApi.getTransactionById(transactionId);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// ==========================================
|
|
31
|
+
// AUTHENTICATED OPERATIONS
|
|
32
|
+
// ==========================================
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* AUTH: Create authenticated transaction
|
|
36
|
+
*/
|
|
37
|
+
async createAuthTransaction(request: TransactionRequestDTO): Promise<TransactionDTO> {
|
|
38
|
+
return this.transactionApi.createAuthTransaction(request);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* AUTH: Get user transaction history by type
|
|
43
|
+
*/
|
|
44
|
+
async getUserTransactionHistory(type: string): Promise<TransactionDTO[]> {
|
|
45
|
+
return this.transactionApi.getUserTransactionHistory(type);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* AUTH: Prepare client signed transaction
|
|
50
|
+
*/
|
|
51
|
+
async prepareClientSignedTransaction(request: ClientTransactionRequestDTO): Promise<ClientTransactionRequestResponseDto> {
|
|
52
|
+
return this.transactionApi.prepareClientSignedTransaction(request);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* AUTH: Burn user tokens
|
|
57
|
+
*/
|
|
58
|
+
async burnUserTokens(request: UserBurnTokenRequestDTO): Promise<TransactionDTO> {
|
|
59
|
+
return this.transactionApi.burnUserTokens(request);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// ==========================================
|
|
63
|
+
// BUSINESS OPERATIONS
|
|
64
|
+
// ==========================================
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* BUSINESS: Create business transaction
|
|
68
|
+
*/
|
|
69
|
+
async createBusinessTransaction(request: TransactionRequestDTO): Promise<TransactionDTO> {
|
|
70
|
+
return this.transactionApi.createBusinessTransaction(request);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// ==========================================
|
|
74
|
+
// ADMIN OPERATIONS
|
|
75
|
+
// ==========================================
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* ADMIN: Create admin transaction
|
|
79
|
+
*/
|
|
80
|
+
async createAdminTransaction(request: TransactionRequestDTO): Promise<TransactionDTO> {
|
|
81
|
+
return this.transactionApi.createAdminTransaction(request);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* ADMIN: Get all tenant transactions
|
|
86
|
+
*/
|
|
87
|
+
async getTenantTransactions(): Promise<TransactionDTO[]> {
|
|
88
|
+
return this.transactionApi.getTenantTransactions();
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* ADMIN: Get paginated transactions with filtering and sorting
|
|
93
|
+
*/
|
|
94
|
+
async getPaginatedTransactions(params: TransactionPaginationParams): Promise<TransactionPaginationResponse> {
|
|
95
|
+
return this.transactionApi.getPaginatedTransactions(params);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* ADMIN: Export transactions to CSV
|
|
100
|
+
*/
|
|
101
|
+
async exportTransactionsCSV(): Promise<Blob> {
|
|
102
|
+
return this.transactionApi.exportTransactionsCSV();
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { UserDTO, UserCreateRequestDTO } from '../../shared/interfaces/pers-shared-lib.interfaces';
|
|
2
|
+
import { PersApiClient } from '../../core/pers-api-client';
|
|
3
|
+
import { UserPublicProfileDTO } from '../models';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Platform-Agnostic User API Client
|
|
7
|
+
*
|
|
8
|
+
* Handles user operations using the PERS backend RESTful API.
|
|
9
|
+
* Updated to use new /users endpoints with enhanced security and consistency.
|
|
10
|
+
* Maintains framework UserApiService method compatibility.
|
|
11
|
+
*/
|
|
12
|
+
export class UserApi {
|
|
13
|
+
constructor(private apiClient: PersApiClient) {}
|
|
14
|
+
|
|
15
|
+
private readonly basePath = '/users';
|
|
16
|
+
|
|
17
|
+
// ==========================================
|
|
18
|
+
// PUBLIC OPERATIONS
|
|
19
|
+
// ==========================================
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* PUBLIC: Get all users public profiles with optional filtering
|
|
23
|
+
* ✅ UPDATED: Uses new RESTful /users/public endpoint
|
|
24
|
+
*/
|
|
25
|
+
async getAllUsersPublicProfiles(filter: {key: string, value: string} | null = null): Promise<UserPublicProfileDTO[]> {
|
|
26
|
+
let url = `${this.basePath}/public`;
|
|
27
|
+
|
|
28
|
+
if (filter) {
|
|
29
|
+
// ✅ MAINTAINED: Same parameter pattern for compatibility
|
|
30
|
+
const params = new URLSearchParams();
|
|
31
|
+
params.set('filterKey', filter.key);
|
|
32
|
+
params.set('filterValue', filter.value);
|
|
33
|
+
url += `?${params.toString()}`;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return this.apiClient.get<UserPublicProfileDTO[]>(url);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// ==========================================
|
|
40
|
+
// AUTHENTICATED OPERATIONS
|
|
41
|
+
// ==========================================
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* AUTH: Get current authenticated user
|
|
45
|
+
* ✅ UPDATED: Uses new RESTful /users/me endpoint
|
|
46
|
+
*/
|
|
47
|
+
async getRemoteUser(): Promise<UserDTO> {
|
|
48
|
+
return this.apiClient.get<UserDTO>(`${this.basePath}/me`);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* AUTH: Update current authenticated user
|
|
53
|
+
* ✅ UPDATED: Uses new RESTful /users/me endpoint
|
|
54
|
+
*/
|
|
55
|
+
async updateRemoteUser(updateRequest: UserCreateRequestDTO): Promise<UserDTO> {
|
|
56
|
+
return this.apiClient.put<UserDTO>(`${this.basePath}/me`, updateRequest);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// ==========================================
|
|
60
|
+
// ADMIN OPERATIONS
|
|
61
|
+
// ==========================================
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* ADMIN: Get all remote users with query parameters
|
|
65
|
+
* ✅ UPDATED: Uses new RESTful /users endpoint with role-based access
|
|
66
|
+
* Note: Admin users get full data, non-admin users get public profiles only
|
|
67
|
+
*/
|
|
68
|
+
async getAllRemoteUsers(): Promise<UserDTO[]> {
|
|
69
|
+
// ✅ MAINTAINED: Same merge=soft parameter for compatibility
|
|
70
|
+
const url = `${this.basePath}?merge=soft`;
|
|
71
|
+
return this.apiClient.get<UserDTO[]>(url);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* ADMIN: Update user as admin
|
|
76
|
+
* ✅ UPDATED: Uses new RESTful /users/{id} endpoint
|
|
77
|
+
*/
|
|
78
|
+
async updateUserAsAdmin(id: string, userData: UserCreateRequestDTO): Promise<UserDTO> {
|
|
79
|
+
return this.apiClient.put<UserDTO>(`${this.basePath}/${id}`, userData);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* ADMIN: Toggle user active status
|
|
84
|
+
* ✅ UPDATED: Uses new consistent /users/{id}/status endpoint
|
|
85
|
+
* Enhanced: Follows RESTful status management pattern across all domains
|
|
86
|
+
*/
|
|
87
|
+
async toggleUserActiveStatusByUser(user: UserDTO): Promise<UserDTO> {
|
|
88
|
+
return this.apiClient.put<UserDTO>(`${this.basePath}/${user.id}/status`, {});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* ADMIN: Get user by unique identifier
|
|
93
|
+
* ✅ UPDATED: Uses new RESTful /users/{id} endpoint
|
|
94
|
+
*/
|
|
95
|
+
async getUserByUniqueIdentifier(id: string): Promise<UserDTO> {
|
|
96
|
+
return this.apiClient.get<UserDTO>(`${this.basePath}/${id}`);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @explorins/pers-sdk-user
|
|
3
|
+
*
|
|
4
|
+
* Platform-agnostic User Domain SDK for PERS ecosystem
|
|
5
|
+
* Handles user management, profiles, and authentication operations
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
// API Layer
|
|
9
|
+
export { UserApi } from './api/user-api';
|
|
10
|
+
|
|
11
|
+
// Service Layer
|
|
12
|
+
export { UserService } from './services/user-service';
|
|
13
|
+
|
|
14
|
+
// Models & Types
|
|
15
|
+
export * from './models';
|
|
16
|
+
export * from '../shared/interfaces/pers-shared-lib.interfaces';
|
|
17
|
+
|
|
18
|
+
// Factory function for creating user SDK instance
|
|
19
|
+
import { PersApiClient } from '../core/pers-api-client';
|
|
20
|
+
import { UserApi } from './api/user-api';
|
|
21
|
+
import { UserService } from './services/user-service';
|
|
22
|
+
import { UserDTO, UserCreateRequestDTO } from '../shared/interfaces/pers-shared-lib.interfaces';
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Create a complete User SDK instance
|
|
26
|
+
*
|
|
27
|
+
* @param apiClient - Configured PERS API client
|
|
28
|
+
* @returns User SDK with flattened structure for better DX
|
|
29
|
+
*/
|
|
30
|
+
export function createUserSDK(apiClient: PersApiClient) {
|
|
31
|
+
const userApi = new UserApi(apiClient);
|
|
32
|
+
const userService = new UserService(userApi);
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
// Direct access to service methods (primary interface)
|
|
36
|
+
|
|
37
|
+
// Public methods - matches framework exactly
|
|
38
|
+
getAllUsersPublicProfiles: (filter: {key: string, value: string} | null = null) =>
|
|
39
|
+
userService.getAllUsersPublicProfiles(filter),
|
|
40
|
+
|
|
41
|
+
// Auth methods - matches framework exactly
|
|
42
|
+
getRemoteUser: () => userService.getRemoteUser(),
|
|
43
|
+
updateRemoteUser: (updateRequest: UserCreateRequestDTO) =>
|
|
44
|
+
userService.updateRemoteUser(updateRequest),
|
|
45
|
+
|
|
46
|
+
// Admin methods - matches framework exactly
|
|
47
|
+
getAllRemoteUsers: () => userService.getAllRemoteUsers(),
|
|
48
|
+
updateUserAsAdmin: (id: string, userData: UserCreateRequestDTO) =>
|
|
49
|
+
userService.updateUserAsAdmin(id, userData),
|
|
50
|
+
toggleUserActiveStatusByUser: (user: UserDTO) =>
|
|
51
|
+
userService.toggleUserActiveStatusByUser(user),
|
|
52
|
+
|
|
53
|
+
getUserByUniqueIdentifier: (id: string) =>
|
|
54
|
+
userService.getUserByUniqueIdentifier(id),
|
|
55
|
+
|
|
56
|
+
// Advanced access for edge cases
|
|
57
|
+
api: userApi,
|
|
58
|
+
service: userService
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export type UserSDK = ReturnType<typeof createUserSDK>;
|