@explorins/pers-sdk 1.1.2 → 1.1.3

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 (291) hide show
  1. package/dist/analytics/api/analytics-api.d.ts +17 -0
  2. package/dist/analytics/api/analytics-api.d.ts.map +1 -0
  3. package/{src/analytics/index.ts → dist/analytics/index.d.ts} +28 -52
  4. package/dist/analytics/index.d.ts.map +1 -0
  5. package/dist/analytics/models/index.d.ts +61 -0
  6. package/dist/analytics/models/index.d.ts.map +1 -0
  7. package/dist/analytics/services/analytics-service.d.ts +19 -0
  8. package/dist/analytics/services/analytics-service.d.ts.map +1 -0
  9. package/dist/analytics.cjs +76 -0
  10. package/dist/analytics.cjs.map +1 -0
  11. package/dist/analytics.d.ts +28 -0
  12. package/dist/analytics.js +72 -0
  13. package/dist/analytics.js.map +1 -0
  14. package/dist/auth-admin/api/auth-admin-api.d.ts +27 -0
  15. package/dist/auth-admin/api/auth-admin-api.d.ts.map +1 -0
  16. package/dist/auth-admin/index.d.ts +26 -0
  17. package/dist/auth-admin/index.d.ts.map +1 -0
  18. package/dist/auth-admin/services/auth-admin-service.d.ts +23 -0
  19. package/dist/auth-admin/services/auth-admin-service.d.ts.map +1 -0
  20. package/dist/auth-admin.cjs +96 -0
  21. package/dist/auth-admin.cjs.map +1 -0
  22. package/dist/auth-admin.d.ts +26 -0
  23. package/dist/auth-admin.js +92 -0
  24. package/dist/auth-admin.js.map +1 -0
  25. package/dist/business/api/business-api.d.ts +133 -0
  26. package/dist/business/api/business-api.d.ts.map +1 -0
  27. package/dist/business/index.d.ts +34 -0
  28. package/dist/business/index.d.ts.map +1 -0
  29. package/dist/business/models/index.d.ts +8 -0
  30. package/dist/business/models/index.d.ts.map +1 -0
  31. package/dist/business/services/business-service.d.ts +51 -0
  32. package/dist/business/services/business-service.d.ts.map +1 -0
  33. package/dist/business.cjs +303 -0
  34. package/dist/business.cjs.map +1 -0
  35. package/dist/business.d.ts +34 -0
  36. package/dist/business.js +299 -0
  37. package/dist/business.js.map +1 -0
  38. package/dist/campaign/api/campaign-api.d.ts +213 -0
  39. package/dist/campaign/api/campaign-api.d.ts.map +1 -0
  40. package/dist/campaign/index.d.ts +44 -0
  41. package/dist/campaign/index.d.ts.map +1 -0
  42. package/dist/campaign/services/campaign-service.d.ts +88 -0
  43. package/dist/campaign/services/campaign-service.d.ts.map +1 -0
  44. package/dist/campaign.cjs +506 -0
  45. package/dist/campaign.cjs.map +1 -0
  46. package/dist/campaign.d.ts +44 -0
  47. package/dist/campaign.js +502 -0
  48. package/dist/campaign.js.map +1 -0
  49. package/dist/core/abstractions/http-client.d.ts +22 -0
  50. package/dist/core/abstractions/http-client.d.ts.map +1 -0
  51. package/dist/core/auth/auth-provider.interface.d.ts +12 -0
  52. package/dist/core/auth/auth-provider.interface.d.ts.map +1 -0
  53. package/dist/core/auth/create-auth-provider.d.ts +27 -0
  54. package/dist/core/auth/create-auth-provider.d.ts.map +1 -0
  55. package/dist/core/auth/simple-auth-config.interface.d.ts +15 -0
  56. package/dist/core/auth/simple-auth-config.interface.d.ts.map +1 -0
  57. package/dist/core/index.d.ts +13 -0
  58. package/dist/core/index.d.ts.map +1 -0
  59. package/dist/core/pers-api-client.d.ts +54 -0
  60. package/dist/core/pers-api-client.d.ts.map +1 -0
  61. package/dist/core/pers-config.d.ts +38 -0
  62. package/dist/core/pers-config.d.ts.map +1 -0
  63. package/dist/core/utils/jwt.function.d.ts +2 -0
  64. package/dist/core/utils/jwt.function.d.ts.map +1 -0
  65. package/dist/core.cjs +506 -0
  66. package/dist/core.cjs.map +1 -0
  67. package/dist/core.d.ts +13 -0
  68. package/dist/core.js +497 -0
  69. package/dist/core.js.map +1 -0
  70. package/dist/donation/api/donation-api.d.ts +18 -0
  71. package/dist/donation/api/donation-api.d.ts.map +1 -0
  72. package/dist/donation/index.d.ts +25 -0
  73. package/dist/donation/index.d.ts.map +1 -0
  74. package/{src/donation/models/index.ts → dist/donation/models/index.d.ts} +8 -11
  75. package/dist/donation/models/index.d.ts.map +1 -0
  76. package/dist/donation/services/donation-service.d.ts +19 -0
  77. package/dist/donation/services/donation-service.d.ts.map +1 -0
  78. package/dist/donation.cjs +78 -0
  79. package/dist/donation.cjs.map +1 -0
  80. package/dist/donation.d.ts +25 -0
  81. package/dist/donation.js +74 -0
  82. package/dist/donation.js.map +1 -0
  83. package/dist/index.cjs +4217 -0
  84. package/dist/index.cjs.map +1 -0
  85. package/dist/index.d.ts +21 -0
  86. package/dist/index.d.ts.map +1 -0
  87. package/dist/index.js +4164 -0
  88. package/dist/index.js.map +1 -0
  89. package/dist/package.json +148 -0
  90. package/dist/payment/api/payment-api.d.ts +105 -0
  91. package/dist/payment/api/payment-api.d.ts.map +1 -0
  92. package/dist/payment/index.d.ts +36 -0
  93. package/dist/payment/index.d.ts.map +1 -0
  94. package/dist/payment/models/index.d.ts +12 -0
  95. package/dist/payment/models/index.d.ts.map +1 -0
  96. package/dist/payment/services/payment-service.d.ts +40 -0
  97. package/dist/payment/services/payment-service.d.ts.map +1 -0
  98. package/dist/payment.cjs +258 -0
  99. package/dist/payment.cjs.map +1 -0
  100. package/dist/payment.d.ts +36 -0
  101. package/dist/payment.js +254 -0
  102. package/dist/payment.js.map +1 -0
  103. package/dist/pers-sdk.d.ts +29 -0
  104. package/dist/pers-sdk.d.ts.map +1 -0
  105. package/dist/redemption/api/redemption-api.d.ts +147 -0
  106. package/dist/redemption/api/redemption-api.d.ts.map +1 -0
  107. package/dist/redemption/index.d.ts +35 -0
  108. package/dist/redemption/index.d.ts.map +1 -0
  109. package/dist/redemption/models/index.d.ts +8 -0
  110. package/dist/redemption/models/index.d.ts.map +1 -0
  111. package/dist/redemption/services/redemption-service.d.ts +56 -0
  112. package/dist/redemption/services/redemption-service.d.ts.map +1 -0
  113. package/dist/redemption.cjs +333 -0
  114. package/dist/redemption.cjs.map +1 -0
  115. package/dist/redemption.d.ts +35 -0
  116. package/dist/redemption.js +329 -0
  117. package/dist/redemption.js.map +1 -0
  118. package/dist/shared/interfaces/pers-shared-lib.interfaces.d.ts +18 -0
  119. package/dist/shared/interfaces/pers-shared-lib.interfaces.d.ts.map +1 -0
  120. package/dist/tenant/api/tenant-api.d.ts +56 -0
  121. package/dist/tenant/api/tenant-api.d.ts.map +1 -0
  122. package/dist/tenant/index.d.ts +34 -0
  123. package/dist/tenant/index.d.ts.map +1 -0
  124. package/dist/tenant/models/index.d.ts +11 -0
  125. package/dist/tenant/models/index.d.ts.map +1 -0
  126. package/dist/tenant/services/tenant-service.d.ts +46 -0
  127. package/dist/tenant/services/tenant-service.d.ts.map +1 -0
  128. package/dist/tenant.cjs +177 -0
  129. package/dist/tenant.cjs.map +1 -0
  130. package/dist/tenant.d.ts +34 -0
  131. package/dist/tenant.js +173 -0
  132. package/dist/tenant.js.map +1 -0
  133. package/dist/token/api/token-api.d.ts +64 -0
  134. package/dist/token/api/token-api.d.ts.map +1 -0
  135. package/dist/token/base/base-token-service.d.ts +87 -0
  136. package/dist/token/base/base-token-service.d.ts.map +1 -0
  137. package/dist/token/index.d.ts +13 -0
  138. package/dist/token/index.d.ts.map +1 -0
  139. package/dist/token/models/index.d.ts +18 -0
  140. package/dist/token/models/index.d.ts.map +1 -0
  141. package/dist/token/services/token-service.d.ts +68 -0
  142. package/dist/token/services/token-service.d.ts.map +1 -0
  143. package/dist/token/token-sdk.d.ts +140 -0
  144. package/dist/token/token-sdk.d.ts.map +1 -0
  145. package/dist/token.cjs +537 -0
  146. package/dist/token.cjs.map +1 -0
  147. package/dist/token.d.ts +13 -0
  148. package/dist/token.js +532 -0
  149. package/dist/token.js.map +1 -0
  150. package/dist/transaction/api/transaction-api.d.ts +133 -0
  151. package/dist/transaction/api/transaction-api.d.ts.map +1 -0
  152. package/dist/transaction/index.d.ts +38 -0
  153. package/dist/transaction/index.d.ts.map +1 -0
  154. package/dist/transaction/models/index.d.ts +42 -0
  155. package/dist/transaction/models/index.d.ts.map +1 -0
  156. package/dist/transaction/services/transaction-service.d.ts +56 -0
  157. package/dist/transaction/services/transaction-service.d.ts.map +1 -0
  158. package/dist/transaction.cjs +394 -0
  159. package/dist/transaction.cjs.map +1 -0
  160. package/dist/transaction.d.ts +38 -0
  161. package/dist/transaction.js +390 -0
  162. package/dist/transaction.js.map +1 -0
  163. package/dist/user/api/user-api.d.ts +56 -0
  164. package/dist/user/api/user-api.d.ts.map +1 -0
  165. package/dist/user/index.d.ts +36 -0
  166. package/dist/user/index.d.ts.map +1 -0
  167. package/{src/user/models/index.ts → dist/user/models/index.d.ts} +12 -10
  168. package/dist/user/models/index.d.ts.map +1 -0
  169. package/dist/user/services/user-service.d.ts +46 -0
  170. package/dist/user/services/user-service.d.ts.map +1 -0
  171. package/dist/user-status/api/user-status-api.d.ts +37 -0
  172. package/dist/user-status/api/user-status-api.d.ts.map +1 -0
  173. package/dist/user-status/index.d.ts +28 -0
  174. package/dist/user-status/index.d.ts.map +1 -0
  175. package/{src/user-status/models/index.ts → dist/user-status/models/index.d.ts} +8 -11
  176. package/dist/user-status/models/index.d.ts.map +1 -0
  177. package/dist/user-status/services/user-status-service.d.ts +26 -0
  178. package/dist/user-status/services/user-status-service.d.ts.map +1 -0
  179. package/dist/user-status.cjs +147 -0
  180. package/dist/user-status.cjs.map +1 -0
  181. package/dist/user-status.d.ts +28 -0
  182. package/dist/user-status.js +143 -0
  183. package/dist/user-status.js.map +1 -0
  184. package/dist/user.cjs +188 -0
  185. package/dist/user.cjs.map +1 -0
  186. package/dist/user.d.ts +36 -0
  187. package/dist/user.js +184 -0
  188. package/dist/user.js.map +1 -0
  189. package/dist/web3/api/web3-api.d.ts +27 -0
  190. package/dist/web3/api/web3-api.d.ts.map +1 -0
  191. package/dist/web3/index.d.ts +16 -0
  192. package/dist/web3/index.d.ts.map +1 -0
  193. package/dist/web3/models/index.d.ts +92 -0
  194. package/dist/web3/models/index.d.ts.map +1 -0
  195. package/dist/web3/services/web3-service.d.ts +21 -0
  196. package/dist/web3/services/web3-service.d.ts.map +1 -0
  197. package/dist/web3-chain/api/web3-chain-api.d.ts +19 -0
  198. package/dist/web3-chain/api/web3-chain-api.d.ts.map +1 -0
  199. package/dist/web3-chain/index.d.ts +17 -0
  200. package/dist/web3-chain/index.d.ts.map +1 -0
  201. package/{src/web3-chain/models/index.ts → dist/web3-chain/models/index.d.ts} +38 -45
  202. package/dist/web3-chain/models/index.d.ts.map +1 -0
  203. package/dist/web3-chain/services/getWeb3FCD.service.d.ts +8 -0
  204. package/dist/web3-chain/services/getWeb3FCD.service.d.ts.map +1 -0
  205. package/dist/web3-chain/services/provider.service.d.ts +15 -0
  206. package/dist/web3-chain/services/provider.service.d.ts.map +1 -0
  207. package/dist/web3-chain/services/public-http-provider.service.d.ts +8 -0
  208. package/dist/web3-chain/services/public-http-provider.service.d.ts.map +1 -0
  209. package/dist/web3-chain/services/web3-chain-service.d.ts +17 -0
  210. package/dist/web3-chain/services/web3-chain-service.d.ts.map +1 -0
  211. package/dist/web3-chain.cjs +316 -0
  212. package/dist/web3-chain.cjs.map +1 -0
  213. package/dist/web3-chain.d.ts +17 -0
  214. package/dist/web3-chain.js +310 -0
  215. package/dist/web3-chain.js.map +1 -0
  216. package/dist/web3.cjs +516 -0
  217. package/dist/web3.cjs.map +1 -0
  218. package/dist/web3.d.ts +16 -0
  219. package/dist/web3.js +513 -0
  220. package/dist/web3.js.map +1 -0
  221. package/package.json +70 -67
  222. package/config/domains.js +0 -22
  223. package/explorins-pers-sdk-1.0.0-alpha.1.tgz +0 -0
  224. package/rollup.config.js +0 -74
  225. package/scripts/copy-declarations.js +0 -147
  226. package/src/analytics/api/analytics-api.ts +0 -24
  227. package/src/analytics/models/index.ts +0 -74
  228. package/src/analytics/services/analytics-service.ts +0 -28
  229. package/src/auth-admin/api/auth-admin-api.ts +0 -42
  230. package/src/auth-admin/index.ts +0 -47
  231. package/src/auth-admin/services/auth-admin-service.ts +0 -36
  232. package/src/business/api/business-api.ts +0 -234
  233. package/src/business/index.ts +0 -53
  234. package/src/business/models/index.ts +0 -13
  235. package/src/business/services/business-service.ts +0 -88
  236. package/src/campaign/api/campaign-api.ts +0 -376
  237. package/src/campaign/index.ts +0 -67
  238. package/src/campaign/services/campaign-service.ts +0 -164
  239. package/src/core/abstractions/http-client.ts +0 -24
  240. package/src/core/auth/auth-provider.interface.ts +0 -16
  241. package/src/core/auth/create-auth-provider.ts +0 -136
  242. package/src/core/auth/simple-auth-config.interface.ts +0 -15
  243. package/src/core/index.ts +0 -33
  244. package/src/core/pers-api-client.ts +0 -343
  245. package/src/core/pers-config.ts +0 -65
  246. package/src/core/utils/jwt.function.ts +0 -24
  247. package/src/donation/api/donation-api.ts +0 -24
  248. package/src/donation/index.ts +0 -47
  249. package/src/donation/services/donation-service.ts +0 -25
  250. package/src/index.ts +0 -55
  251. package/src/payment/api/payment-api.ts +0 -185
  252. package/src/payment/index.ts +0 -64
  253. package/src/payment/models/index.ts +0 -29
  254. package/src/payment/services/payment-service.ts +0 -70
  255. package/src/pers-sdk.ts +0 -45
  256. package/src/redemption/api/redemption-api.ts +0 -241
  257. package/src/redemption/index.ts +0 -60
  258. package/src/redemption/models/index.ts +0 -17
  259. package/src/redemption/services/redemption-service.ts +0 -103
  260. package/src/shared/interfaces/pers-shared-lib.interfaces.ts +0 -99
  261. package/src/tenant/api/tenant-api.ts +0 -92
  262. package/src/tenant/index.ts +0 -61
  263. package/src/tenant/models/index.ts +0 -20
  264. package/src/tenant/services/tenant-service.ts +0 -78
  265. package/src/token/api/token-api.ts +0 -129
  266. package/src/token/base/base-token-service.ts +0 -167
  267. package/src/token/index.ts +0 -38
  268. package/src/token/models/index.ts +0 -30
  269. package/src/token/services/token-service.ts +0 -125
  270. package/src/token/token-sdk.ts +0 -231
  271. package/src/transaction/api/transaction-api.ts +0 -296
  272. package/src/transaction/index.ts +0 -65
  273. package/src/transaction/models/index.ts +0 -60
  274. package/src/transaction/services/transaction-service.ts +0 -104
  275. package/src/user/api/user-api.ts +0 -98
  276. package/src/user/index.ts +0 -62
  277. package/src/user/services/user-service.ts +0 -75
  278. package/src/user-status/api/user-status-api.ts +0 -78
  279. package/src/user-status/index.ts +0 -55
  280. package/src/user-status/services/user-status-service.ts +0 -51
  281. package/src/web3/api/web3-api.ts +0 -68
  282. package/src/web3/index.ts +0 -38
  283. package/src/web3/models/index.ts +0 -150
  284. package/src/web3/services/web3-service.ts +0 -338
  285. package/src/web3-chain/api/web3-chain-api.ts +0 -42
  286. package/src/web3-chain/index.ts +0 -27
  287. package/src/web3-chain/services/getWeb3FCD.service.ts +0 -47
  288. package/src/web3-chain/services/provider.service.ts +0 -123
  289. package/src/web3-chain/services/public-http-provider.service.ts +0 -26
  290. package/src/web3-chain/services/web3-chain-service.ts +0 -131
  291. package/tsconfig.json +0 -28
@@ -1,150 +0,0 @@
1
- import type { ContractAbi, Web3 } from 'web3';
2
- import type { TokenDTO } from '../../shared/interfaces/pers-shared-lib.interfaces';
3
-
4
- // ✅ REMOVE: Custom Web3ContractAbi type (no longer needed)
5
- // export type Web3ContractAbi = readonly AbiFragment[] | AbiFragment[];
6
-
7
- export interface Web3BalanceRequest {
8
- accountAddress: string;
9
- token: TokenDTO;
10
- tokenId: string | null;
11
- }
12
-
13
- export interface Web3BalanceResponse {
14
- rawBalance: number;
15
- formattedBalance: string;
16
- decimals: number;
17
- symbol: string;
18
- hasBalance: boolean;
19
- }
20
-
21
- export interface Web3TokenConfig {
22
- token: TokenDTO;
23
- tokenIds?: (string | null)[];
24
- metadata?: any[];
25
- }
26
-
27
- export interface Web3TokenListRequest {
28
- accountAddress: string;
29
- tokens: Web3TokenConfig[];
30
- }
31
-
32
- export interface Web3TokenResult {
33
- tokenId: string | null;
34
- balance: number;
35
- formattedBalance: string;
36
- hasBalance: boolean;
37
- metadata: any | null;
38
- }
39
-
40
- export interface Web3TokenListResponse {
41
- accountAddress: string;
42
- tokens: {
43
- token: TokenDTO;
44
- results: Web3TokenResult[];
45
- }[];
46
- }
47
-
48
- export interface NFTItem {
49
- tokenId: string;
50
- name: string;
51
- description: string;
52
- imageUrl: string;
53
- rawBalance: number;
54
- formattedBalance: string;
55
- hasBalance: boolean;
56
- metadata: any;
57
- tokenIndex: number;
58
- }
59
-
60
- export interface ERC721CollectionRequest {
61
- accountAddress: string;
62
- nftContracts: TokenDTO[];
63
- maxNFTsPerContract?: number;
64
- }
65
-
66
- export interface ERC721CollectionResponse {
67
- accountAddress: string;
68
- contracts: {
69
- token: TokenDTO;
70
- totalNFTs: number;
71
- nfts: NFTItem[];
72
- hasMore: boolean;
73
- }[];
74
- summary: {
75
- totalContracts: number;
76
- totalNFTs: number;
77
- loadingTime: number;
78
- };
79
- }
80
-
81
- // ✅ NEW: ERC20 Balance types (simplified)
82
- export interface ERC20BalanceRequest {
83
- accountAddress: string;
84
- token: TokenDTO;
85
- }
86
-
87
- // ✅ NEW: ERC1155 Collection types (clearer naming)
88
- export interface ERC1155CollectionRequest {
89
- accountAddress: string;
90
- tokens: TokenDTO[];
91
- }
92
-
93
- // ✅ RE-EXPORT: Standard Web3.js types for consumers
94
- export type { ContractAbi } from 'web3';
95
-
96
- // ✅ CACHE: Simple cache interface with TTL
97
- export interface CacheEntry<T> {
98
- data: T;
99
- timestamp: number;
100
- ttl: number;
101
- }
102
-
103
- export interface CacheStorage {
104
- [key: string]: CacheEntry<unknown>;
105
- }
106
-
107
- export class SimpleCache {
108
- private storage: CacheStorage = {};
109
- private readonly defaultTTL = 10 * 1000; // 10 seconds
110
-
111
- set<T>(key: string, data: T, ttl?: number): void {
112
- this.storage[key] = {
113
- data,
114
- timestamp: Date.now(),
115
- ttl: ttl ?? this.defaultTTL
116
- };
117
- }
118
-
119
- get<T>(key: string): T | null {
120
- const entry = this.storage[key];
121
-
122
- if (!entry) {
123
- return null;
124
- }
125
-
126
- const now = Date.now();
127
- const isExpired = (now - entry.timestamp) > entry.ttl;
128
-
129
- if (isExpired) {
130
- delete this.storage[key];
131
- return null;
132
- }
133
-
134
- return entry.data as T;
135
- }
136
-
137
- clear(): void {
138
- this.storage = {};
139
- }
140
-
141
- cleanup(): void {
142
- const now = Date.now();
143
- Object.keys(this.storage).forEach(key => {
144
- const entry = this.storage[key];
145
- if ((now - entry.timestamp) > entry.ttl) {
146
- delete this.storage[key];
147
- }
148
- });
149
- }
150
- }
@@ -1,338 +0,0 @@
1
- import { Web3ChainService } from '../../web3-chain';
2
- import { Web3Api } from '../api/web3-api';
3
- import {
4
- ERC20BalanceRequest,
5
- ERC1155CollectionRequest,
6
- ERC721CollectionRequest,
7
- ERC721CollectionResponse,
8
- NFTItem,
9
- Web3BalanceResponse,
10
- Web3TokenListResponse,
11
- Web3TokenResult,
12
- SimpleCache
13
- } from '../models';
14
-
15
- export class Web3Service {
16
- //temporary fix, remove when the backend supports custom gateways
17
- private readonly defaultIpfsGatewayDomain = 'pers.mypinata.cloud';
18
-
19
- // ✅ CACHE: Simple 10-second cache instance
20
- private cache = new SimpleCache();
21
- private cleanupInterval: NodeJS.Timeout | null = null;
22
-
23
- constructor(
24
- private web3Api: Web3Api,
25
- private web3ChainService: Web3ChainService
26
- ) {
27
- this.cleanupInterval = setInterval(() => {
28
- this.cache.cleanup();
29
- }, 30 * 1000);
30
- }
31
-
32
- destroy(): void {
33
- if (this.cleanupInterval) {
34
- clearInterval(this.cleanupInterval);
35
- this.cleanupInterval = null;
36
- }
37
- this.cache.clear();
38
- }
39
-
40
- async getERC20Balance(request: ERC20BalanceRequest): Promise<Web3BalanceResponse> {
41
-
42
- const cacheKey = `erc20_balance_${request.accountAddress}_${request.token.contractAddress}_${request.token.chainId}`;
43
-
44
- // ✅ CACHE CHECK: Try to get from cache first
45
- const cached = this.cache.get<Web3BalanceResponse>(cacheKey);
46
- if (cached) {
47
- console.debug(`💾 [Web3Service] Using cached ERC20 balance for ${request.token.symbol}`);
48
- return cached;
49
- }
50
-
51
- console.debug(`🔄 [Web3Service] Fetching fresh ERC20 balance for ${request.token.symbol}`);
52
-
53
- const rawBalance = await this.web3Api.getTokenBalance({
54
- accountAddress: request.accountAddress,
55
- contractAddress: request.token.contractAddress,
56
- abi: request.token.abi,
57
- tokenId: null, // Always null for ERC20
58
- chainId: request.token.chainId
59
- });
60
-
61
- const decimals = request.token.decimals ?? 18;
62
- const symbol = request.token.symbol ?? 'UNKNOWN';
63
-
64
- const response: Web3BalanceResponse = {
65
- rawBalance,
66
- formattedBalance: this.formatBalance(rawBalance, decimals),
67
- decimals,
68
- symbol,
69
- hasBalance: rawBalance > 0
70
- };
71
-
72
- // ✅ CACHE SET: Store result in cache
73
- this.cache.set(cacheKey, response);
74
-
75
- return response;
76
- }
77
-
78
- async getERC1155Collection(request: ERC1155CollectionRequest): Promise<Web3TokenListResponse> {
79
-
80
- // ✅ CACHE KEY: Create unique cache key for collection request
81
- const contractAddresses = request.tokens.map(t => t.contractAddress).sort().join(',');
82
- const cacheKey = `erc1155_collection_${request.accountAddress}_${contractAddresses}`;
83
-
84
- // ✅ CACHE CHECK: Try to get from cache first
85
- const cached = this.cache.get<Web3TokenListResponse>(cacheKey);
86
- if (cached) {
87
- console.debug(`💾 [Web3Service] Using cached ERC1155 collection for ${request.accountAddress}`);
88
- return cached;
89
- }
90
-
91
- console.debug(`🔄 [Web3Service] Fetching fresh ERC1155 collection for ${request.accountAddress}`);
92
-
93
- const tokenResults = await Promise.all(
94
- request.tokens.map(async (token) => {
95
- // ✅ FIXED: Handle null metadata properly
96
- const tokenIds: string[] = token.metadata?.map(m =>
97
- m.tokenMetadataIncrementalId?.toString()
98
- ).filter((id): id is string => id !== undefined) ?? [];
99
-
100
- // Check balance for each known tokenId
101
- const balanceResults = await Promise.allSettled(
102
- tokenIds.map(async (tokenId) => {
103
- try {
104
- const rawBalance = await this.web3Api.getTokenBalance({
105
- accountAddress: request.accountAddress,
106
- contractAddress: token.contractAddress,
107
- abi: token.abi,
108
- tokenId,
109
- chainId: token.chainId
110
- });
111
-
112
- const decimals = token.decimals ?? 0; // ERC1155 usually no decimals
113
-
114
- return {
115
- tokenId,
116
- balance: rawBalance,
117
- formattedBalance: this.formatBalance(rawBalance, decimals),
118
- hasBalance: rawBalance > 0,
119
- // ✅ FIXED: Convert null to undefined for findMetadata
120
- metadata: this.findMetadata(token.metadata ?? undefined, tokenId)
121
- };
122
- } catch (error) {
123
- console.warn(`Failed to get balance for token ${token.contractAddress}:${tokenId}`, error);
124
- return null; // Skip failed tokens
125
- }
126
- })
127
- );
128
-
129
- // Filter successful results with balance > 0
130
- const successfulResults: Web3TokenResult[] = [];
131
- for (const result of balanceResults) {
132
- if (result.status === 'fulfilled' && result.value !== null && result.value.hasBalance) {
133
- successfulResults.push(result.value);
134
- }
135
- }
136
-
137
- return {
138
- token,
139
- results: successfulResults
140
- };
141
- })
142
- );
143
-
144
- const response: Web3TokenListResponse = {
145
- accountAddress: request.accountAddress,
146
- tokens: tokenResults.filter(t => t.results.length > 0)
147
- };
148
-
149
- // ✅ CACHE SET: Store complete collection result
150
- this.cache.set(cacheKey, response);
151
-
152
- return response;
153
- }
154
-
155
- async getERC721Collection(request: ERC721CollectionRequest): Promise<ERC721CollectionResponse> {
156
-
157
- // ✅ CACHE KEY: Create unique cache key for NFT collection
158
- const contractAddresses = request.nftContracts.map(t => t.contractAddress).sort().join(',');
159
- const maxNFTs = request.maxNFTsPerContract || 50;
160
- const cacheKey = `erc721_collection_${request.accountAddress}_${contractAddresses}_${maxNFTs}`;
161
-
162
- // ✅ CACHE CHECK: Try to get from cache first
163
- const cached = this.cache.get<ERC721CollectionResponse>(cacheKey);
164
- if (cached) {
165
- console.debug(`💾 [Web3Service] Using cached ERC721 collection for ${request.accountAddress}`);
166
- return cached;
167
- }
168
-
169
- console.debug(`🔄 [Web3Service] Fetching fresh ERC721 collection for ${request.accountAddress}`);
170
-
171
- const startTime = Date.now();
172
-
173
- const contractResults = await Promise.all(
174
- request.nftContracts.map(async (token) => {
175
- try {
176
- const totalBalance = await this.web3Api.getTokenBalance({
177
- accountAddress: request.accountAddress,
178
- contractAddress: token.contractAddress,
179
- abi: token.abi,
180
- tokenId: null,
181
- chainId: token.chainId
182
- });
183
-
184
- if (totalBalance === 0) {
185
- return {
186
- token,
187
- totalNFTs: 0,
188
- nfts: [],
189
- hasMore: false
190
- };
191
- }
192
-
193
- const nftsToLoad = Math.min(totalBalance, maxNFTs);
194
-
195
- const nftResults = await Promise.allSettled(
196
- Array.from({ length: nftsToLoad }, async (_, index): Promise<NFTItem | null> => {
197
- try {
198
- const tokenId = await this.web3Api.getTokenOfOwnerByIndex({
199
- contractAddress: token.contractAddress,
200
- abi: token.abi,
201
- accountAddress: request.accountAddress,
202
- tokenIndex: index,
203
- chainId: token.chainId
204
- });
205
-
206
- const tokenUri = await this.web3Api.getTokenUri({
207
- contractAddress: token.contractAddress,
208
- abi: token.abi,
209
- tokenId,
210
- chainId: token.chainId
211
- });
212
-
213
- const metadata = await this.fetchMetadata(tokenUri, token.chainId);
214
-
215
- const nftItem: NFTItem = {
216
- tokenId,
217
- name: metadata?.name || `Token #${tokenId}`,
218
- description: metadata?.description || '',
219
- imageUrl: await this.resolveIPFSUrl(metadata?.image || '', token.chainId),
220
- rawBalance: 1,
221
- formattedBalance: '1',
222
- hasBalance: true,
223
- metadata,
224
- tokenIndex: index
225
- };
226
-
227
- return nftItem;
228
-
229
- } catch (error) {
230
- console.warn(`Failed to load NFT at index ${index} for ${token.symbol}:`, error);
231
- return null;
232
- }
233
- })
234
- );
235
-
236
- // ✅ FIXED: Usar tipo específico NFTItem
237
- const successfulNFTs = nftResults
238
- .filter((result): result is PromiseFulfilledResult<NFTItem | null> =>
239
- result.status === 'fulfilled' && result.value !== null
240
- )
241
- .map(result => result.value as NFTItem);
242
-
243
- return {
244
- token,
245
- totalNFTs: totalBalance,
246
- nfts: successfulNFTs,
247
- hasMore: totalBalance > maxNFTs
248
- };
249
-
250
- } catch (error) {
251
- console.error(`Failed to load NFT collection for ${token.symbol}:`, error);
252
- return {
253
- token,
254
- totalNFTs: 0,
255
- nfts: [],
256
- hasMore: false
257
- };
258
- }
259
- })
260
- );
261
-
262
- const totalNFTs = contractResults.reduce((sum, contract) => sum + contract.nfts.length, 0);
263
- const loadingTime = Date.now() - startTime;
264
-
265
- const response: ERC721CollectionResponse = {
266
- accountAddress: request.accountAddress,
267
- contracts: contractResults,
268
- summary: {
269
- totalContracts: request.nftContracts.length,
270
- totalNFTs,
271
- loadingTime
272
- }
273
- };
274
-
275
- // ✅ CACHE SET: Store complete collection response
276
- this.cache.set(cacheKey, response);
277
-
278
- return response;
279
- }
280
-
281
- // ==========================================
282
- // HELPER METHODS
283
- // ==========================================
284
-
285
- private formatBalance(rawBalance: number, decimals: number): string {
286
- const balance = rawBalance / Math.pow(10, decimals);
287
-
288
- return balance.toLocaleString('en-US', {
289
- minimumFractionDigits: 0,
290
- maximumFractionDigits: decimals > 0 ? 2 : 0
291
- });
292
- }
293
-
294
- // ✅ FIXED: Update method signature to handle null properly
295
- private findMetadata(metadata: any[] | undefined, tokenId: string | null): any | null {
296
- if (!metadata || tokenId === null) return null;
297
- return metadata.find(m =>
298
- m.tokenMetadataIncrementalId?.toString() === tokenId
299
- ) || null;
300
- }
301
-
302
- private async fetchMetadata(uri: string, chainId: number): Promise<any> {
303
- try {
304
- const httpUrl = await this.resolveIPFSUrl(uri, chainId);
305
- const response = await fetch(httpUrl);
306
-
307
- if (!response.ok) {
308
- throw new Error(`HTTP ${response.status}: ${response.statusText}`);
309
- }
310
-
311
- return await response.json();
312
- } catch (error) {
313
- console.warn('Failed to fetch NFT metadata:', error);
314
- return null;
315
- }
316
- }
317
-
318
- private async getIpfsGatewayDomain(chainId: number): Promise<string> {
319
- try {
320
- const chainData = await this.web3ChainService.getChainDataWithCache(chainId);
321
- return chainData.ipfsGatewayDomain || this.defaultIpfsGatewayDomain;
322
- } catch (error) {
323
- console.warn(`Failed to get chain data for chainId ${chainId}, using default IPFS gateway:`, error);
324
- return this.defaultIpfsGatewayDomain;
325
- }
326
- }
327
-
328
- private async resolveIPFSUrl(url: string, chainId: number): Promise<string> {
329
- if (!url) return '';
330
-
331
- if (url.startsWith('ipfs://')) {
332
- const gatewayDomain = await this.getIpfsGatewayDomain(chainId);
333
- return `https://${gatewayDomain}/ipfs/${url.slice(7)}`;
334
- }
335
-
336
- return url;
337
- }
338
- }
@@ -1,42 +0,0 @@
1
- import { PersApiClient } from '../../core/pers-api-client';
2
- import { ChainData } from '../models';
3
-
4
- /**
5
- * Platform-Agnostic Web3 Chain API Client
6
- *
7
- * Handles blockchain chain operations using the PERS backend.
8
- * Uses @explorins/web3-ts types for perfect framework compatibility.
9
- */
10
- export class Web3ChainApi {
11
- constructor(private apiClient: PersApiClient) {}
12
-
13
- private basePath = '/chains';
14
-
15
- // ==========================================
16
- // PUBLIC OPERATIONS
17
- // ==========================================
18
-
19
- /**
20
- * PUBLIC: Get chain data by chain ID
21
- * ✅ Returns ChainData exactly as framework expects from @explorins/web3-ts
22
- */
23
- async getChainData(chainId: number): Promise<ChainData> {
24
- try {
25
-
26
- console.log('🔍 [Web3ChainApi] Fetching chain data for chainId:', chainId);
27
- const response = await this.apiClient.get<ChainData>(`${this.basePath}/${chainId}`);
28
-
29
- if (!response) {
30
- throw new Error(`No chain data received for chainId: ${chainId}`);
31
- }
32
-
33
- return response;
34
- } catch (error) {
35
- console.error('❌ [Web3ChainApi] Failed to get chain data:', {
36
- chainId,
37
- error: error instanceof Error ? error.message : String(error)
38
- });
39
- throw error;
40
- }
41
- }
42
- }
@@ -1,27 +0,0 @@
1
- import { PersApiClient } from '../core/pers-api-client';
2
- import { Web3ChainApi } from './api/web3-chain-api';
3
- import { Web3ProviderService } from './services/provider.service';
4
-
5
- import { Web3ChainService } from './services/web3-chain-service';
6
-
7
- export function createWeb3ChainSDK(apiClient: PersApiClient, providerService: Web3ProviderService) {
8
- const web3ChainApi = new Web3ChainApi(apiClient);
9
- const web3ChainService = new Web3ChainService(web3ChainApi, providerService); // ✅ DIRECT INJECTION
10
-
11
- return {
12
- // ✅ REPLICA: Same methods as framework
13
- getChainDataById: (chainId: number) => web3ChainService.getChainDataById(chainId),
14
- getWeb3ByChainId: (chainId: number) => web3ChainService.getWeb3ByChainId(chainId),
15
-
16
- api: web3ChainApi,
17
- service: web3ChainService
18
- };
19
- }
20
-
21
- // ✅ EXPORT: All models and service
22
- export { Web3ChainApi } from './api/web3-chain-api';
23
- export { Web3ChainService } from './services/web3-chain-service';
24
- export { Web3ProviderService } from './services/provider.service';
25
- export * from './models';
26
- export type { ChainData } from './models';
27
- export * from '../shared/interfaces/pers-shared-lib.interfaces';
@@ -1,47 +0,0 @@
1
-
2
- //IMPORTANT//
3
- //This function is temporary so we install ethers just to make it work, once we delete this function we must uninstall Ethers
4
-
5
- import { ChainData } from "@explorins/web3-ts";
6
- import { FetchRequest, JsonRpcProvider } from "ethers";
7
-
8
- export const getWeb3ProviderFromChainData = (
9
- chainData: ChainData,
10
- timeout = 15000,
11
- customUserAgentName = '',
12
- tokenRefresher?: () => Promise<string>
13
- ) => {
14
-
15
- // Fixed ethers provider setup for authenticated requests
16
- let ethersProvider: JsonRpcProvider;
17
-
18
- if (chainData.authHeader) {
19
- // For authenticated requests, create a custom FetchRequest
20
- const fetchRequest = new FetchRequest(chainData.rpcUrl);
21
- fetchRequest.timeout = timeout;
22
- fetchRequest.setHeader('Authorization', chainData.authHeader);
23
- fetchRequest.setHeader('Content-Type', 'application/json');
24
-
25
- if (customUserAgentName) {
26
- fetchRequest.setHeader('User-Agent', customUserAgentName);
27
- }
28
-
29
- // Create provider with the configured FetchRequest
30
- ethersProvider = new JsonRpcProvider(fetchRequest, undefined, {
31
- staticNetwork: false,
32
- polling: false, // Disable polling for better Lambda performance
33
- });
34
- } else {
35
- // For public chains, use simple URL-based provider
36
- ethersProvider = new JsonRpcProvider(chainData.rpcUrl, undefined, {
37
- staticNetwork: false,
38
- polling: false,
39
- });
40
- }
41
-
42
- return {
43
- web3Provider: null,
44
- ethersProvider: ethersProvider,
45
- isAuthenticated: !!chainData.authHeader,
46
- };
47
- };