@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,22 @@
1
+ // Domain configurations for the PERS SDK
2
+ // This is the single source of truth for all domain configurations
3
+ export const domains = [
4
+ { name: 'core', externals: ['jwt-decode'] },
5
+ { name: 'business', externals: ['@explorins/pers-shared'] },
6
+ { name: 'transaction', externals: ['@explorins/pers-shared'] },
7
+ { name: 'analytics', externals: ['@explorins/pers-shared'] },
8
+ { name: 'auth-admin', externals: ['@explorins/pers-shared'] },
9
+ { name: 'campaign', externals: ['@explorins/pers-shared'] },
10
+ { name: 'donation', externals: ['@explorins/pers-shared'] },
11
+ { name: 'payment', externals: ['@explorins/pers-shared'] },
12
+ { name: 'redemption', externals: ['@explorins/pers-shared'] },
13
+ { name: 'tenant', externals: ['@explorins/pers-shared'] },
14
+ { name: 'token', externals: ['@explorins/pers-shared'] },
15
+ { name: 'user', externals: ['@explorins/pers-shared'] },
16
+ { name: 'user-status', externals: ['@explorins/pers-shared'] },
17
+ { name: 'web3-chain', externals: ['@explorins/pers-shared', 'web3', '@explorins/web3-ts', 'ethers'] },
18
+ { name: 'web3', externals: ['@explorins/pers-shared', 'web3', '@explorins/web3-ts', 'ethers'] }
19
+ ];
20
+
21
+ // Extract just the domain names for scripts that only need the names
22
+ export const domainNames = domains.map(domain => domain.name);
package/package.json CHANGED
@@ -1,52 +1,145 @@
1
1
  {
2
2
  "name": "@explorins/pers-sdk",
3
- "version": "1.0.0-alpha.1",
4
- "description": "Platform-agnostic SDK for PERS (Phygital Experience Rewards System)",
3
+ "version": "1.1.2",
4
+ "description": "Platform-agnostic SDK for PERS (Phygital Experience Rewards System) - Production Defaults",
5
5
  "type": "module",
6
+ "main": "./index.cjs",
7
+ "module": "./index.js",
8
+ "types": "./index.d.ts",
6
9
  "exports": {
7
10
  ".": {
8
- "types": "./dist/index.d.ts",
9
- "import": "./dist/index.esm.js",
10
- "require": "./dist/index.js"
11
+ "types": "./index.d.ts",
12
+ "import": "./index.js",
13
+ "require": "./index.cjs"
11
14
  },
12
- "./core": {
13
- "types": "./dist/core/core.d.ts",
14
- "import": "./dist/core.esm.js",
15
- "require": "./dist/core.js"
15
+ "./analytics": {
16
+ "types": "./analytics.d.ts",
17
+ "import": "./analytics.js",
18
+ "require": "./analytics.cjs"
19
+ },
20
+ "./auth-admin": {
21
+ "types": "./auth-admin.d.ts",
22
+ "import": "./auth-admin.js",
23
+ "require": "./auth-admin.cjs"
16
24
  },
17
25
  "./business": {
18
- "types": "./dist/business/index.d.ts",
19
- "import": "./dist/business.esm.js",
20
- "require": "./dist/business.js"
26
+ "types": "./business.d.ts",
27
+ "import": "./business.js",
28
+ "require": "./business.cjs"
29
+ },
30
+ "./campaign": {
31
+ "types": "./campaign.d.ts",
32
+ "import": "./campaign.js",
33
+ "require": "./campaign.cjs"
34
+ },
35
+ "./core": {
36
+ "types": "./core.d.ts",
37
+ "import": "./core.js",
38
+ "require": "./core.cjs"
39
+ },
40
+ "./donation": {
41
+ "types": "./donation.d.ts",
42
+ "import": "./donation.js",
43
+ "require": "./donation.cjs"
44
+ },
45
+ "./payment": {
46
+ "types": "./payment.d.ts",
47
+ "import": "./payment.js",
48
+ "require": "./payment.cjs"
49
+ },
50
+ "./redemption": {
51
+ "types": "./redemption.d.ts",
52
+ "import": "./redemption.js",
53
+ "require": "./redemption.cjs"
54
+ },
55
+ "./tenant": {
56
+ "types": "./tenant.d.ts",
57
+ "import": "./tenant.js",
58
+ "require": "./tenant.cjs"
59
+ },
60
+ "./token": {
61
+ "types": "./token.d.ts",
62
+ "import": "./token.js",
63
+ "require": "./token.cjs"
64
+ },
65
+ "./transaction": {
66
+ "types": "./transaction.d.ts",
67
+ "import": "./transaction.js",
68
+ "require": "./transaction.cjs"
69
+ },
70
+ "./user": {
71
+ "types": "./user.d.ts",
72
+ "import": "./user.js",
73
+ "require": "./user.cjs"
74
+ },
75
+ "./user-status": {
76
+ "types": "./user-status.d.ts",
77
+ "import": "./user-status.js",
78
+ "require": "./user-status.cjs"
79
+ },
80
+ "./web3-chain": {
81
+ "types": "./web3-chain.d.ts",
82
+ "import": "./web3-chain.js",
83
+ "require": "./web3-chain.cjs"
84
+ },
85
+ "./web3": {
86
+ "types": "./web3.d.ts",
87
+ "import": "./web3.js",
88
+ "require": "./web3.cjs"
21
89
  }
22
90
  },
23
- "scripts": {
24
- "build": "rollup -c",
91
+ "typesVersions": {
92
+ "*": {
93
+ "analytics": ["./analytics.d.ts"],
94
+ "auth-admin": ["./auth-admin.d.ts"],
95
+ "business": ["./business.d.ts"],
96
+ "campaign": ["./campaign.d.ts"],
97
+ "core": ["./core.d.ts"],
98
+ "donation": ["./donation.d.ts"],
99
+ "payment": ["./payment.d.ts"],
100
+ "redemption": ["./redemption.d.ts"],
101
+ "tenant": ["./tenant.d.ts"],
102
+ "token": ["./token.d.ts"],
103
+ "transaction": ["./transaction.d.ts"],
104
+ "user": ["./user.d.ts"],
105
+ "user-status": ["./user-status.d.ts"],
106
+ "web3-chain": ["./web3-chain.d.ts"],
107
+ "web3": ["./web3.d.ts"]
108
+ }
109
+ },
110
+ "scripts": {
111
+ "build": "rollup -c && node scripts/copy-declarations.js",
25
112
  "build:watch": "rollup -c --watch",
26
113
  "clean": "rimraf dist",
27
114
  "test": "jest",
28
115
  "test:watch": "jest --watch",
29
- "lint": "eslint src/**/*.ts"
30
- },
31
- "dependencies": {
32
- "@explorins/pers-shared": "*"
116
+ "lint": "eslint src/**/*.ts",
117
+ "prepublishOnly": "npm run clean && npm run build",
118
+ "publish": "npm publish"
33
119
  },
34
120
  "devDependencies": {
35
- "typescript": "^5.4.5",
121
+ "@rollup/plugin-typescript": "^11.1.6",
36
122
  "@types/jest": "^29.5.12",
37
123
  "jest": "^29.7.0",
38
- "@rollup/plugin-typescript": "^11.1.6",
124
+ "rimraf": "^5.0.5",
39
125
  "rollup": "^4.50.0",
40
- "rimraf": "^5.0.5"
126
+ "rollup-plugin-copy": "^3.5.0",
127
+ "typescript": "^5.4.5"
41
128
  },
42
129
  "peerDependencies": {
43
- "@explorins/pers-shared": "*"
130
+ "@explorins/pers-shared": "*",
131
+ "jwt-decode": "^3.0.0 || ^4.0.0"
44
132
  },
45
133
  "publishConfig": {
46
134
  "access": "public",
47
135
  "registry": "https://registry.npmjs.org/"
48
136
  },
49
- "keywords": ["pers", "business", "sdk", "platform-agnostic"],
137
+ "keywords": [
138
+ "pers",
139
+ "business",
140
+ "sdk",
141
+ "platform-agnostic"
142
+ ],
50
143
  "author": "Explorins",
51
144
  "license": "MIT"
52
145
  }
package/rollup.config.js CHANGED
@@ -1,67 +1,56 @@
1
1
  import typescript from '@rollup/plugin-typescript';
2
+ import copy from 'rollup-plugin-copy';
3
+ import { domains } from './config/domains.js';
2
4
 
3
- export default [
4
- // Core entry point
5
- {
6
- input: 'src/core/core.ts',
7
- output: [
8
- {
9
- file: 'dist/core.js',
10
- format: 'cjs',
11
- sourcemap: true
12
- },
13
- {
14
- file: 'dist/core.esm.js',
15
- format: 'esm',
16
- sourcemap: true
17
- }
18
- ],
19
- plugins: [
20
- typescript({
21
- tsconfig: './tsconfig.json',
22
- declaration: true,
23
- declarationDir: './dist'
24
- })
25
- ],
26
- external: ['rxjs', 'rxjs/operators']
27
- },
28
-
29
- // Business domain entry point
30
- {
31
- input: 'src/business/index.ts',
32
- output: [
33
- {
34
- file: 'dist/business.js',
35
- format: 'cjs',
36
- sourcemap: true
37
- },
38
- {
39
- file: 'dist/business.esm.js',
40
- format: 'esm',
41
- sourcemap: true
5
+ // Generate domain configurations
6
+ const domainConfigs = domains.map(domain => ({
7
+ input: `src/${domain.name}/index.ts`,
8
+ output: [
9
+ {
10
+ file: `dist/${domain.name}.cjs`,
11
+ format: 'cjs',
12
+ sourcemap: true,
13
+ exports: 'named'
14
+ },
15
+ {
16
+ file: `dist/${domain.name}.js`,
17
+ format: 'esm',
18
+ sourcemap: true
19
+ }
20
+ ],
21
+ plugins: [
22
+ typescript({
23
+ tsconfig: './tsconfig.json',
24
+ declaration: true,
25
+ declarationMap: true,
26
+ outDir: './dist/temp',
27
+ declarationDir: './dist/temp',
28
+ compilerOptions: {
29
+ rootDir: './src',
30
+ outDir: './dist/temp',
31
+ declarationDir: './dist/temp'
42
32
  }
43
- ],
44
- plugins: [
45
- typescript({
46
- tsconfig: './tsconfig.json',
47
- declaration: true,
48
- declarationDir: './dist'
49
- })
50
- ],
51
- external: ['@explorins/pers-shared', 'rxjs', 'rxjs/operators']
52
- },
33
+ })
34
+ ],
35
+ external: domain.externals
36
+ }));
37
+
38
+ export default [
39
+ // All domain configurations
40
+ ...domainConfigs,
53
41
 
54
42
  // Main entry point (everything)
55
43
  {
56
44
  input: 'src/index.ts',
57
45
  output: [
58
46
  {
59
- file: 'dist/index.js',
47
+ file: 'dist/index.cjs',
60
48
  format: 'cjs',
61
- sourcemap: true
49
+ sourcemap: true,
50
+ exports: 'named'
62
51
  },
63
52
  {
64
- file: 'dist/index.esm.js',
53
+ file: 'dist/index.js',
65
54
  format: 'esm',
66
55
  sourcemap: true
67
56
  }
@@ -70,9 +59,16 @@ export default [
70
59
  typescript({
71
60
  tsconfig: './tsconfig.json',
72
61
  declaration: true,
73
- declarationDir: './dist'
62
+ declarationMap: true,
63
+ declarationDir: './dist',
64
+ outDir: './dist'
65
+ }),
66
+ copy({
67
+ targets: [
68
+ { src: 'package.json', dest: 'dist' }
69
+ ]
74
70
  })
75
71
  ],
76
- external: ['@explorins/pers-shared', 'rxjs', 'rxjs/operators']
72
+ external: ['@explorins/pers-shared', 'web3', 'jwt-decode', '@explorins/web3-ts', 'ethers'] // All dependencies
77
73
  }
78
74
  ];
@@ -0,0 +1,147 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from 'fs';
4
+ import path from 'path';
5
+ import { fileURLToPath } from 'url';
6
+
7
+ // Import domain names from shared configuration
8
+ import { domainNames } from '../config/domains.js';
9
+
10
+ // Get __dirname equivalent for ES modules
11
+ const __filename = fileURLToPath(import.meta.url);
12
+ const __dirname = path.dirname(__filename);
13
+
14
+ const distPath = path.join(__dirname, '..', 'dist');
15
+ const tempPath = path.join(distPath, 'temp');
16
+
17
+ console.log('Copying domain declaration files...');
18
+
19
+ // Ensure dist directory exists
20
+ if (!fs.existsSync(distPath)) {
21
+ fs.mkdirSync(distPath, { recursive: true });
22
+ }
23
+
24
+ let copiedCount = 0;
25
+ let errors = [];
26
+
27
+ for (const domain of domainNames) {
28
+ const sourcePath = path.join(tempPath, domain, 'index.d.ts');
29
+ const targetPath = path.join(distPath, `${domain}.d.ts`);
30
+
31
+ try {
32
+ if (fs.existsSync(sourcePath)) {
33
+ let content = fs.readFileSync(sourcePath, 'utf8');
34
+
35
+ // Fix relative imports for the root-level declaration files
36
+ // Convert './api/something' to './domain/api/something'
37
+ // Convert './models' to './domain/models'
38
+ // Convert './services/something' to './domain/services/something'
39
+ content = content.replace(
40
+ /from ['"]\.\/(api|models|services)([^'"]*)['"]/g,
41
+ `from './${domain}/$1$2'`
42
+ );
43
+
44
+ // Also fix export statements
45
+ content = content.replace(
46
+ /export \{ ([^}]+) \} from ['"]\.\/(api|models|services)([^'"]*)['"]/g,
47
+ `export { $1 } from './${domain}/$2$3'`
48
+ );
49
+
50
+ // Fix export * statements
51
+ content = content.replace(
52
+ /export \* from ['"]\.\/(api|models|services)([^'"]*)['"]/g,
53
+ `export * from './${domain}/$1$2'`
54
+ );
55
+
56
+ // Fix problematic import paths that reference @explorins/pers-shared directly
57
+ // Replace specific import patterns with the re-exported types
58
+ content = content.replace(
59
+ /import\("@explorins\/pers-shared\/[^"]+"\)\.(\w+)/g,
60
+ '$1'
61
+ );
62
+
63
+ // Fix centralized interface imports - convert relative paths to correct dist structure
64
+ content = content.replace(
65
+ /from ['"]\.\.\/(shared\/interfaces\/pers-shared-lib\.interfaces)['"]/g,
66
+ `from './$1'`
67
+ );
68
+
69
+ // Fix centralized interface exports
70
+ content = content.replace(
71
+ /export \* from ['"]\.\.\/(shared\/interfaces\/pers-shared-lib\.interfaces)['"]/g,
72
+ `export * from './$1'`
73
+ );
74
+
75
+ // Fix core imports - convert ../core/ to ./core/
76
+ content = content.replace(
77
+ /from ['"]\.\.\/(core\/[^'"]*)['"]/g,
78
+ `from './$1'`
79
+ );
80
+
81
+ // Fix pers-sdk imports - convert ../pers-sdk to ./pers-sdk
82
+ content = content.replace(
83
+ /from ['"]\.\.\/(pers-sdk)['"]/g,
84
+ `from './$1'`
85
+ );
86
+
87
+ // Fix cross-domain imports - convert ../domain-name/ to ./domain-name/
88
+ content = content.replace(
89
+ /from ['"]\.\.\/(web3-chain|core|business|payment|user|transaction|campaign|analytics|auth-admin|donation|redemption|tenant|token|user-status|web3)\/([^'"]*)['"]/g,
90
+ `from './$1/$2'`
91
+ );
92
+
93
+ // Fix relative imports within domain files - they need to reference the domain subfolder
94
+ // But skip paths that already reference shared, core, or business subdirectories correctly
95
+ if (!content.includes('./shared/interfaces/') && !content.includes('./core/')) {
96
+ content = content.replace(
97
+ /from ['"]\.\/([^'"]+)['"]/g,
98
+ (match, path) => {
99
+ // Don't transform if it's already correctly prefixed
100
+ if (path.startsWith(`${domain}/`) || path.startsWith('shared/') || path.startsWith('core/')) {
101
+ return match;
102
+ }
103
+ return `from './${domain}/${path}'`;
104
+ }
105
+ );
106
+
107
+ content = content.replace(
108
+ /export \* from ['"]\.\/([^'"]+)['"]/g,
109
+ (match, path) => {
110
+ if (path.startsWith(`${domain}/`) || path.startsWith('shared/') || path.startsWith('core/')) {
111
+ return match;
112
+ }
113
+ return `export * from './${domain}/${path}'`;
114
+ }
115
+ );
116
+ }
117
+
118
+ fs.writeFileSync(targetPath, content);
119
+ console.log(`✓ Copied ${domain}.d.ts`);
120
+ copiedCount++;
121
+ } else {
122
+ errors.push(`Source file not found: ${sourcePath}`);
123
+ }
124
+ } catch (error) {
125
+ errors.push(`Error copying ${domain}.d.ts: ${error.message}`);
126
+ }
127
+ }
128
+
129
+ // Clean up temp directory
130
+ try {
131
+ if (fs.existsSync(tempPath)) {
132
+ fs.rmSync(tempPath, { recursive: true, force: true });
133
+ console.log('✓ Cleaned up temp directory');
134
+ }
135
+ } catch (error) {
136
+ console.warn(`Warning: Could not clean up temp directory: ${error.message}`);
137
+ }
138
+
139
+ console.log(`\nSummary: ${copiedCount}/${domainNames.length} declaration files copied successfully`);
140
+
141
+ if (errors.length > 0) {
142
+ console.error('\nErrors encountered:');
143
+ errors.forEach(error => console.error(` - ${error}`));
144
+ process.exit(1);
145
+ }
146
+
147
+ console.log('✓ All declaration files copied successfully!');
@@ -0,0 +1,24 @@
1
+ import { PersApiClient } from '../../core/pers-api-client';
2
+ import { TransactionAnalyticsRequestDTO, TransactionAnalyticsResponseDTO } from '../models';
3
+
4
+
5
+ /**
6
+ * Platform-Agnostic Analytics API Client
7
+ *
8
+ * Handles analytics operations using the PERS backend.
9
+ * Uses @explorins/pers-shared DTOs for consistency with backend.
10
+ */
11
+ export class AnalyticsApi {
12
+ constructor(private apiClient: PersApiClient) {}
13
+
14
+ // ==========================================
15
+ // ADMIN OPERATIONS
16
+ // ==========================================
17
+
18
+ /**
19
+ * ADMIN: Get transaction analytics with filtering and aggregation
20
+ */
21
+ async getTransactionAnalytics(request: TransactionAnalyticsRequestDTO): Promise<TransactionAnalyticsResponseDTO> {
22
+ return this.apiClient.post<TransactionAnalyticsResponseDTO>('/transactions/analytics', request);
23
+ }
24
+ }
@@ -0,0 +1,52 @@
1
+ /**
2
+ * @explorins/pers-sdk-analytics
3
+ *
4
+ * Platform-agnostic Analytics Domain SDK for PERS ecosystem
5
+ * Handles analytics operations and data aggregation
6
+ */
7
+
8
+ // API Layer
9
+ export { AnalyticsApi } from './api/analytics-api';
10
+
11
+ // Service Layer
12
+ export { AnalyticsService } from './services/analytics-service';
13
+
14
+ // Models & Types
15
+ export * from './models';
16
+ export * from '../shared/interfaces/pers-shared-lib.interfaces';
17
+
18
+ // Base Service (for inheritance pattern)
19
+ // Note: BaseAnalyticsService not yet implemented - using factory pattern for now
20
+
21
+ // Models & Types
22
+ export * from './models';
23
+
24
+ // Factory function for creating analytics SDK instance
25
+ import { PersApiClient } from '../core/pers-api-client';
26
+ import { AnalyticsApi } from './api/analytics-api';
27
+ import { TransactionAnalyticsRequestDTO } from './models';
28
+ import { AnalyticsService } from './services/analytics-service';
29
+
30
+ /**
31
+ * Create a complete Analytics SDK instance
32
+ *
33
+ * @param apiClient - Configured PERS API client
34
+ * @returns Analytics SDK with flattened structure for better DX
35
+ */
36
+ export function createAnalyticsSDK(apiClient: PersApiClient) {
37
+ const analyticsApi = new AnalyticsApi(apiClient);
38
+ const analyticsService = new AnalyticsService(analyticsApi);
39
+
40
+ return {
41
+ // Direct access to service methods (primary interface)
42
+
43
+ // Admin methods
44
+ getTransactionAnalytics: (request: TransactionAnalyticsRequestDTO) => analyticsService.getTransactionAnalytics(request),
45
+
46
+ // Advanced access for edge cases
47
+ api: analyticsApi,
48
+ service: analyticsService
49
+ };
50
+ }
51
+
52
+ export type AnalyticsSDK = ReturnType<typeof createAnalyticsSDK>;
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Analytics Domain Models
3
+ *
4
+ * Re-exports from @explorins/pers-shared for consistency with backend
5
+ * and to provide a single import source for analytics-related types.
6
+ */
7
+
8
+ // Core analytics entities
9
+
10
+
11
+ export interface TransactionAnalyticsGroupByExpression {
12
+ expression: string;
13
+ alias: string;
14
+ }
15
+
16
+ export interface TransactionAnalyticsRequestDTO {
17
+ filters?: TransactionAnalyticsFilters;
18
+ groupBy?: TransactionAnalyticsGroupBy[];
19
+ groupByExpressions?: TransactionAnalyticsGroupByExpression[];
20
+ metrics?: TransactionAnalyticsMetric[];
21
+ orderBy?: string;
22
+ orderDirection?: 'ASC' | 'DESC';
23
+ limit?: number;
24
+ startDate?: string;
25
+ endDate?: string;
26
+ }
27
+
28
+ export type TransactionAnalyticsFilters = {
29
+ status?: string;
30
+ tokenType?: string;
31
+ triggerProcessType?: string;
32
+ tenantId?: string;
33
+ chainId?: number;
34
+ type?: string;
35
+ [key: string]: any;
36
+ };
37
+
38
+ export type TransactionAnalyticsGroupBy =
39
+ | 'month' | 'week' | 'day' | 'year' | 'quarter'
40
+ | 'tokenType' | 'status' | 'chainId' | 'triggerProcessType' | 'type'
41
+ | 'senderAddress' | 'recipientAddress' | 'senderId' | 'recipientId' | 'senderOwnerType' | 'recipientOwnerType' | 'createdAt';
42
+
43
+ export type TransactionAnalyticsMetric =
44
+ | 'count' | 'sum' | 'avg' | 'min' | 'max';
45
+
46
+ export interface TransactionAnalyticsResultItem {
47
+ [key: string]: string | number | Date | undefined;
48
+ count?: string;
49
+ sum?: number;
50
+ avg?: number;
51
+ min?: number;
52
+ max?: number;
53
+ tokentype?: string;
54
+ tokenType?: string;
55
+ year?: string;
56
+ month?: string;
57
+ type?: string;
58
+ senderaddress?: string;
59
+ senderAddress?: string;
60
+ recipientaddress?: string;
61
+ recipientAddress?: string;
62
+ triggerprocesstype?: string;
63
+ triggerProcessType?: string;
64
+ userid?: string;
65
+ userId?: string;
66
+ }
67
+
68
+ export interface TransactionAnalyticsResponseDTO {
69
+ results: TransactionAnalyticsResultItem[];
70
+ totalGroups: number;
71
+ metadata: {
72
+ executionTime: string;
73
+ };
74
+ }
@@ -0,0 +1,28 @@
1
+ import { AnalyticsApi } from '../api/analytics-api';
2
+ import {
3
+ TransactionAnalyticsRequestDTO,
4
+ TransactionAnalyticsResponseDTO
5
+ } from '../models';
6
+
7
+ /**
8
+ * Platform-Agnostic Analytics Service
9
+ *
10
+ * Contains analytics business logic and operations that work across platforms.
11
+ * No framework dependencies - pure TypeScript business logic.
12
+ *
13
+ * Focuses only on actual backend capabilities.
14
+ */
15
+ export class AnalyticsService {
16
+ constructor(private analyticsApi: AnalyticsApi) {}
17
+
18
+ // ==========================================
19
+ // ADMIN OPERATIONS
20
+ // ==========================================
21
+
22
+ /**
23
+ * ADMIN: Get transaction analytics with filtering and aggregation
24
+ */
25
+ async getTransactionAnalytics(request: TransactionAnalyticsRequestDTO): Promise<TransactionAnalyticsResponseDTO> {
26
+ return this.analyticsApi.getTransactionAnalytics(request);
27
+ }
28
+ }