@explorins/pers-sdk-react-native 1.3.2 → 1.5.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/README.md +276 -123
- package/dist/hooks/index.d.ts +10 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +8 -0
- package/dist/hooks/useAnalytics.d.ts +96 -0
- package/dist/hooks/useAnalytics.d.ts.map +1 -0
- package/dist/hooks/useAnalytics.js +73 -0
- package/dist/hooks/useAuth.d.ts +52 -7
- package/dist/hooks/useAuth.d.ts.map +1 -1
- package/dist/hooks/useAuth.js +250 -3
- package/dist/hooks/useBusiness.d.ts +45 -3
- package/dist/hooks/useBusiness.d.ts.map +1 -1
- package/dist/hooks/useBusiness.js +182 -28
- package/dist/hooks/useCampaigns.d.ts +11 -4
- package/dist/hooks/useCampaigns.d.ts.map +1 -1
- package/dist/hooks/useCampaigns.js +101 -39
- package/dist/hooks/useDonations.d.ts +33 -0
- package/dist/hooks/useDonations.d.ts.map +1 -0
- package/dist/hooks/useDonations.js +62 -0
- package/dist/hooks/useFiles.d.ts +50 -0
- package/dist/hooks/useFiles.d.ts.map +1 -0
- package/dist/hooks/useFiles.js +140 -0
- package/dist/hooks/usePurchases.d.ts +9 -0
- package/dist/hooks/usePurchases.d.ts.map +1 -0
- package/dist/hooks/usePurchases.js +56 -0
- package/dist/hooks/useRedemptions.d.ts +10 -5
- package/dist/hooks/useRedemptions.d.ts.map +1 -1
- package/dist/hooks/useRedemptions.js +118 -66
- package/dist/hooks/useTenants.d.ts +10 -0
- package/dist/hooks/useTenants.d.ts.map +1 -0
- package/dist/hooks/useTenants.js +68 -0
- package/dist/hooks/useTokens.d.ts +36 -2
- package/dist/hooks/useTokens.d.ts.map +1 -1
- package/dist/hooks/useTokens.js +180 -19
- package/dist/hooks/useTransactionSigner.d.ts +73 -0
- package/dist/hooks/useTransactionSigner.d.ts.map +1 -0
- package/dist/hooks/useTransactionSigner.js +216 -0
- package/dist/hooks/useTransactions.d.ts +45 -3
- package/dist/hooks/useTransactions.d.ts.map +1 -1
- package/dist/hooks/useTransactions.js +149 -39
- package/dist/hooks/useUserStatus.d.ts +9 -0
- package/dist/hooks/useUserStatus.d.ts.map +1 -0
- package/dist/hooks/useUserStatus.js +57 -0
- package/dist/hooks/useUsers.d.ts +17 -0
- package/dist/hooks/useUsers.d.ts.map +1 -0
- package/dist/hooks/useUsers.js +120 -0
- package/dist/hooks/useWeb3.d.ts +69 -6
- package/dist/hooks/useWeb3.d.ts.map +1 -1
- package/dist/hooks/useWeb3.js +177 -17
- package/dist/index.d.ts +6 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +31540 -794
- package/dist/index.js.map +1 -1
- package/dist/polyfills/index.d.ts +1 -1
- package/dist/polyfills/index.d.ts.map +1 -1
- package/dist/polyfills/index.js +155 -9
- package/dist/polyfills/web3-polyfills.d.ts +7 -0
- package/dist/polyfills/web3-polyfills.d.ts.map +1 -0
- package/dist/polyfills/web3-polyfills.js +85 -0
- package/dist/providers/PersSDKProvider.d.ts +28 -18
- package/dist/providers/PersSDKProvider.d.ts.map +1 -1
- package/dist/providers/PersSDKProvider.js +63 -129
- package/dist/providers/react-native-auth-provider.d.ts +19 -64
- package/dist/providers/react-native-auth-provider.d.ts.map +1 -1
- package/dist/providers/react-native-auth-provider.js +57 -175
- package/package.json +177 -157
- package/src/hooks/index.ts +13 -1
- package/src/hooks/useAnalytics.ts +150 -0
- package/src/hooks/useAuth.ts +286 -27
- package/src/hooks/useBusiness.ts +193 -30
- package/src/hooks/useCampaigns.ts +121 -43
- package/src/hooks/useDonations.ts +68 -0
- package/src/hooks/useFiles.ts +160 -0
- package/src/hooks/usePurchases.ts +69 -0
- package/src/hooks/useRedemptions.ts +135 -68
- package/src/hooks/useTenants.ts +77 -0
- package/src/hooks/useTokens.ts +189 -21
- package/src/hooks/useTransactionSigner.ts +287 -0
- package/src/hooks/useTransactions.ts +163 -41
- package/src/hooks/useUserStatus.ts +65 -0
- package/src/hooks/useUsers.ts +133 -0
- package/src/hooks/useWeb3.ts +201 -21
- package/src/index.ts +22 -17
- package/src/polyfills/index.ts +163 -10
- package/src/polyfills/web3-polyfills.ts +98 -0
- package/src/providers/PersSDKProvider.tsx +114 -178
- package/src/providers/react-native-auth-provider.ts +65 -208
- package/dist/index.esm.js +0 -1057
- package/dist/index.esm.js.map +0 -1
- package/dist/polyfills/index.simple.d.ts +0 -2
- package/dist/polyfills/index.simple.d.ts.map +0 -1
- package/dist/polyfills/index.simple.js +0 -17
- package/src/polyfills/index.simple.ts +0 -22
- package/src/types/external-modules.d.ts +0 -13
package/package.json
CHANGED
|
@@ -1,157 +1,177 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@explorins/pers-sdk-react-native",
|
|
3
|
-
"version": "1.
|
|
4
|
-
"description": "React Native SDK for PERS Platform - Tourism Loyalty System",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"types": "dist/index.d.ts",
|
|
7
|
-
"scripts": {
|
|
8
|
-
"build": "tsc && rollup -c --bundleConfigAsCjs",
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"web3"
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
"
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
"
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
"
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
"
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
"
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
"
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
"
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
"
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
"
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
"
|
|
121
|
-
"
|
|
122
|
-
"
|
|
123
|
-
"
|
|
124
|
-
"
|
|
125
|
-
"
|
|
126
|
-
"
|
|
127
|
-
"
|
|
128
|
-
"
|
|
129
|
-
"
|
|
130
|
-
"
|
|
131
|
-
"
|
|
132
|
-
"
|
|
133
|
-
"
|
|
134
|
-
"
|
|
135
|
-
"
|
|
136
|
-
"
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
"
|
|
140
|
-
"
|
|
141
|
-
"
|
|
142
|
-
"
|
|
143
|
-
"
|
|
144
|
-
"
|
|
145
|
-
"
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
"
|
|
149
|
-
"
|
|
150
|
-
"
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
"
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@explorins/pers-sdk-react-native",
|
|
3
|
+
"version": "1.5.2",
|
|
4
|
+
"description": "React Native SDK for PERS Platform - Tourism Loyalty System with Manager Pattern Architecture",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"scripts": {
|
|
8
|
+
"build": "tsc && rollup -c --bundleConfigAsCjs",
|
|
9
|
+
"build:watch": "rollup -c --bundleConfigAsCjs --watch",
|
|
10
|
+
"dev": "tsc --watch",
|
|
11
|
+
"clean": "rimraf dist",
|
|
12
|
+
"docs": "typedoc",
|
|
13
|
+
"docs:dev": "typedoc --watch",
|
|
14
|
+
"docs:json": "typedoc --json docs/api.json",
|
|
15
|
+
"docs:serve": "npx http-server docs -p 8080",
|
|
16
|
+
"prepublishOnly": "npm run clean && npm run build",
|
|
17
|
+
"publish-version": "npm run clean && npm run build && npm version patch && npm publish",
|
|
18
|
+
"publish-with-docs": "npm run clean && npm run build && npm run docs && npm version patch && npm publish",
|
|
19
|
+
"yalc:publish": "npm version patch --no-git-tag-version && npm run build && yalc publish",
|
|
20
|
+
"yalc:push": "npm version patch --no-git-tag-version && npm run build && yalc push"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"pers",
|
|
24
|
+
"sdk",
|
|
25
|
+
"react-native",
|
|
26
|
+
"tourism",
|
|
27
|
+
"loyalty",
|
|
28
|
+
"blockchain",
|
|
29
|
+
"web3"
|
|
30
|
+
],
|
|
31
|
+
"author": "eXplorins",
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"@dfns/sdk": "^0.8.1",
|
|
35
|
+
"@dfns/sdk-react-native": "^0.8.1",
|
|
36
|
+
"@explorins/pers-sdk": "^1.6.3",
|
|
37
|
+
"@explorins/pers-shared": "^2.1.40",
|
|
38
|
+
"@explorins/pers-signer": "^1.0.6",
|
|
39
|
+
"@explorins/web3-ts": "^0.3.75",
|
|
40
|
+
"@react-native-async-storage/async-storage": "^2.2.0",
|
|
41
|
+
"buffer": "^6.0.3",
|
|
42
|
+
"ethers": "^6.15.0",
|
|
43
|
+
"react-native-get-random-values": "^2.0.0",
|
|
44
|
+
"react-native-keychain": "^10.0.0",
|
|
45
|
+
"typedoc": "^0.25.13",
|
|
46
|
+
"typedoc-plugin-markdown": "^3.17.1"
|
|
47
|
+
},
|
|
48
|
+
"browser": {
|
|
49
|
+
"crypto": false,
|
|
50
|
+
"url": false,
|
|
51
|
+
"http": false,
|
|
52
|
+
"https": false,
|
|
53
|
+
"zlib": false,
|
|
54
|
+
"stream": false,
|
|
55
|
+
"assert": false,
|
|
56
|
+
"path": false,
|
|
57
|
+
"fs": false,
|
|
58
|
+
"os": false,
|
|
59
|
+
"readable-stream": false,
|
|
60
|
+
"util": false,
|
|
61
|
+
"events": false,
|
|
62
|
+
"net": false,
|
|
63
|
+
"tls": false,
|
|
64
|
+
"child_process": false,
|
|
65
|
+
"pngjs": false,
|
|
66
|
+
"pngjs/lib/bitmapper": false,
|
|
67
|
+
"pngjs/lib/parser-async": false,
|
|
68
|
+
"pngjs/lib/parser-sync": false,
|
|
69
|
+
"./bitmapper": false,
|
|
70
|
+
"hash-base": false,
|
|
71
|
+
"@ethereumjs/common": false,
|
|
72
|
+
"@ethereumjs/tx": false,
|
|
73
|
+
"@ethereumjs/util": false,
|
|
74
|
+
"stream-browserify": false,
|
|
75
|
+
"crypto-browserify": false,
|
|
76
|
+
"inherits": false,
|
|
77
|
+
"safe-buffer": false,
|
|
78
|
+
"string_decoder": false,
|
|
79
|
+
"process-nextick-args": false,
|
|
80
|
+
"isarray": false,
|
|
81
|
+
"core-util-is": false,
|
|
82
|
+
"util-deprecate": false,
|
|
83
|
+
"ethereum-cryptography": false,
|
|
84
|
+
"keccak": false,
|
|
85
|
+
"secp256k1": false,
|
|
86
|
+
"scrypt-js": false,
|
|
87
|
+
"bech32": false,
|
|
88
|
+
"ws": false,
|
|
89
|
+
"xhr2-cookies": false,
|
|
90
|
+
"aes-js": false,
|
|
91
|
+
"@ethersproject/sha2": false,
|
|
92
|
+
"@ethersproject/pbkdf2": false,
|
|
93
|
+
"@ethersproject/scrypt": false
|
|
94
|
+
},
|
|
95
|
+
"peerDependencies": {
|
|
96
|
+
"react": ">=16.8.0",
|
|
97
|
+
"react-native": ">=0.60.0"
|
|
98
|
+
},
|
|
99
|
+
"peerDependenciesMeta": {
|
|
100
|
+
"react-native-keychain": {
|
|
101
|
+
"optional": true
|
|
102
|
+
},
|
|
103
|
+
"@react-native-async-storage/async-storage": {
|
|
104
|
+
"optional": false
|
|
105
|
+
},
|
|
106
|
+
"react-native-get-random-values": {
|
|
107
|
+
"optional": true
|
|
108
|
+
},
|
|
109
|
+
"react-native-url-polyfill": {
|
|
110
|
+
"optional": true
|
|
111
|
+
},
|
|
112
|
+
"react-native-polyfill-globals": {
|
|
113
|
+
"optional": true
|
|
114
|
+
},
|
|
115
|
+
"web-streams-polyfill": {
|
|
116
|
+
"optional": true
|
|
117
|
+
}
|
|
118
|
+
},
|
|
119
|
+
"overrides": {
|
|
120
|
+
"readable-stream": false,
|
|
121
|
+
"@ethereumjs/common": false,
|
|
122
|
+
"@ethereumjs/util": false,
|
|
123
|
+
"@ethereumjs/rlp": false,
|
|
124
|
+
"@ethereumjs/tx": false,
|
|
125
|
+
"stream": false,
|
|
126
|
+
"util": false,
|
|
127
|
+
"events": false,
|
|
128
|
+
"crypto": false,
|
|
129
|
+
"fs": false,
|
|
130
|
+
"path": false,
|
|
131
|
+
"os": false,
|
|
132
|
+
"net": false,
|
|
133
|
+
"tls": false,
|
|
134
|
+
"child_process": false,
|
|
135
|
+
"hash-base": false,
|
|
136
|
+
"inherits": false,
|
|
137
|
+
"safe-buffer": false,
|
|
138
|
+
"string_decoder": false,
|
|
139
|
+
"process-nextick-args": false,
|
|
140
|
+
"isarray": false,
|
|
141
|
+
"core-util-is": false,
|
|
142
|
+
"util-deprecate": false,
|
|
143
|
+
"ethereum-cryptography": false,
|
|
144
|
+
"keccak": false,
|
|
145
|
+
"secp256k1": false,
|
|
146
|
+
"scrypt-js": false,
|
|
147
|
+
"bech32": false,
|
|
148
|
+
"ws": false,
|
|
149
|
+
"xhr2-cookies": false,
|
|
150
|
+
"aes-js": false,
|
|
151
|
+
"@ethersproject/sha2": false,
|
|
152
|
+
"@ethersproject/pbkdf2": false,
|
|
153
|
+
"@ethersproject/scrypt": false
|
|
154
|
+
},
|
|
155
|
+
"devDependencies": {
|
|
156
|
+
"@react-native-async-storage/async-storage": "^1.19.0",
|
|
157
|
+
"@rollup/plugin-commonjs": "^25.0.7",
|
|
158
|
+
"@rollup/plugin-json": "^6.1.0",
|
|
159
|
+
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
160
|
+
"@types/react": "^19.1.1",
|
|
161
|
+
"@types/react-native": "^0.72.8",
|
|
162
|
+
"rimraf": "^5.0.0",
|
|
163
|
+
"rollup": "^4.0.0",
|
|
164
|
+
"rollup-plugin-typescript2": "^0.36.0",
|
|
165
|
+
"typescript": "^5.2.0"
|
|
166
|
+
},
|
|
167
|
+
"files": [
|
|
168
|
+
"dist/**/*",
|
|
169
|
+
"src/**/*",
|
|
170
|
+
"README.md"
|
|
171
|
+
],
|
|
172
|
+
"repository": {
|
|
173
|
+
"type": "git",
|
|
174
|
+
"url": "git+https://github.com/eXplorins/pers-sdk.git",
|
|
175
|
+
"directory": "packages/pers-sdk-react-native"
|
|
176
|
+
}
|
|
177
|
+
}
|
package/src/hooks/index.ts
CHANGED
|
@@ -2,7 +2,19 @@
|
|
|
2
2
|
export { useAuth } from './useAuth';
|
|
3
3
|
export { useTokens } from './useTokens';
|
|
4
4
|
export { useTransactions } from './useTransactions';
|
|
5
|
+
export { useTransactionSigner } from './useTransactionSigner';
|
|
5
6
|
export { useBusiness } from './useBusiness';
|
|
6
7
|
export { useCampaigns } from './useCampaigns';
|
|
7
8
|
export { useRedemptions } from './useRedemptions';
|
|
8
|
-
export { useWeb3 } from './useWeb3';
|
|
9
|
+
export { useWeb3 } from './useWeb3';
|
|
10
|
+
export { usePurchases } from './usePurchases';
|
|
11
|
+
export { useTenants } from './useTenants';
|
|
12
|
+
export { useUsers } from './useUsers';
|
|
13
|
+
export { useUserStatus } from './useUserStatus';
|
|
14
|
+
export { useFiles } from './useFiles';
|
|
15
|
+
export { useAnalytics } from './useAnalytics';
|
|
16
|
+
export { useDonations } from './useDonations';
|
|
17
|
+
|
|
18
|
+
// Re-export auth-related types for convenience
|
|
19
|
+
export type { RawUserData } from './useAuth';
|
|
20
|
+
export type { TransactionSignerHook, TransactionSigningResult } from './useTransactionSigner';
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { useCallback } from 'react';
|
|
2
|
+
import { usePersSDK } from '../providers/PersSDKProvider';
|
|
3
|
+
|
|
4
|
+
// Import analytics types directly from core SDK
|
|
5
|
+
interface TransactionAnalyticsFilters {
|
|
6
|
+
status?: string;
|
|
7
|
+
tokenType?: string;
|
|
8
|
+
triggerProcessType?: string;
|
|
9
|
+
tenantId?: string;
|
|
10
|
+
chainId?: number;
|
|
11
|
+
type?: string;
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
type TransactionAnalyticsGroupBy =
|
|
16
|
+
| 'month' | 'week' | 'day' | 'year' | 'quarter'
|
|
17
|
+
| 'tokenType' | 'status' | 'chainId' | 'triggerProcessType' | 'type'
|
|
18
|
+
| 'senderAddress' | 'recipientAddress' | 'senderId' | 'recipientId' | 'senderOwnerType' | 'recipientOwnerType' | 'createdAt';
|
|
19
|
+
|
|
20
|
+
type TransactionAnalyticsMetric =
|
|
21
|
+
| 'count' | 'sum' | 'avg' | 'min' | 'max';
|
|
22
|
+
|
|
23
|
+
interface TransactionAnalyticsGroupByExpression {
|
|
24
|
+
expression: string;
|
|
25
|
+
alias: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Request DTO for transaction analytics
|
|
30
|
+
*/
|
|
31
|
+
interface TransactionAnalyticsRequestDTO {
|
|
32
|
+
filters?: TransactionAnalyticsFilters;
|
|
33
|
+
groupBy?: TransactionAnalyticsGroupBy[];
|
|
34
|
+
groupByExpressions?: TransactionAnalyticsGroupByExpression[];
|
|
35
|
+
metrics?: TransactionAnalyticsMetric[];
|
|
36
|
+
orderBy?: string;
|
|
37
|
+
orderDirection?: 'ASC' | 'DESC';
|
|
38
|
+
limit?: number;
|
|
39
|
+
startDate?: string;
|
|
40
|
+
endDate?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
interface TransactionAnalyticsResultItem {
|
|
44
|
+
[key: string]: string | number | Date | undefined;
|
|
45
|
+
count?: string;
|
|
46
|
+
sum?: number;
|
|
47
|
+
avg?: number;
|
|
48
|
+
min?: number;
|
|
49
|
+
max?: number;
|
|
50
|
+
tokentype?: string;
|
|
51
|
+
tokenType?: string;
|
|
52
|
+
year?: string;
|
|
53
|
+
month?: string;
|
|
54
|
+
type?: string;
|
|
55
|
+
senderaddress?: string;
|
|
56
|
+
senderAddress?: string;
|
|
57
|
+
recipientaddress?: string;
|
|
58
|
+
recipientAddress?: string;
|
|
59
|
+
triggerprocesstype?: string;
|
|
60
|
+
triggerProcessType?: string;
|
|
61
|
+
userid?: string;
|
|
62
|
+
userId?: string;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Response DTO for transaction analytics
|
|
67
|
+
*/
|
|
68
|
+
interface TransactionAnalyticsResponseDTO {
|
|
69
|
+
results: TransactionAnalyticsResultItem[];
|
|
70
|
+
totalGroups: number;
|
|
71
|
+
metadata: {
|
|
72
|
+
executionTime: string;
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* React hook for analytics operations in the PERS SDK
|
|
78
|
+
*
|
|
79
|
+
* Provides methods for retrieving transaction analytics and insights.
|
|
80
|
+
* Supports various analytics queries for business intelligence and reporting.
|
|
81
|
+
*
|
|
82
|
+
* @returns Analytics hook with methods for data analysis
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* function AnalyticsComponent() {
|
|
87
|
+
* const { getTransactionAnalytics } = useAnalytics();
|
|
88
|
+
*
|
|
89
|
+
* const loadAnalytics = async () => {
|
|
90
|
+
* try {
|
|
91
|
+
* const analytics = await getTransactionAnalytics({
|
|
92
|
+
* timeRange: 'last_30_days',
|
|
93
|
+
* groupBy: 'day'
|
|
94
|
+
* });
|
|
95
|
+
* console.log('Transaction analytics:', analytics);
|
|
96
|
+
* } catch (error) {
|
|
97
|
+
* console.error('Failed to load analytics:', error);
|
|
98
|
+
* }
|
|
99
|
+
* };
|
|
100
|
+
*
|
|
101
|
+
* return <button onClick={loadAnalytics}>Load Analytics</button>;
|
|
102
|
+
* }
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export const useAnalytics = () => {
|
|
106
|
+
const { sdk, isInitialized } = usePersSDK();
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Retrieves transaction analytics data based on request parameters
|
|
110
|
+
*
|
|
111
|
+
* @param request - Analytics request parameters (time range, grouping, filters, etc.)
|
|
112
|
+
* @returns Promise resolving to analytics data with results and metadata
|
|
113
|
+
* @throws Error if SDK is not initialized
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```typescript
|
|
117
|
+
* const { getTransactionAnalytics } = useAnalytics();
|
|
118
|
+
* const analytics = await getTransactionAnalytics({
|
|
119
|
+
* groupBy: ['day'],
|
|
120
|
+
* metrics: ['count', 'sum'],
|
|
121
|
+
* startDate: '2024-01-01',
|
|
122
|
+
* endDate: '2024-01-31',
|
|
123
|
+
* filters: { status: 'completed' }
|
|
124
|
+
* });
|
|
125
|
+
* console.log('Daily transaction analytics:', analytics.results);
|
|
126
|
+
* console.log('Execution time:', analytics.metadata.executionTime);
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
const getTransactionAnalytics = useCallback(async (request: TransactionAnalyticsRequestDTO): Promise<TransactionAnalyticsResponseDTO> => {
|
|
130
|
+
if (!isInitialized || !sdk) {
|
|
131
|
+
throw new Error('SDK not initialized. Call initialize() first.');
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
try {
|
|
135
|
+
const result = await sdk.analytics.getTransactionAnalytics(request);
|
|
136
|
+
console.log('Transaction analytics fetched successfully:', result);
|
|
137
|
+
return result;
|
|
138
|
+
} catch (error) {
|
|
139
|
+
console.error('Failed to fetch transaction analytics:', error);
|
|
140
|
+
throw error;
|
|
141
|
+
}
|
|
142
|
+
}, [sdk, isInitialized]);
|
|
143
|
+
|
|
144
|
+
return {
|
|
145
|
+
getTransactionAnalytics,
|
|
146
|
+
isAvailable: isInitialized && !!sdk?.analytics,
|
|
147
|
+
};
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
export type AnalyticsHook = ReturnType<typeof useAnalytics>;
|