@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,136 +0,0 @@
1
- import { PersAuthProvider } from './auth-provider.interface';
2
- import { SimpleAuthConfig } from './simple-auth-config.interface';
3
-
4
- /**
5
- * Creates a platform-agnostic AuthProvider from simple configuration
6
- *
7
- * This factory function is completely platform-agnostic and can be used
8
- * across Angular, React, Vue, Node.js, or any other JavaScript environment.
9
- *
10
- * Features:
11
- * - Token caching with refresh support
12
- * - Automatic token refresh on expiration
13
- * - Configurable token providers
14
- * - Platform-independent (no localStorage assumptions)
15
- *
16
- * @param config - Simple auth configuration
17
- * @returns AuthProvider implementation
18
- */
19
- export function createAuthProvider(config: SimpleAuthConfig): PersAuthProvider {
20
- // Store current token for refresh scenarios and caching
21
- let currentToken: string | null = config.token || null;
22
- let isRefreshing = false; // Prevent concurrent refresh attempts
23
- let refreshPromise: Promise<void> | null = null;
24
-
25
- return {
26
- authType: config.authType || 'user',
27
-
28
- async getToken(): Promise<string | null> {
29
- // If currently refreshing, wait for it to complete
30
- if (isRefreshing && refreshPromise) {
31
- await refreshPromise;
32
- return currentToken;
33
- }
34
-
35
- // Use cached current token (updated after refresh)
36
- if (currentToken) {
37
- return currentToken;
38
- }
39
-
40
- // Custom token provider function (always fresh)
41
- if (config.tokenProvider) {
42
- const token = await config.tokenProvider();
43
- currentToken = token; // Cache for future calls
44
- return token;
45
- }
46
-
47
- // No token available
48
- return null;
49
- },
50
-
51
- async getProjectKey(): Promise<string | null> {
52
- return config.projectKey || null;
53
- },
54
-
55
- async onTokenExpired(): Promise<void> {
56
- // Prevent concurrent refresh attempts
57
- if (isRefreshing) {
58
- if (refreshPromise) {
59
- await refreshPromise;
60
- }
61
- return;
62
- }
63
-
64
- // No refresh logic provided
65
- if (!config.onTokenExpired) {
66
- console.warn('Token expired but no refresh logic provided');
67
- currentToken = null; // Clear expired token
68
- return;
69
- }
70
-
71
- // Start refresh process
72
- isRefreshing = true;
73
- refreshPromise = (async () => {
74
- try {
75
- // Execute refresh logic (should update token source)
76
- await config.onTokenExpired!();
77
-
78
- // After refresh, get the new token
79
- if (config.tokenProvider) {
80
- const newToken = await config.tokenProvider();
81
- if (newToken && newToken !== currentToken) {
82
- currentToken = newToken;
83
-
84
- // Notify about successful token refresh
85
- if (config.onTokenRefreshed) {
86
- config.onTokenRefreshed(newToken);
87
- }
88
- } else {
89
- console.warn('Token refresh completed but no new token received');
90
- currentToken = null;
91
- }
92
- } else {
93
- // For static token configs, clear the token since we can't refresh
94
- console.warn('Token expired for static token config - clearing token');
95
- currentToken = null;
96
- }
97
- } catch (error) {
98
- console.error('Token refresh failed:', error);
99
- currentToken = null; // Clear token on refresh failure
100
- throw error; // Re-throw to let SDK handle the error
101
- } finally {
102
- isRefreshing = false;
103
- refreshPromise = null;
104
- }
105
- })();
106
-
107
- await refreshPromise;
108
- }
109
- };
110
- }
111
-
112
- /**
113
- * Platform-specific localStorage token provider for browsers
114
- * This is a convenience function for browser environments
115
- */
116
- /* export function createBrowserTokenProvider(tokenKey: string = 'userJwt'): () => Promise<string | null> {
117
- return async () => {
118
- if (typeof localStorage !== 'undefined') {
119
- return localStorage.getItem(tokenKey);
120
- }
121
- return null;
122
- };
123
- } */
124
-
125
- /**
126
- * Platform-specific environment variable token provider for Node.js
127
- * This is a convenience function for Node.js environments
128
- */
129
- /* export function createNodeTokenProvider(envVar: string = 'JWT_TOKEN'): () => Promise<string | null> {
130
- return async () => {
131
- if (typeof process !== 'undefined' && process.env) {
132
- return process.env[envVar] || null;
133
- }
134
- return null;
135
- };
136
- } */
@@ -1,15 +0,0 @@
1
- /**
2
- * Simple Auth Configuration Interface - Dev-Friendly Alternative
3
- *
4
- * Instead of implementing AuthProvider, developers can use this simple config
5
- * which will be automatically converted to a full AuthProvider implementation.
6
- */
7
- export interface SimpleAuthConfig {
8
- authType?: 'admin' | 'user' | 'firebase';
9
- token?: string;
10
- tokenProvider?: () => Promise<string | null>;
11
- projectKey?: string;
12
- onTokenExpired?: () => Promise<void>;
13
- // Advanced: for reactive token updates after refresh
14
- onTokenRefreshed?: (newToken: string) => void;
15
- }
package/src/core/index.ts DELETED
@@ -1,33 +0,0 @@
1
- /**
2
- * @explorins/pers-sdk/core - Core SDK Entry Point
3
- *
4
- * Platform-agnostic PERS API client and core functionality
5
- */
6
-
7
- // Core PERS API client
8
- export * from './pers-api-client';
9
-
10
- // Configuration interfaces and types
11
- export * from './pers-config';
12
- export type { PersEnvironment, PersApiVersion } from './pers-config';
13
-
14
- // Authentication interfaces
15
- export {
16
- PersAuthProvider,
17
- SimpleAuthConfig,
18
- createAuthProvider,
19
- /* createBrowserTokenProvider,
20
- createNodeTokenProvider */
21
- } from './auth/auth-provider.interface';
22
-
23
- // Add compatibility alias for Angular package
24
- // export { PersAuthProvider as AuthProvider } from './auth/auth-provider.interface';
25
-
26
- export type { PersRequestOptions as AuthRequestOptions } from './auth/auth-provider.interface';
27
-
28
- // Platform abstractions
29
- export * from './abstractions/http-client';
30
-
31
- // Main SDK class
32
- export { PersSDK, createPersSDK } from '../pers-sdk';
33
-
@@ -1,343 +0,0 @@
1
- // packages/pers-sdk/src/core/pers-api-client.ts
2
- /**
3
- * PERS API Client - Core platform-agnostic client for PERS backend
4
- */
5
-
6
- import { HttpClient, RequestOptions } from './abstractions/http-client';
7
- import { PersConfig, buildApiRoot, mergeWithDefaults } from './pers-config';
8
-
9
- export class PersApiClient {
10
- private readonly apiRoot: string;
11
- private readonly mergedConfig: ReturnType<typeof mergeWithDefaults>;
12
-
13
- constructor(
14
- private httpClient: HttpClient,
15
- private config: PersConfig
16
- ) {
17
- // Merge user config with defaults (production + v2)
18
- this.mergedConfig = mergeWithDefaults(config);
19
-
20
- // Build API root from merged environment and version
21
- this.apiRoot = buildApiRoot(this.mergedConfig.environment, this.mergedConfig.apiVersion);
22
- }
23
-
24
- /**
25
- * Get request headers including auth token and project key
26
- */
27
- private async getHeaders(): Promise<Record<string, string>> {
28
- const headers: Record<string, string> = {
29
- 'Content-Type': 'application/json',
30
- };
31
-
32
- // Add authentication token
33
- if (this.mergedConfig.authProvider) {
34
- const token = await this.mergedConfig.authProvider.getToken();
35
- if (token) {
36
- headers['Authorization'] = `Bearer ${token}`;
37
- }
38
- }
39
-
40
- // Add project key
41
- if (this.mergedConfig.authProvider) {
42
- const projectKey = await this.mergedConfig.authProvider.getProjectKey();
43
- if (projectKey) {
44
- headers['x-project-key'] = projectKey;
45
- }
46
- } else if(this.mergedConfig.apiProjectKey) {
47
- // Fallback to config project key if no auth provider
48
- headers['x-project-key'] = this.mergedConfig.apiProjectKey;
49
- }
50
-
51
- return headers;
52
- }
53
-
54
- /**
55
- * Make a request with proper headers, auth, and error handling
56
- */
57
- private async request<T>(
58
- method: 'GET' | 'POST' | 'PUT' | 'DELETE',
59
- endpoint: string,
60
- body?: unknown,
61
- options?: { retryCount?: number; responseType?: 'json' | 'blob' | 'text' | 'arraybuffer' }
62
- ): Promise<T> {
63
- const { retryCount = 0, responseType = 'json' } = options || {};
64
- const url = `${this.apiRoot}${endpoint}`;
65
-
66
- // ✅ DEBUGGING: Add extensive logging for CSV endpoint
67
- const isCSVEndpoint = endpoint.includes('/export/csv');
68
-
69
- const requestOptions: RequestOptions = {
70
- headers: await this.getHeaders(),
71
- timeout: this.mergedConfig.timeout,
72
- responseType
73
- };
74
-
75
- try {
76
- let result: T;
77
-
78
- switch (method) {
79
- case 'GET':
80
- result = await this.httpClient.get<T>(url, requestOptions);
81
- break;
82
- case 'POST':
83
- result = await this.httpClient.post<T>(url, body, requestOptions);
84
- break;
85
- case 'PUT':
86
- result = await this.httpClient.put<T>(url, body, requestOptions);
87
- break;
88
- case 'DELETE':
89
- result = await this.httpClient.delete<T>(url, requestOptions);
90
- break;
91
- default:
92
- throw new Error(`Unsupported HTTP method: ${method}`);
93
- }
94
-
95
- return result;
96
- } catch (error: unknown) {
97
- if (isCSVEndpoint) {
98
- console.error('❌ [PERS API CLIENT] CSV Request failed:', error);
99
- }
100
-
101
- // Handle 401 errors with automatic token refresh
102
- const apiError = error as { status?: number; message?: string };
103
-
104
- if (apiError.status === 401 && retryCount === 0 && this.mergedConfig.authProvider?.onTokenExpired) {
105
- try {
106
- await this.mergedConfig.authProvider.onTokenExpired();
107
- // Retry once with refreshed token
108
- return this.request<T>(method, endpoint, body, { ...options, retryCount: 1 });
109
- } catch (refreshError) {
110
- throw new PersApiError(
111
- `Authentication refresh failed: ${refreshError}`,
112
- endpoint,
113
- method,
114
- 401
115
- );
116
- }
117
- }
118
-
119
- throw new PersApiError(
120
- `PERS API request failed: ${apiError.message || error}`,
121
- endpoint,
122
- method,
123
- apiError.status
124
- );
125
- }
126
- }
127
-
128
- /**
129
- * Generic GET request
130
- */
131
- async get<T>(endpoint: string, responseType?: 'json' | 'blob' | 'text' | 'arraybuffer'): Promise<T> {
132
- return this.request<T>('GET', endpoint, undefined, { responseType });
133
- }
134
-
135
- /**
136
- * Generic POST request
137
- */
138
- async post<T>(endpoint: string, body?: unknown): Promise<T> {
139
- return this.request<T>('POST', endpoint, body);
140
- }
141
-
142
- /**
143
- * Generic PUT request
144
- */
145
- async put<T>(endpoint: string, body?: unknown): Promise<T> {
146
- return this.request<T>('PUT', endpoint, body);
147
- }
148
-
149
- /**
150
- * Generic DELETE request
151
- */
152
- async delete<T>(endpoint: string): Promise<T> {
153
- return this.request<T>('DELETE', endpoint);
154
- }
155
-
156
- /**
157
- * Get current configuration (returns merged config)
158
- */
159
- getConfig(): ReturnType<typeof mergeWithDefaults> {
160
- return this.mergedConfig;
161
- }
162
-
163
- /**
164
- * Get original user configuration
165
- */
166
- getOriginalConfig(): PersConfig {
167
- return this.config;
168
- }
169
- }
170
-
171
- export class PersApiError extends Error {
172
- constructor(
173
- message: string,
174
- public endpoint: string,
175
- public method: string,
176
- public statusCode?: number
177
- ) {
178
- super(message);
179
- this.name = 'PersApiError';
180
- }
181
- }
182
- /**
183
- * PERS API Client - Core platform-agnostic client for PERS backend
184
- */
185
-
186
- /*import { HttpClient, RequestOptions } from './abstractions/http-client';
187
- import { PersConfig, buildApiRoot, mergeWithDefaults } from './pers-config';
188
-
189
- export class PersApiClient {
190
- private readonly apiRoot: string;
191
- private readonly mergedConfig: ReturnType<typeof mergeWithDefaults>;
192
-
193
- constructor(
194
- private httpClient: HttpClient,
195
- private config: PersConfig
196
- ) {
197
- // Merge user config with defaults (production + v2)
198
- this.mergedConfig = mergeWithDefaults(config);
199
-
200
- // Build API root from merged environment and version
201
- this.apiRoot = buildApiRoot(this.mergedConfig.environment, this.mergedConfig.apiVersion);
202
- }
203
-
204
- /**
205
- * Get request headers including auth token and project key
206
- */
207
- /*private async getHeaders(): Promise<Record<string, string>> {
208
- const headers: Record<string, string> = {
209
- 'Content-Type': 'application/json',
210
- };
211
-
212
- // Add authentication token
213
- if (this.mergedConfig.authProvider) {
214
- const token = await this.mergedConfig.authProvider.getToken();
215
- if (token) {
216
- headers['Authorization'] = `Bearer ${token}`;
217
- }
218
- }
219
-
220
- // Add project key
221
- if (this.mergedConfig.authProvider) {
222
- const projectKey = await this.mergedConfig.authProvider.getProjectKey();
223
- if (projectKey) {
224
- headers['x-project-key'] = projectKey;
225
- }
226
- } else if(this.mergedConfig.apiProjectKey) {
227
- // Fallback to config project key if no auth provider
228
- headers['x-project-key'] = this.mergedConfig.apiProjectKey;
229
- }
230
-
231
- return headers;
232
- }
233
-
234
- /**
235
- * Make a request with proper headers, auth, and error handling
236
- */
237
- /*private async request<T>(
238
- method: 'GET' | 'POST' | 'PUT' | 'DELETE',
239
- endpoint: string,
240
- body?: any,
241
- options?: { retryCount?: number }
242
- ): Promise<T> {
243
- const { retryCount = 0 } = options || {};
244
- const url = `${this.apiRoot}${endpoint}`;
245
-
246
- const requestOptions: RequestOptions = {
247
- headers: await this.getHeaders(),
248
- timeout: this.mergedConfig.timeout,
249
- };
250
-
251
- try {
252
- switch (method) {
253
- case 'GET':
254
- return await this.httpClient.get<T>(url, requestOptions);
255
- case 'POST':
256
- return await this.httpClient.post<T>(url, body, requestOptions);
257
- case 'PUT':
258
- return await this.httpClient.put<T>(url, body, requestOptions);
259
- case 'DELETE':
260
- return await this.httpClient.delete<T>(url, requestOptions);
261
- default:
262
- throw new Error(`Unsupported HTTP method: ${method}`);
263
- }
264
- } catch (error: any) {
265
- // Handle 401 errors with automatic token refresh
266
- if (error.status === 401 && retryCount === 0 && this.mergedConfig.authProvider?.onTokenExpired) {
267
- try {
268
- await this.mergedConfig.authProvider.onTokenExpired();
269
- // Retry once with refreshed token
270
- return this.request<T>(method, endpoint, body, { ...options, retryCount: 1 });
271
- } catch (refreshError) {
272
- throw new PersApiError(
273
- `Authentication refresh failed: ${refreshError}`,
274
- endpoint,
275
- method,
276
- 401
277
- );
278
- }
279
- }
280
-
281
- throw new PersApiError(
282
- `PERS API request failed: ${error.message || error}`,
283
- endpoint,
284
- method,
285
- error.status
286
- );
287
- }
288
- }
289
-
290
- /**
291
- * Generic GET request
292
- */
293
- /*async get<T>(endpoint: string): Promise<T> {
294
- return this.request<T>('GET', endpoint);
295
- }
296
-
297
- /**
298
- * Generic POST request
299
- */
300
- /*async post<T>(endpoint: string, body?: any): Promise<T> {
301
- return this.request<T>('POST', endpoint, body);
302
- }
303
-
304
- /**
305
- * Generic PUT request
306
- */
307
- /*async put<T>(endpoint: string, body?: any): Promise<T> {
308
- return this.request<T>('PUT', endpoint, body);
309
- }
310
-
311
- /**
312
- * Generic DELETE request
313
- */
314
- /*async delete<T>(endpoint: string): Promise<T> {
315
- return this.request<T>('DELETE', endpoint);
316
- }
317
-
318
- /**
319
- * Get current configuration (returns merged config)
320
- */
321
- /*getConfig(): ReturnType<typeof mergeWithDefaults> {
322
- return this.mergedConfig;
323
- }
324
-
325
- /**
326
- * Get original user configuration
327
- */
328
- /*getOriginalConfig(): PersConfig {
329
- return this.config;
330
- }
331
- }
332
-
333
- export class PersApiError extends Error {
334
- constructor(
335
- message: string,
336
- public endpoint: string,
337
- public method: string,
338
- public statusCode?: number
339
- ) {
340
- super(message);
341
- this.name = 'PersApiError';
342
- }
343
- }*/
@@ -1,65 +0,0 @@
1
- /**
2
- * PERS SDK Configuration interfaces
3
- */
4
-
5
- import { PersAuthProvider } from './auth/auth-provider.interface';
6
-
7
- export type PersEnvironment = 'development' | 'staging' | 'production';
8
- export type PersApiVersion = 'v1' | 'v1.8' | 'v1.9' | 'v2';
9
-
10
- export interface PersConfig {
11
- environment?: PersEnvironment;
12
- apiProjectKey?: string;
13
- apiVersion?: PersApiVersion;
14
- timeout?: number;
15
- retries?: number;
16
- authProvider?: PersAuthProvider;
17
- // Internal - constructed automatically
18
- readonly apiRoot?: string;
19
- }
20
-
21
- export interface PersAuthConfig {
22
- type: 'firebase' | 'jwt' | 'none';
23
- tokenProvider?: () => Promise<string | null>;
24
- }
25
-
26
- /**
27
- * Default configuration values
28
- */
29
- export const DEFAULT_PERS_CONFIG = {
30
- environment: 'production' as PersEnvironment,
31
- apiVersion: 'v2' as PersApiVersion,
32
- timeout: 30000,
33
- retries: 3
34
- } as const;
35
-
36
- /**
37
- * Internal function to construct API root from environment
38
- * Now defaults to production and v2
39
- */
40
- export function buildApiRoot(
41
- environment: PersEnvironment = 'production',
42
- version: PersApiVersion = 'v2'
43
- ): string {
44
- const baseUrls = {
45
- development: 'https://explorins-loyalty.ngrok.io',
46
- staging: `https://dev.api.pers.ninja/${version}`,
47
- production: `https://api.pers.ninja/${version}`
48
- };
49
-
50
- return `${baseUrls[environment]}`;
51
- }
52
-
53
- /**
54
- * Merge user config with defaults
55
- */
56
- export function mergeWithDefaults(config: PersConfig): PersConfig & Required<Pick<PersConfig, 'environment' | 'apiVersion' | 'timeout' | 'retries'>> {
57
- return {
58
- ...DEFAULT_PERS_CONFIG,
59
- ...config,
60
- environment: config.environment ?? DEFAULT_PERS_CONFIG.environment,
61
- apiVersion: config.apiVersion ?? DEFAULT_PERS_CONFIG.apiVersion,
62
- timeout: config.timeout ?? DEFAULT_PERS_CONFIG.timeout,
63
- retries: config.retries ?? DEFAULT_PERS_CONFIG.retries
64
- };
65
- }
@@ -1,24 +0,0 @@
1
- import { jwtDecode } from "jwt-decode";
2
-
3
-
4
- export const isTokenExpired = (token: string, margin: number = 60): boolean => {
5
- // ✅ SANITIZE: Remove any words (Bearer etc) if exists and get the token
6
- const cleanToken = token.split(' ')[1] || token;
7
-
8
- // ✅ VALIDATION: Check if token is jwt
9
- if (!cleanToken || cleanToken.split('.').length !== 3) {
10
- return true; // Consider invalid tokens as expired
11
- }
12
-
13
- try {
14
- // ✅ TYPE-SAFE: Decode with proper typing
15
- const decoded: any = jwtDecode(cleanToken);
16
- const currentTime = Math.floor(Date.now() / 1000);
17
-
18
- // ✅ CONFIGURABLE: Use provided margin (default 60 seconds)
19
- return decoded.exp < (currentTime + margin);
20
- } catch (error) {
21
- console.error('[SDK JWT Utils] Error decoding JWT token:', error);
22
- return true; // Consider unparseable tokens as expired
23
- }
24
- };
@@ -1,24 +0,0 @@
1
- import { PersApiClient } from '../../core/pers-api-client';
2
- import { DonationTypeDTO } from '../../shared/interfaces/pers-shared-lib.interfaces';
3
-
4
- /**
5
- * Platform-Agnostic Donation API Client
6
- *
7
- * Handles donation operations using the PERS backend.
8
- * Matches framework DonationApiService methods exactly.
9
- */
10
- export class DonationApi {
11
- constructor(private apiClient: PersApiClient) {}
12
-
13
- // ==========================================
14
- // PUBLIC OPERATIONS
15
- // ==========================================
16
-
17
- /**
18
- * PUBLIC: Get all donation types
19
- * ✅ ONLY method actually used by framework
20
- */
21
- async getAllDonationTypes(): Promise<DonationTypeDTO[]> {
22
- return this.apiClient.get<DonationTypeDTO[]>('/purchase/donation/type');
23
- }
24
- }
@@ -1,47 +0,0 @@
1
- /**
2
- * @explorins/pers-sdk-donation
3
- *
4
- * Platform-agnostic Donation Domain SDK for PERS ecosystem
5
- * Handles donation type retrieval for purchase flow integration
6
- */
7
-
8
- // API Layer
9
- export { DonationApi } from './api/donation-api';
10
-
11
- // Service Layer
12
- export { DonationService } from './services/donation-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 donation SDK instance
20
- import { PersApiClient } from '../core/pers-api-client';
21
- import { DonationApi } from './api/donation-api';
22
- import { DonationService } from './services/donation-service';
23
-
24
- /**
25
- * Create a complete Donation SDK instance
26
- *
27
- * @param apiClient - Configured PERS API client
28
- * @returns Donation SDK with flattened structure for better DX
29
- */
30
- export function createDonationSDK(apiClient: PersApiClient) {
31
- const donationApi = new DonationApi(apiClient);
32
- const donationService = new DonationService(donationApi);
33
-
34
- return {
35
- // Direct access to service methods (primary interface)
36
- // ✅ FRAMEWORK ALIGNED: Only method actually used by framework
37
-
38
- // Public methods
39
- getAllDonationTypes: () => donationService.getAllDonationTypes(),
40
-
41
- // Advanced access for edge cases
42
- api: donationApi,
43
- service: donationService
44
- };
45
- }
46
-
47
- export type DonationSDK = ReturnType<typeof createDonationSDK>;