@explorins/pers-sdk 1.0.0-alpha.1 → 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.
Files changed (77) hide show
  1. package/config/domains.js +22 -0
  2. package/explorins-pers-sdk-1.0.0-alpha.1.tgz +0 -0
  3. package/package.json +116 -23
  4. package/rollup.config.js +50 -54
  5. package/scripts/copy-declarations.js +147 -0
  6. package/src/analytics/api/analytics-api.ts +24 -0
  7. package/src/analytics/index.ts +52 -0
  8. package/src/analytics/models/index.ts +74 -0
  9. package/src/analytics/services/analytics-service.ts +28 -0
  10. package/src/auth-admin/api/auth-admin-api.ts +42 -0
  11. package/src/auth-admin/index.ts +47 -0
  12. package/src/auth-admin/services/auth-admin-service.ts +36 -0
  13. package/src/business/api/business-api.ts +181 -19
  14. package/src/business/index.ts +4 -3
  15. package/src/business/models/index.ts +4 -4
  16. package/src/business/services/business-service.ts +1 -1
  17. package/src/campaign/api/campaign-api.ts +376 -0
  18. package/src/campaign/index.ts +67 -0
  19. package/src/campaign/services/campaign-service.ts +164 -0
  20. package/src/core/abstractions/http-client.ts +1 -0
  21. package/src/core/auth/auth-provider.interface.ts +2 -2
  22. package/src/core/auth/create-auth-provider.ts +6 -6
  23. package/src/core/index.ts +33 -0
  24. package/src/core/pers-api-client.ts +211 -19
  25. package/src/core/pers-config.ts +34 -7
  26. package/src/core/utils/jwt.function.ts +24 -0
  27. package/src/donation/api/donation-api.ts +24 -0
  28. package/src/donation/index.ts +47 -0
  29. package/src/donation/models/index.ts +11 -0
  30. package/src/donation/services/donation-service.ts +25 -0
  31. package/src/index.ts +40 -1
  32. package/src/payment/api/payment-api.ts +185 -0
  33. package/src/payment/index.ts +64 -0
  34. package/src/payment/models/index.ts +29 -0
  35. package/src/payment/services/payment-service.ts +70 -0
  36. package/src/redemption/api/redemption-api.ts +241 -0
  37. package/src/redemption/index.ts +60 -0
  38. package/src/redemption/models/index.ts +17 -0
  39. package/src/redemption/services/redemption-service.ts +103 -0
  40. package/src/shared/interfaces/pers-shared-lib.interfaces.ts +99 -0
  41. package/src/tenant/api/tenant-api.ts +92 -0
  42. package/src/tenant/index.ts +61 -0
  43. package/src/tenant/models/index.ts +20 -0
  44. package/src/tenant/services/tenant-service.ts +78 -0
  45. package/src/token/api/token-api.ts +129 -0
  46. package/src/token/base/base-token-service.ts +167 -0
  47. package/src/token/index.ts +38 -0
  48. package/src/token/models/index.ts +30 -0
  49. package/src/token/services/token-service.ts +125 -0
  50. package/src/token/token-sdk.ts +231 -0
  51. package/src/transaction/api/transaction-api.ts +296 -0
  52. package/src/transaction/index.ts +65 -0
  53. package/src/transaction/models/index.ts +60 -0
  54. package/src/transaction/services/transaction-service.ts +104 -0
  55. package/src/user/api/user-api.ts +98 -0
  56. package/src/user/index.ts +62 -0
  57. package/src/user/models/index.ts +10 -0
  58. package/src/user/services/user-service.ts +75 -0
  59. package/src/user-status/api/user-status-api.ts +78 -0
  60. package/src/user-status/index.ts +55 -0
  61. package/src/user-status/models/index.ts +11 -0
  62. package/src/user-status/services/user-status-service.ts +51 -0
  63. package/src/web3/api/web3-api.ts +68 -0
  64. package/src/web3/index.ts +38 -0
  65. package/src/web3/models/index.ts +150 -0
  66. package/src/web3/services/web3-service.ts +338 -0
  67. package/src/web3-chain/api/web3-chain-api.ts +42 -0
  68. package/src/web3-chain/index.ts +27 -0
  69. package/src/web3-chain/models/index.ts +45 -0
  70. package/src/web3-chain/services/getWeb3FCD.service.ts +47 -0
  71. package/src/web3-chain/services/provider.service.ts +123 -0
  72. package/src/web3-chain/services/public-http-provider.service.ts +26 -0
  73. package/src/web3-chain/services/web3-chain-service.ts +131 -0
  74. package/src/business/business/tsconfig.json +0 -18
  75. package/src/core/abstractions/core-interfaces.ts +0 -56
  76. package/src/core/core.ts +0 -30
  77. package/src/core.ts +0 -30
@@ -0,0 +1,42 @@
1
+ import { PersApiClient } from '../../core/pers-api-client';
2
+ import {
3
+ AdminDTO,
4
+ SessionAuthResponseDTO as TokenRefreshResponse,
5
+ SessionAuthResponseDTO as AdminLoginResponseDTO
6
+ } from '../../shared/interfaces/pers-shared-lib.interfaces';
7
+
8
+ /**
9
+ * Platform-Agnostic Auth Admin API Client
10
+ *
11
+ * Handles authentication and authorization admin operations using the PERS backend.
12
+ * Uses @explorins/pers-shared DTOs for consistency with backend.
13
+ *
14
+ * Note: Special header handling (bypass-auth-interceptor) may need to be implemented
15
+ * at the PersApiClient level or through a specialized auth client.
16
+ */
17
+ export class AuthAdminApi {
18
+ constructor(private apiClient: PersApiClient) {}
19
+
20
+ private readonly basePath = '/auth';
21
+
22
+ // ==========================================
23
+ // ADMIN AUTHENTICATION OPERATIONS
24
+ // ==========================================
25
+
26
+ /**
27
+ * ADMIN: Login tenant admin with JWT
28
+ * Note: JWT handling and auth bypass headers may need special implementation
29
+ */
30
+ async loginTenantAdmin(jwt: string): Promise<AdminLoginResponseDTO> {
31
+ // TODO: Implement proper JWT and bypass header handling when PersApiClient supports it
32
+ return this.apiClient.post<AdminLoginResponseDTO>(`${this.basePath}/token`, {});
33
+ }
34
+
35
+ /**
36
+ * ADMIN: Refresh access token
37
+ * Note: Bypass header handling may need special implementation
38
+ */
39
+ async refreshAccessToken(refreshToken: string): Promise<TokenRefreshResponse> {
40
+ return this.apiClient.post<TokenRefreshResponse>(`${this.basePath}/refresh`, { refreshToken });
41
+ }
42
+ }
@@ -0,0 +1,47 @@
1
+ /**
2
+ * @explorins/pers-sdk-auth-admin
3
+ *
4
+ * Platform-agnostic Auth Admin Domain SDK for PERS ecosystem
5
+ * Handles authentication and authorization admin operations
6
+ */
7
+
8
+ // API Layer
9
+ export { AuthAdminApi } from './api/auth-admin-api';
10
+
11
+ // Service Layer
12
+ export { AuthAdminService } from './services/auth-admin-service';
13
+
14
+ // Models & Types - re-export all centralized interfaces
15
+ export * from '../shared/interfaces/pers-shared-lib.interfaces';
16
+
17
+ // Models & Types - imported from centralized interfaces
18
+
19
+ // Factory function for creating auth admin SDK instance
20
+ import { PersApiClient } from '../core/pers-api-client';
21
+ import { AuthAdminApi } from './api/auth-admin-api';
22
+ import { AuthAdminService } from './services/auth-admin-service';
23
+
24
+ /**
25
+ * Create a complete Auth Admin SDK instance
26
+ *
27
+ * @param apiClient - Configured PERS API client
28
+ * @returns Auth Admin SDK with flattened structure for better DX
29
+ */
30
+ export function createAuthAdminSDK(apiClient: PersApiClient) {
31
+ const authAdminApi = new AuthAdminApi(apiClient);
32
+ const authAdminService = new AuthAdminService(authAdminApi);
33
+
34
+ return {
35
+ // Direct access to service methods (primary interface)
36
+
37
+ // Admin authentication methods
38
+ loginTenantAdmin: (jwt: string) => authAdminService.loginTenantAdmin(jwt),
39
+ refreshAccessToken: (refreshToken: string) => authAdminService.refreshAccessToken(refreshToken),
40
+
41
+ // Advanced access for edge cases
42
+ api: authAdminApi,
43
+ service: authAdminService
44
+ };
45
+ }
46
+
47
+ export type AuthAdminSDK = ReturnType<typeof createAuthAdminSDK>;
@@ -0,0 +1,36 @@
1
+ import { AuthAdminApi } from '../api/auth-admin-api';
2
+ import {
3
+ AdminDTO,
4
+ SessionAuthResponseDTO as TokenRefreshResponse,
5
+ SessionAuthResponseDTO as AdminLoginResponseDTO
6
+ } from '../../shared/interfaces/pers-shared-lib.interfaces';
7
+
8
+ /**
9
+ * Platform-Agnostic Auth Admin Service
10
+ *
11
+ * Contains auth admin business logic and operations that work across platforms.
12
+ * No framework dependencies - pure TypeScript business logic.
13
+ *
14
+ * Focuses only on actual backend capabilities.
15
+ */
16
+ export class AuthAdminService {
17
+ constructor(private authAdminApi: AuthAdminApi) {}
18
+
19
+ // ==========================================
20
+ // ADMIN AUTHENTICATION OPERATIONS
21
+ // ==========================================
22
+
23
+ /**
24
+ * ADMIN: Login tenant admin with JWT
25
+ */
26
+ async loginTenantAdmin(jwt: string): Promise<AdminLoginResponseDTO> {
27
+ return this.authAdminApi.loginTenantAdmin(jwt);
28
+ }
29
+
30
+ /**
31
+ * ADMIN: Refresh access token
32
+ */
33
+ async refreshAccessToken(refreshToken: string): Promise<TokenRefreshResponse> {
34
+ return this.authAdminApi.refreshAccessToken(refreshToken);
35
+ }
36
+ }
@@ -1,72 +1,234 @@
1
1
  import { PersApiClient } from '../../core/pers-api-client';
2
- import { BusinessDTO, BusinessTypeDTO, BusinessUpdateRequestDTO } from '@explorins/pers-shared';
2
+ import {
3
+ BusinessDTO,
4
+ BusinessTypeDTO,
5
+ BusinessUpdateRequestDTO,
6
+ BusinessCreateRequestDTO,
7
+ BusinessToggleActiveRequestDTO,
8
+ BusinessApiKeyDTO,
9
+ BusinessTokenBalancesDTO,
10
+ BusinessTypeCreateRequestDTO
11
+ } from '../../shared/interfaces/pers-shared-lib.interfaces';
3
12
 
4
13
  /**
5
14
  * Platform-Agnostic Business API Client
6
15
  *
7
- * Focuses on non-admin business operations using the PERS backend.
8
- * Uses @explorins/pers-shared DTOs for consistency with backend.
16
+ * Updated to match the new RESTful /businesses endpoints.
17
+ * Uses @explorins/pers-shared DTOs for full type safety and consistency with backend.
9
18
  */
10
19
  export class BusinessApi {
11
20
  constructor(private apiClient: PersApiClient) {}
12
21
 
22
+ private readonly basePath = '/businesses';
23
+
24
+ // ==========================================
25
+ // 🌐 BUSINESS TYPES MANAGEMENT
26
+ // ==========================================
27
+
28
+ /**
29
+ * Get all business types (project key required)
30
+ *
31
+ * Endpoint: GET /businesses/types
32
+ * Auth: @ApiSecurity('projectKey')
33
+ */
34
+ async getAllBusinessTypes(): Promise<BusinessTypeDTO[]> {
35
+ return this.apiClient.get<BusinessTypeDTO[]>(`${this.basePath}/types`);
36
+ }
37
+
38
+ /**
39
+ * ADMIN: Create business type
40
+ *
41
+ * Endpoint: POST /businesses/types
42
+ * Auth: @TenantAdmin()
43
+ */
44
+ async createBusinessType(dto: BusinessTypeCreateRequestDTO): Promise<BusinessTypeDTO> {
45
+ return this.apiClient.post<BusinessTypeDTO>(`${this.basePath}/types`, dto);
46
+ }
47
+
48
+ /**
49
+ * ADMIN: Update business type
50
+ *
51
+ * Endpoint: PUT /businesses/types
52
+ * Auth: @TenantAdmin()
53
+ */
54
+ async updateBusinessType(dto: BusinessTypeDTO): Promise<BusinessTypeDTO> {
55
+ return this.apiClient.put<BusinessTypeDTO>(`${this.basePath}/types`, dto);
56
+ }
57
+
13
58
  /**
14
- * Get all active businesses (public endpoint)
59
+ * ADMIN: Delete business type
60
+ *
61
+ * Endpoint: DELETE /businesses/types/{id}
62
+ * Auth: @TenantAdmin()
63
+ */
64
+ async deleteBusinessType(id: number): Promise<boolean> {
65
+ return this.apiClient.delete<boolean>(`${this.basePath}/types/${id}`);
66
+ }
67
+
68
+ // ==========================================
69
+ // 🏢 BUSINESS MANAGEMENT
70
+ // ==========================================
71
+
72
+ /**
73
+ * Get current business info (business authentication required)
74
+ *
75
+ * Endpoint: GET /businesses/me
76
+ * Auth: @Business()
77
+ */
78
+ async getCurrentBusiness(): Promise<BusinessTokenBalancesDTO> {
79
+ return this.apiClient.get<BusinessTokenBalancesDTO>(`${this.basePath}/me`);
80
+ }
81
+
82
+ /**
83
+ * Get all active businesses (project key required)
84
+ *
85
+ * Endpoint: GET /businesses
86
+ * Auth: @ApiSecurity('projectKey')
87
+ * Note: Regular users automatically get active businesses only
15
88
  */
16
89
  async getActiveBusinesses(): Promise<BusinessDTO[]> {
17
- return this.apiClient.get<BusinessDTO[]>('/business');
90
+ return this.apiClient.get<BusinessDTO[]>(`${this.basePath}`);
18
91
  }
19
92
 
20
93
  /**
21
- * Get all business types (public endpoint)
94
+ * Get all businesses with filtering (admin users can access inactive)
95
+ *
96
+ * Endpoint: GET /businesses?active={boolean}&sanitize={mode}
97
+ * Auth: @ApiSecurity('projectKey') (enhanced with role-based filtering)
22
98
  */
23
- async getAllBusinessTypes(): Promise<BusinessTypeDTO[]> {
24
- return this.apiClient.get<BusinessTypeDTO[]>('/business/type');
99
+ async getAllBusinesses(options?: {
100
+ active?: boolean;
101
+ sanitize?: 'soft' | 'hard';
102
+ }): Promise<BusinessDTO[]> {
103
+ const params = new URLSearchParams();
104
+
105
+ if (options?.active !== undefined) {
106
+ params.append('active', String(options.active));
107
+ }
108
+
109
+ if (options?.sanitize) {
110
+ params.append('sanitize', options.sanitize);
111
+ }
112
+
113
+ const queryString = params.toString();
114
+ const url = queryString ? `${this.basePath}?${queryString}` : this.basePath;
115
+
116
+ return this.apiClient.get<BusinessDTO[]>(url);
117
+ }
118
+
119
+ /**
120
+ * ADMIN: Get all businesses (admin endpoint with full access)
121
+ *
122
+ * Endpoint: GET /businesses/admin
123
+ * Auth: @TenantAdmin()
124
+ */
125
+ async getAllBusinessesAdmin(options?: {
126
+ active?: boolean;
127
+ sanitize?: 'soft' | 'hard';
128
+ }): Promise<BusinessDTO[]> {
129
+ const params = new URLSearchParams();
130
+
131
+ if (options?.active !== undefined) {
132
+ params.append('active', String(options.active));
133
+ }
134
+
135
+ if (options?.sanitize) {
136
+ params.append('sanitize', options.sanitize);
137
+ }
138
+
139
+ const queryString = params.toString();
140
+ const url = queryString ? `${this.basePath}?${queryString}` : this.basePath;
141
+
142
+ return this.apiClient.get<BusinessDTO[]>(url);
25
143
  }
26
144
 
27
145
  /**
28
146
  * Get business by ID
147
+ *
148
+ * Endpoint: GET /businesses/{id}
149
+ * Auth: @ApiSecurity('projectKey')
29
150
  */
30
151
  async getBusinessById(businessId: string): Promise<BusinessDTO> {
31
- return this.apiClient.get<BusinessDTO>(`/business/${businessId}`);
152
+ return this.apiClient.get<BusinessDTO>(`${this.basePath}/${businessId}`);
32
153
  }
33
154
 
34
155
  /**
35
156
  * Get business by account address
157
+ *
158
+ * Endpoint: GET /businesses/account/{accountAddress}
159
+ * Auth: @ApiSecurity('projectKey')
36
160
  */
37
161
  async getBusinessByAccount(accountAddress: string): Promise<BusinessDTO> {
38
- return this.apiClient.get<BusinessDTO>(`/business/account/${accountAddress}`);
162
+ return this.apiClient.get<BusinessDTO>(`${this.basePath}/account/${accountAddress}`);
39
163
  }
40
164
 
41
165
  // ==========================================
42
- // ADMIN OPERATIONS
166
+ // 🔧 ADMIN OPERATIONS
43
167
  // ==========================================
44
168
 
45
169
  /**
46
- * ADMIN: Get all businesses (active and inactive)
170
+ * ADMIN: Create business
171
+ *
172
+ * Endpoint: POST /businesses
173
+ * Auth: @TenantAdmin()
174
+ * Returns: BusinessApiKeyDTO | BusinessTokenBalancesDTO
175
+ */
176
+ async createBusiness(dto: BusinessCreateRequestDTO): Promise<BusinessApiKeyDTO | BusinessTokenBalancesDTO> {
177
+ return this.apiClient.post<BusinessApiKeyDTO | BusinessTokenBalancesDTO>(`${this.basePath}`, dto);
178
+ }
179
+
180
+ /**
181
+ * ADMIN: Create business by display name (convenience method)
182
+ *
183
+ * This is a convenience wrapper that creates the proper DTO structure
47
184
  */
48
- async getAllBusinesses(): Promise<BusinessDTO[]> {
49
- return this.apiClient.get<BusinessDTO[]>('/business/admin');
185
+ async createBusinessByDisplayName(displayName: string): Promise<BusinessApiKeyDTO | BusinessTokenBalancesDTO> {
186
+ const dto: BusinessCreateRequestDTO = {
187
+ displayName,
188
+ // Add other required fields based on BusinessCreateRequestDTO structure
189
+ // You may need to check the DTO definition for required fields
190
+ };
191
+ return this.createBusiness(dto);
50
192
  }
51
193
 
52
194
  /**
53
- * ADMIN: Create business by display name
195
+ * ADMIN: Create businesses from URL
196
+ *
197
+ * Endpoint: POST /businesses/bulk/url
198
+ * Auth: @TenantAdmin()
54
199
  */
55
- async createBusinessByDisplayName(displayName: string): Promise<BusinessDTO> {
56
- return this.apiClient.post<BusinessDTO>('/business/admin/', { displayName });
200
+ async createBusinessesFromUrl(url: string): Promise<BusinessDTO[]> {
201
+ return this.apiClient.post<BusinessDTO[]>(`${this.basePath}/bulk/url`, { url });
57
202
  }
58
203
 
59
204
  /**
60
205
  * ADMIN: Update business
206
+ *
207
+ * Endpoint: PUT /businesses/{id}
208
+ * Auth: @TenantAdmin()
61
209
  */
62
210
  async updateBusiness(id: string, businessData: BusinessUpdateRequestDTO): Promise<BusinessDTO> {
63
- return this.apiClient.put<BusinessDTO>(`/business/admin/${id}`, businessData);
211
+ return this.apiClient.put<BusinessDTO>(`${this.basePath}/${id}`, businessData);
64
212
  }
65
213
 
66
214
  /**
67
215
  * ADMIN: Toggle business active status
216
+ *
217
+ * Endpoint: PUT /businesses/{id}/activate
218
+ * Auth: @TenantAdmin()
68
219
  */
69
220
  async toggleBusinessActive(id: string, isActive: boolean): Promise<BusinessDTO> {
70
- return this.apiClient.put<BusinessDTO>(`/business/admin/activate/${id}`, { isActive });
221
+ const dto: BusinessToggleActiveRequestDTO = { isActive };
222
+ return this.apiClient.put<BusinessDTO>(`${this.basePath}/${id}/status`, dto);
223
+ }
224
+
225
+ /**
226
+ * ADMIN: Generate new business API key
227
+ *
228
+ * Endpoint: PUT /businesses/{id}/api-key
229
+ * Auth: @TenantAdmin()
230
+ */
231
+ async generateNewBusinessApiKey(id: string): Promise<string> {
232
+ return this.apiClient.put<string>(`${this.basePath}/${id}/api-key`, {});
71
233
  }
72
234
  }
@@ -11,9 +11,10 @@ export { BusinessApi } from './api/business-api';
11
11
  // Service Layer
12
12
  export { BusinessService } from './services/business-service';
13
13
 
14
- // Models & Types
15
- export * from './models';
14
+ // Models & Types - re-export all centralized interfaces
15
+ export * from '../shared/interfaces/pers-shared-lib.interfaces';
16
16
 
17
+ import { BusinessUpdateRequestDTO } from '../shared/interfaces/pers-shared-lib.interfaces';
17
18
  // Factory function for creating business SDK instance
18
19
  import { PersApiClient } from '../core/pers-api-client';
19
20
  import { BusinessApi } from './api/business-api';
@@ -40,7 +41,7 @@ export function createBusinessSDK(apiClient: PersApiClient) {
40
41
  // Admin methods
41
42
  getAllBusinesses: () => businessService.getAllBusinesses(),
42
43
  createBusinessByDisplayName: (displayName: string) => businessService.createBusinessByDisplayName(displayName),
43
- updateBusiness: (id: string, businessData: any) => businessService.updateBusiness(id, businessData),
44
+ updateBusiness: (id: string, businessData: BusinessUpdateRequestDTO) => businessService.updateBusiness(id, businessData),
44
45
  toggleBusinessActive: (id: string, isActive: boolean) => businessService.toggleBusinessActive(id, isActive),
45
46
 
46
47
  // Advanced access for edge cases
@@ -5,9 +5,9 @@
5
5
  * and to provide a single import source for business-related types.
6
6
  */
7
7
 
8
- // Core business entities
9
- export type {
8
+ // Core business entities from centralized pers-shared interfaces
9
+ export type {
10
10
  BusinessDTO,
11
11
  BusinessTypeDTO,
12
- BusinessUpdateRequestDTO
13
- } from '@explorins/pers-shared';
12
+ BusinessUpdateRequestDTO
13
+ } from '../../shared/interfaces/pers-shared-lib.interfaces';
@@ -3,7 +3,7 @@ import {
3
3
  BusinessDTO,
4
4
  BusinessTypeDTO,
5
5
  BusinessUpdateRequestDTO
6
- } from '../models';
6
+ } from '../../shared/interfaces/pers-shared-lib.interfaces';
7
7
 
8
8
  /**
9
9
  * Platform-Agnostic Business Service