@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.
- package/dist/analytics/api/analytics-api.d.ts +17 -0
- package/dist/analytics/api/analytics-api.d.ts.map +1 -0
- package/{src/analytics/index.ts → dist/analytics/index.d.ts} +28 -52
- package/dist/analytics/index.d.ts.map +1 -0
- package/dist/analytics/models/index.d.ts +61 -0
- package/dist/analytics/models/index.d.ts.map +1 -0
- package/dist/analytics/services/analytics-service.d.ts +19 -0
- package/dist/analytics/services/analytics-service.d.ts.map +1 -0
- package/dist/analytics.cjs +76 -0
- package/dist/analytics.cjs.map +1 -0
- package/dist/analytics.d.ts +28 -0
- package/dist/analytics.js +72 -0
- package/dist/analytics.js.map +1 -0
- package/dist/auth-admin/api/auth-admin-api.d.ts +27 -0
- package/dist/auth-admin/api/auth-admin-api.d.ts.map +1 -0
- package/dist/auth-admin/index.d.ts +26 -0
- package/dist/auth-admin/index.d.ts.map +1 -0
- package/dist/auth-admin/services/auth-admin-service.d.ts +23 -0
- package/dist/auth-admin/services/auth-admin-service.d.ts.map +1 -0
- package/dist/auth-admin.cjs +96 -0
- package/dist/auth-admin.cjs.map +1 -0
- package/dist/auth-admin.d.ts +26 -0
- package/dist/auth-admin.js +92 -0
- package/dist/auth-admin.js.map +1 -0
- package/dist/business/api/business-api.d.ts +133 -0
- package/dist/business/api/business-api.d.ts.map +1 -0
- package/dist/business/index.d.ts +34 -0
- package/dist/business/index.d.ts.map +1 -0
- package/dist/business/models/index.d.ts +8 -0
- package/dist/business/models/index.d.ts.map +1 -0
- package/dist/business/services/business-service.d.ts +51 -0
- package/dist/business/services/business-service.d.ts.map +1 -0
- package/dist/business.cjs +303 -0
- package/dist/business.cjs.map +1 -0
- package/dist/business.d.ts +34 -0
- package/dist/business.js +299 -0
- package/dist/business.js.map +1 -0
- package/dist/campaign/api/campaign-api.d.ts +213 -0
- package/dist/campaign/api/campaign-api.d.ts.map +1 -0
- package/dist/campaign/index.d.ts +44 -0
- package/dist/campaign/index.d.ts.map +1 -0
- package/dist/campaign/services/campaign-service.d.ts +88 -0
- package/dist/campaign/services/campaign-service.d.ts.map +1 -0
- package/dist/campaign.cjs +506 -0
- package/dist/campaign.cjs.map +1 -0
- package/dist/campaign.d.ts +44 -0
- package/dist/campaign.js +502 -0
- package/dist/campaign.js.map +1 -0
- package/dist/core/abstractions/http-client.d.ts +22 -0
- package/dist/core/abstractions/http-client.d.ts.map +1 -0
- package/dist/core/auth/auth-provider.interface.d.ts +12 -0
- package/dist/core/auth/auth-provider.interface.d.ts.map +1 -0
- package/dist/core/auth/create-auth-provider.d.ts +27 -0
- package/dist/core/auth/create-auth-provider.d.ts.map +1 -0
- package/dist/core/auth/simple-auth-config.interface.d.ts +15 -0
- package/dist/core/auth/simple-auth-config.interface.d.ts.map +1 -0
- package/dist/core/index.d.ts +13 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/pers-api-client.d.ts +54 -0
- package/dist/core/pers-api-client.d.ts.map +1 -0
- package/dist/core/pers-config.d.ts +38 -0
- package/dist/core/pers-config.d.ts.map +1 -0
- package/dist/core/utils/jwt.function.d.ts +2 -0
- package/dist/core/utils/jwt.function.d.ts.map +1 -0
- package/dist/core.cjs +506 -0
- package/dist/core.cjs.map +1 -0
- package/dist/core.d.ts +13 -0
- package/dist/core.js +497 -0
- package/dist/core.js.map +1 -0
- package/dist/donation/api/donation-api.d.ts +18 -0
- package/dist/donation/api/donation-api.d.ts.map +1 -0
- package/dist/donation/index.d.ts +25 -0
- package/dist/donation/index.d.ts.map +1 -0
- package/{src/donation/models/index.ts → dist/donation/models/index.d.ts} +8 -11
- package/dist/donation/models/index.d.ts.map +1 -0
- package/dist/donation/services/donation-service.d.ts +19 -0
- package/dist/donation/services/donation-service.d.ts.map +1 -0
- package/dist/donation.cjs +78 -0
- package/dist/donation.cjs.map +1 -0
- package/dist/donation.d.ts +25 -0
- package/dist/donation.js +74 -0
- package/dist/donation.js.map +1 -0
- package/dist/index.cjs +4217 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4164 -0
- package/dist/index.js.map +1 -0
- package/dist/package.json +148 -0
- package/dist/payment/api/payment-api.d.ts +105 -0
- package/dist/payment/api/payment-api.d.ts.map +1 -0
- package/dist/payment/index.d.ts +36 -0
- package/dist/payment/index.d.ts.map +1 -0
- package/dist/payment/models/index.d.ts +12 -0
- package/dist/payment/models/index.d.ts.map +1 -0
- package/dist/payment/services/payment-service.d.ts +40 -0
- package/dist/payment/services/payment-service.d.ts.map +1 -0
- package/dist/payment.cjs +258 -0
- package/dist/payment.cjs.map +1 -0
- package/dist/payment.d.ts +36 -0
- package/dist/payment.js +254 -0
- package/dist/payment.js.map +1 -0
- package/dist/pers-sdk.d.ts +29 -0
- package/dist/pers-sdk.d.ts.map +1 -0
- package/dist/redemption/api/redemption-api.d.ts +147 -0
- package/dist/redemption/api/redemption-api.d.ts.map +1 -0
- package/dist/redemption/index.d.ts +35 -0
- package/dist/redemption/index.d.ts.map +1 -0
- package/dist/redemption/models/index.d.ts +8 -0
- package/dist/redemption/models/index.d.ts.map +1 -0
- package/dist/redemption/services/redemption-service.d.ts +56 -0
- package/dist/redemption/services/redemption-service.d.ts.map +1 -0
- package/dist/redemption.cjs +333 -0
- package/dist/redemption.cjs.map +1 -0
- package/dist/redemption.d.ts +35 -0
- package/dist/redemption.js +329 -0
- package/dist/redemption.js.map +1 -0
- package/dist/shared/interfaces/pers-shared-lib.interfaces.d.ts +18 -0
- package/dist/shared/interfaces/pers-shared-lib.interfaces.d.ts.map +1 -0
- package/dist/tenant/api/tenant-api.d.ts +56 -0
- package/dist/tenant/api/tenant-api.d.ts.map +1 -0
- package/dist/tenant/index.d.ts +34 -0
- package/dist/tenant/index.d.ts.map +1 -0
- package/dist/tenant/models/index.d.ts +11 -0
- package/dist/tenant/models/index.d.ts.map +1 -0
- package/dist/tenant/services/tenant-service.d.ts +46 -0
- package/dist/tenant/services/tenant-service.d.ts.map +1 -0
- package/dist/tenant.cjs +177 -0
- package/dist/tenant.cjs.map +1 -0
- package/dist/tenant.d.ts +34 -0
- package/dist/tenant.js +173 -0
- package/dist/tenant.js.map +1 -0
- package/dist/token/api/token-api.d.ts +64 -0
- package/dist/token/api/token-api.d.ts.map +1 -0
- package/dist/token/base/base-token-service.d.ts +87 -0
- package/dist/token/base/base-token-service.d.ts.map +1 -0
- package/dist/token/index.d.ts +13 -0
- package/dist/token/index.d.ts.map +1 -0
- package/dist/token/models/index.d.ts +18 -0
- package/dist/token/models/index.d.ts.map +1 -0
- package/dist/token/services/token-service.d.ts +68 -0
- package/dist/token/services/token-service.d.ts.map +1 -0
- package/dist/token/token-sdk.d.ts +140 -0
- package/dist/token/token-sdk.d.ts.map +1 -0
- package/dist/token.cjs +537 -0
- package/dist/token.cjs.map +1 -0
- package/dist/token.d.ts +13 -0
- package/dist/token.js +532 -0
- package/dist/token.js.map +1 -0
- package/dist/transaction/api/transaction-api.d.ts +133 -0
- package/dist/transaction/api/transaction-api.d.ts.map +1 -0
- package/dist/transaction/index.d.ts +38 -0
- package/dist/transaction/index.d.ts.map +1 -0
- package/dist/transaction/models/index.d.ts +42 -0
- package/dist/transaction/models/index.d.ts.map +1 -0
- package/dist/transaction/services/transaction-service.d.ts +56 -0
- package/dist/transaction/services/transaction-service.d.ts.map +1 -0
- package/dist/transaction.cjs +394 -0
- package/dist/transaction.cjs.map +1 -0
- package/dist/transaction.d.ts +38 -0
- package/dist/transaction.js +390 -0
- package/dist/transaction.js.map +1 -0
- package/dist/user/api/user-api.d.ts +56 -0
- package/dist/user/api/user-api.d.ts.map +1 -0
- package/dist/user/index.d.ts +36 -0
- package/dist/user/index.d.ts.map +1 -0
- package/{src/user/models/index.ts → dist/user/models/index.d.ts} +12 -10
- package/dist/user/models/index.d.ts.map +1 -0
- package/dist/user/services/user-service.d.ts +46 -0
- package/dist/user/services/user-service.d.ts.map +1 -0
- package/dist/user-status/api/user-status-api.d.ts +37 -0
- package/dist/user-status/api/user-status-api.d.ts.map +1 -0
- package/dist/user-status/index.d.ts +28 -0
- package/dist/user-status/index.d.ts.map +1 -0
- package/{src/user-status/models/index.ts → dist/user-status/models/index.d.ts} +8 -11
- package/dist/user-status/models/index.d.ts.map +1 -0
- package/dist/user-status/services/user-status-service.d.ts +26 -0
- package/dist/user-status/services/user-status-service.d.ts.map +1 -0
- package/dist/user-status.cjs +147 -0
- package/dist/user-status.cjs.map +1 -0
- package/dist/user-status.d.ts +28 -0
- package/dist/user-status.js +143 -0
- package/dist/user-status.js.map +1 -0
- package/dist/user.cjs +188 -0
- package/dist/user.cjs.map +1 -0
- package/dist/user.d.ts +36 -0
- package/dist/user.js +184 -0
- package/dist/user.js.map +1 -0
- package/dist/web3/api/web3-api.d.ts +27 -0
- package/dist/web3/api/web3-api.d.ts.map +1 -0
- package/dist/web3/index.d.ts +16 -0
- package/dist/web3/index.d.ts.map +1 -0
- package/dist/web3/models/index.d.ts +92 -0
- package/dist/web3/models/index.d.ts.map +1 -0
- package/dist/web3/services/web3-service.d.ts +21 -0
- package/dist/web3/services/web3-service.d.ts.map +1 -0
- package/dist/web3-chain/api/web3-chain-api.d.ts +19 -0
- package/dist/web3-chain/api/web3-chain-api.d.ts.map +1 -0
- package/dist/web3-chain/index.d.ts +17 -0
- package/dist/web3-chain/index.d.ts.map +1 -0
- package/{src/web3-chain/models/index.ts → dist/web3-chain/models/index.d.ts} +38 -45
- package/dist/web3-chain/models/index.d.ts.map +1 -0
- package/dist/web3-chain/services/getWeb3FCD.service.d.ts +8 -0
- package/dist/web3-chain/services/getWeb3FCD.service.d.ts.map +1 -0
- package/dist/web3-chain/services/provider.service.d.ts +15 -0
- package/dist/web3-chain/services/provider.service.d.ts.map +1 -0
- package/dist/web3-chain/services/public-http-provider.service.d.ts +8 -0
- package/dist/web3-chain/services/public-http-provider.service.d.ts.map +1 -0
- package/dist/web3-chain/services/web3-chain-service.d.ts +17 -0
- package/dist/web3-chain/services/web3-chain-service.d.ts.map +1 -0
- package/dist/web3-chain.cjs +316 -0
- package/dist/web3-chain.cjs.map +1 -0
- package/dist/web3-chain.d.ts +17 -0
- package/dist/web3-chain.js +310 -0
- package/dist/web3-chain.js.map +1 -0
- package/dist/web3.cjs +516 -0
- package/dist/web3.cjs.map +1 -0
- package/dist/web3.d.ts +16 -0
- package/dist/web3.js +513 -0
- package/dist/web3.js.map +1 -0
- package/package.json +70 -67
- package/config/domains.js +0 -22
- package/explorins-pers-sdk-1.0.0-alpha.1.tgz +0 -0
- package/rollup.config.js +0 -74
- package/scripts/copy-declarations.js +0 -147
- package/src/analytics/api/analytics-api.ts +0 -24
- package/src/analytics/models/index.ts +0 -74
- package/src/analytics/services/analytics-service.ts +0 -28
- package/src/auth-admin/api/auth-admin-api.ts +0 -42
- package/src/auth-admin/index.ts +0 -47
- package/src/auth-admin/services/auth-admin-service.ts +0 -36
- package/src/business/api/business-api.ts +0 -234
- package/src/business/index.ts +0 -53
- package/src/business/models/index.ts +0 -13
- package/src/business/services/business-service.ts +0 -88
- package/src/campaign/api/campaign-api.ts +0 -376
- package/src/campaign/index.ts +0 -67
- package/src/campaign/services/campaign-service.ts +0 -164
- package/src/core/abstractions/http-client.ts +0 -24
- package/src/core/auth/auth-provider.interface.ts +0 -16
- package/src/core/auth/create-auth-provider.ts +0 -136
- package/src/core/auth/simple-auth-config.interface.ts +0 -15
- package/src/core/index.ts +0 -33
- package/src/core/pers-api-client.ts +0 -343
- package/src/core/pers-config.ts +0 -65
- package/src/core/utils/jwt.function.ts +0 -24
- package/src/donation/api/donation-api.ts +0 -24
- package/src/donation/index.ts +0 -47
- package/src/donation/services/donation-service.ts +0 -25
- package/src/index.ts +0 -55
- package/src/payment/api/payment-api.ts +0 -185
- package/src/payment/index.ts +0 -64
- package/src/payment/models/index.ts +0 -29
- package/src/payment/services/payment-service.ts +0 -70
- package/src/pers-sdk.ts +0 -45
- package/src/redemption/api/redemption-api.ts +0 -241
- package/src/redemption/index.ts +0 -60
- package/src/redemption/models/index.ts +0 -17
- package/src/redemption/services/redemption-service.ts +0 -103
- package/src/shared/interfaces/pers-shared-lib.interfaces.ts +0 -99
- package/src/tenant/api/tenant-api.ts +0 -92
- package/src/tenant/index.ts +0 -61
- package/src/tenant/models/index.ts +0 -20
- package/src/tenant/services/tenant-service.ts +0 -78
- package/src/token/api/token-api.ts +0 -129
- package/src/token/base/base-token-service.ts +0 -167
- package/src/token/index.ts +0 -38
- package/src/token/models/index.ts +0 -30
- package/src/token/services/token-service.ts +0 -125
- package/src/token/token-sdk.ts +0 -231
- package/src/transaction/api/transaction-api.ts +0 -296
- package/src/transaction/index.ts +0 -65
- package/src/transaction/models/index.ts +0 -60
- package/src/transaction/services/transaction-service.ts +0 -104
- package/src/user/api/user-api.ts +0 -98
- package/src/user/index.ts +0 -62
- package/src/user/services/user-service.ts +0 -75
- package/src/user-status/api/user-status-api.ts +0 -78
- package/src/user-status/index.ts +0 -55
- package/src/user-status/services/user-status-service.ts +0 -51
- package/src/web3/api/web3-api.ts +0 -68
- package/src/web3/index.ts +0 -38
- package/src/web3/models/index.ts +0 -150
- package/src/web3/services/web3-service.ts +0 -338
- package/src/web3-chain/api/web3-chain-api.ts +0 -42
- package/src/web3-chain/index.ts +0 -27
- package/src/web3-chain/services/getWeb3FCD.service.ts +0 -47
- package/src/web3-chain/services/provider.service.ts +0 -123
- package/src/web3-chain/services/public-http-provider.service.ts +0 -26
- package/src/web3-chain/services/web3-chain-service.ts +0 -131
- 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
|
-
}*/
|
package/src/core/pers-config.ts
DELETED
|
@@ -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
|
-
}
|
package/src/donation/index.ts
DELETED
|
@@ -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>;
|