@explorins/pers-sdk 1.1.2 → 1.2.0
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.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.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.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.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.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.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 +129 -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.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.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.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.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.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.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.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.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.js +513 -0
- package/dist/web3.js.map +1 -0
- package/package.json +56 -72
- 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
package/dist/core.js
ADDED
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PERS SDK Configuration interfaces
|
|
3
|
+
*/
|
|
4
|
+
/**
|
|
5
|
+
* Default configuration values
|
|
6
|
+
*/
|
|
7
|
+
const DEFAULT_PERS_CONFIG = {
|
|
8
|
+
environment: 'production',
|
|
9
|
+
apiVersion: 'v2',
|
|
10
|
+
timeout: 30000,
|
|
11
|
+
retries: 3
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Internal function to construct API root from environment
|
|
15
|
+
* Now defaults to production and v2
|
|
16
|
+
*/
|
|
17
|
+
function buildApiRoot(environment = 'production', version = 'v2') {
|
|
18
|
+
const baseUrls = {
|
|
19
|
+
development: 'https://explorins-loyalty.ngrok.io',
|
|
20
|
+
staging: `https://dev.api.pers.ninja/${version}`,
|
|
21
|
+
production: `https://api.pers.ninja/${version}`
|
|
22
|
+
};
|
|
23
|
+
return `${baseUrls[environment]}`;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Merge user config with defaults
|
|
27
|
+
*/
|
|
28
|
+
function mergeWithDefaults(config) {
|
|
29
|
+
return {
|
|
30
|
+
...DEFAULT_PERS_CONFIG,
|
|
31
|
+
...config,
|
|
32
|
+
environment: config.environment ?? DEFAULT_PERS_CONFIG.environment,
|
|
33
|
+
apiVersion: config.apiVersion ?? DEFAULT_PERS_CONFIG.apiVersion,
|
|
34
|
+
timeout: config.timeout ?? DEFAULT_PERS_CONFIG.timeout,
|
|
35
|
+
retries: config.retries ?? DEFAULT_PERS_CONFIG.retries
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// packages/pers-sdk/src/core/pers-api-client.ts
|
|
40
|
+
/**
|
|
41
|
+
* PERS API Client - Core platform-agnostic client for PERS backend
|
|
42
|
+
*/
|
|
43
|
+
class PersApiClient {
|
|
44
|
+
constructor(httpClient, config) {
|
|
45
|
+
this.httpClient = httpClient;
|
|
46
|
+
this.config = config;
|
|
47
|
+
// Merge user config with defaults (production + v2)
|
|
48
|
+
this.mergedConfig = mergeWithDefaults(config);
|
|
49
|
+
// Build API root from merged environment and version
|
|
50
|
+
this.apiRoot = buildApiRoot(this.mergedConfig.environment, this.mergedConfig.apiVersion);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get request headers including auth token and project key
|
|
54
|
+
*/
|
|
55
|
+
async getHeaders() {
|
|
56
|
+
const headers = {
|
|
57
|
+
'Content-Type': 'application/json',
|
|
58
|
+
};
|
|
59
|
+
// Add authentication token
|
|
60
|
+
if (this.mergedConfig.authProvider) {
|
|
61
|
+
const token = await this.mergedConfig.authProvider.getToken();
|
|
62
|
+
if (token) {
|
|
63
|
+
headers['Authorization'] = `Bearer ${token}`;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// Add project key
|
|
67
|
+
if (this.mergedConfig.authProvider) {
|
|
68
|
+
const projectKey = await this.mergedConfig.authProvider.getProjectKey();
|
|
69
|
+
if (projectKey) {
|
|
70
|
+
headers['x-project-key'] = projectKey;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else if (this.mergedConfig.apiProjectKey) {
|
|
74
|
+
// Fallback to config project key if no auth provider
|
|
75
|
+
headers['x-project-key'] = this.mergedConfig.apiProjectKey;
|
|
76
|
+
}
|
|
77
|
+
return headers;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Make a request with proper headers, auth, and error handling
|
|
81
|
+
*/
|
|
82
|
+
async request(method, endpoint, body, options) {
|
|
83
|
+
const { retryCount = 0, responseType = 'json' } = options || {};
|
|
84
|
+
const url = `${this.apiRoot}${endpoint}`;
|
|
85
|
+
// ✅ DEBUGGING: Add extensive logging for CSV endpoint
|
|
86
|
+
const isCSVEndpoint = endpoint.includes('/export/csv');
|
|
87
|
+
const requestOptions = {
|
|
88
|
+
headers: await this.getHeaders(),
|
|
89
|
+
timeout: this.mergedConfig.timeout,
|
|
90
|
+
responseType
|
|
91
|
+
};
|
|
92
|
+
try {
|
|
93
|
+
let result;
|
|
94
|
+
switch (method) {
|
|
95
|
+
case 'GET':
|
|
96
|
+
result = await this.httpClient.get(url, requestOptions);
|
|
97
|
+
break;
|
|
98
|
+
case 'POST':
|
|
99
|
+
result = await this.httpClient.post(url, body, requestOptions);
|
|
100
|
+
break;
|
|
101
|
+
case 'PUT':
|
|
102
|
+
result = await this.httpClient.put(url, body, requestOptions);
|
|
103
|
+
break;
|
|
104
|
+
case 'DELETE':
|
|
105
|
+
result = await this.httpClient.delete(url, requestOptions);
|
|
106
|
+
break;
|
|
107
|
+
default:
|
|
108
|
+
throw new Error(`Unsupported HTTP method: ${method}`);
|
|
109
|
+
}
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
catch (error) {
|
|
113
|
+
if (isCSVEndpoint) {
|
|
114
|
+
console.error('❌ [PERS API CLIENT] CSV Request failed:', error);
|
|
115
|
+
}
|
|
116
|
+
// Handle 401 errors with automatic token refresh
|
|
117
|
+
const apiError = error;
|
|
118
|
+
if (apiError.status === 401 && retryCount === 0 && this.mergedConfig.authProvider?.onTokenExpired) {
|
|
119
|
+
try {
|
|
120
|
+
await this.mergedConfig.authProvider.onTokenExpired();
|
|
121
|
+
// Retry once with refreshed token
|
|
122
|
+
return this.request(method, endpoint, body, { ...options, retryCount: 1 });
|
|
123
|
+
}
|
|
124
|
+
catch (refreshError) {
|
|
125
|
+
throw new PersApiError(`Authentication refresh failed: ${refreshError}`, endpoint, method, 401);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
throw new PersApiError(`PERS API request failed: ${apiError.message || error}`, endpoint, method, apiError.status);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Generic GET request
|
|
133
|
+
*/
|
|
134
|
+
async get(endpoint, responseType) {
|
|
135
|
+
return this.request('GET', endpoint, undefined, { responseType });
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Generic POST request
|
|
139
|
+
*/
|
|
140
|
+
async post(endpoint, body) {
|
|
141
|
+
return this.request('POST', endpoint, body);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Generic PUT request
|
|
145
|
+
*/
|
|
146
|
+
async put(endpoint, body) {
|
|
147
|
+
return this.request('PUT', endpoint, body);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Generic DELETE request
|
|
151
|
+
*/
|
|
152
|
+
async delete(endpoint) {
|
|
153
|
+
return this.request('DELETE', endpoint);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Get current configuration (returns merged config)
|
|
157
|
+
*/
|
|
158
|
+
getConfig() {
|
|
159
|
+
return this.mergedConfig;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Get original user configuration
|
|
163
|
+
*/
|
|
164
|
+
getOriginalConfig() {
|
|
165
|
+
return this.config;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
class PersApiError extends Error {
|
|
169
|
+
constructor(message, endpoint, method, statusCode) {
|
|
170
|
+
super(message);
|
|
171
|
+
this.endpoint = endpoint;
|
|
172
|
+
this.method = method;
|
|
173
|
+
this.statusCode = statusCode;
|
|
174
|
+
this.name = 'PersApiError';
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* PERS API Client - Core platform-agnostic client for PERS backend
|
|
179
|
+
*/
|
|
180
|
+
/*import { HttpClient, RequestOptions } from './abstractions/http-client';
|
|
181
|
+
import { PersConfig, buildApiRoot, mergeWithDefaults } from './pers-config';
|
|
182
|
+
|
|
183
|
+
export class PersApiClient {
|
|
184
|
+
private readonly apiRoot: string;
|
|
185
|
+
private readonly mergedConfig: ReturnType<typeof mergeWithDefaults>;
|
|
186
|
+
|
|
187
|
+
constructor(
|
|
188
|
+
private httpClient: HttpClient,
|
|
189
|
+
private config: PersConfig
|
|
190
|
+
) {
|
|
191
|
+
// Merge user config with defaults (production + v2)
|
|
192
|
+
this.mergedConfig = mergeWithDefaults(config);
|
|
193
|
+
|
|
194
|
+
// Build API root from merged environment and version
|
|
195
|
+
this.apiRoot = buildApiRoot(this.mergedConfig.environment, this.mergedConfig.apiVersion);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Get request headers including auth token and project key
|
|
200
|
+
*/
|
|
201
|
+
/*private async getHeaders(): Promise<Record<string, string>> {
|
|
202
|
+
const headers: Record<string, string> = {
|
|
203
|
+
'Content-Type': 'application/json',
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
// Add authentication token
|
|
207
|
+
if (this.mergedConfig.authProvider) {
|
|
208
|
+
const token = await this.mergedConfig.authProvider.getToken();
|
|
209
|
+
if (token) {
|
|
210
|
+
headers['Authorization'] = `Bearer ${token}`;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
// Add project key
|
|
215
|
+
if (this.mergedConfig.authProvider) {
|
|
216
|
+
const projectKey = await this.mergedConfig.authProvider.getProjectKey();
|
|
217
|
+
if (projectKey) {
|
|
218
|
+
headers['x-project-key'] = projectKey;
|
|
219
|
+
}
|
|
220
|
+
} else if(this.mergedConfig.apiProjectKey) {
|
|
221
|
+
// Fallback to config project key if no auth provider
|
|
222
|
+
headers['x-project-key'] = this.mergedConfig.apiProjectKey;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
return headers;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Make a request with proper headers, auth, and error handling
|
|
230
|
+
*/
|
|
231
|
+
/*private async request<T>(
|
|
232
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE',
|
|
233
|
+
endpoint: string,
|
|
234
|
+
body?: any,
|
|
235
|
+
options?: { retryCount?: number }
|
|
236
|
+
): Promise<T> {
|
|
237
|
+
const { retryCount = 0 } = options || {};
|
|
238
|
+
const url = `${this.apiRoot}${endpoint}`;
|
|
239
|
+
|
|
240
|
+
const requestOptions: RequestOptions = {
|
|
241
|
+
headers: await this.getHeaders(),
|
|
242
|
+
timeout: this.mergedConfig.timeout,
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
try {
|
|
246
|
+
switch (method) {
|
|
247
|
+
case 'GET':
|
|
248
|
+
return await this.httpClient.get<T>(url, requestOptions);
|
|
249
|
+
case 'POST':
|
|
250
|
+
return await this.httpClient.post<T>(url, body, requestOptions);
|
|
251
|
+
case 'PUT':
|
|
252
|
+
return await this.httpClient.put<T>(url, body, requestOptions);
|
|
253
|
+
case 'DELETE':
|
|
254
|
+
return await this.httpClient.delete<T>(url, requestOptions);
|
|
255
|
+
default:
|
|
256
|
+
throw new Error(`Unsupported HTTP method: ${method}`);
|
|
257
|
+
}
|
|
258
|
+
} catch (error: any) {
|
|
259
|
+
// Handle 401 errors with automatic token refresh
|
|
260
|
+
if (error.status === 401 && retryCount === 0 && this.mergedConfig.authProvider?.onTokenExpired) {
|
|
261
|
+
try {
|
|
262
|
+
await this.mergedConfig.authProvider.onTokenExpired();
|
|
263
|
+
// Retry once with refreshed token
|
|
264
|
+
return this.request<T>(method, endpoint, body, { ...options, retryCount: 1 });
|
|
265
|
+
} catch (refreshError) {
|
|
266
|
+
throw new PersApiError(
|
|
267
|
+
`Authentication refresh failed: ${refreshError}`,
|
|
268
|
+
endpoint,
|
|
269
|
+
method,
|
|
270
|
+
401
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
throw new PersApiError(
|
|
276
|
+
`PERS API request failed: ${error.message || error}`,
|
|
277
|
+
endpoint,
|
|
278
|
+
method,
|
|
279
|
+
error.status
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* Generic GET request
|
|
286
|
+
*/
|
|
287
|
+
/*async get<T>(endpoint: string): Promise<T> {
|
|
288
|
+
return this.request<T>('GET', endpoint);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* Generic POST request
|
|
293
|
+
*/
|
|
294
|
+
/*async post<T>(endpoint: string, body?: any): Promise<T> {
|
|
295
|
+
return this.request<T>('POST', endpoint, body);
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Generic PUT request
|
|
300
|
+
*/
|
|
301
|
+
/*async put<T>(endpoint: string, body?: any): Promise<T> {
|
|
302
|
+
return this.request<T>('PUT', endpoint, body);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Generic DELETE request
|
|
307
|
+
*/
|
|
308
|
+
/*async delete<T>(endpoint: string): Promise<T> {
|
|
309
|
+
return this.request<T>('DELETE', endpoint);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Get current configuration (returns merged config)
|
|
314
|
+
*/
|
|
315
|
+
/*getConfig(): ReturnType<typeof mergeWithDefaults> {
|
|
316
|
+
return this.mergedConfig;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Get original user configuration
|
|
321
|
+
*/
|
|
322
|
+
/*getOriginalConfig(): PersConfig {
|
|
323
|
+
return this.config;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
export class PersApiError extends Error {
|
|
328
|
+
constructor(
|
|
329
|
+
message: string,
|
|
330
|
+
public endpoint: string,
|
|
331
|
+
public method: string,
|
|
332
|
+
public statusCode?: number
|
|
333
|
+
) {
|
|
334
|
+
super(message);
|
|
335
|
+
this.name = 'PersApiError';
|
|
336
|
+
}
|
|
337
|
+
}*/
|
|
338
|
+
|
|
339
|
+
/**
|
|
340
|
+
* Creates a platform-agnostic AuthProvider from simple configuration
|
|
341
|
+
*
|
|
342
|
+
* This factory function is completely platform-agnostic and can be used
|
|
343
|
+
* across Angular, React, Vue, Node.js, or any other JavaScript environment.
|
|
344
|
+
*
|
|
345
|
+
* Features:
|
|
346
|
+
* - Token caching with refresh support
|
|
347
|
+
* - Automatic token refresh on expiration
|
|
348
|
+
* - Configurable token providers
|
|
349
|
+
* - Platform-independent (no localStorage assumptions)
|
|
350
|
+
*
|
|
351
|
+
* @param config - Simple auth configuration
|
|
352
|
+
* @returns AuthProvider implementation
|
|
353
|
+
*/
|
|
354
|
+
function createAuthProvider(config) {
|
|
355
|
+
// Store current token for refresh scenarios and caching
|
|
356
|
+
let currentToken = config.token || null;
|
|
357
|
+
let isRefreshing = false; // Prevent concurrent refresh attempts
|
|
358
|
+
let refreshPromise = null;
|
|
359
|
+
return {
|
|
360
|
+
authType: config.authType || 'user',
|
|
361
|
+
async getToken() {
|
|
362
|
+
// If currently refreshing, wait for it to complete
|
|
363
|
+
if (isRefreshing && refreshPromise) {
|
|
364
|
+
await refreshPromise;
|
|
365
|
+
return currentToken;
|
|
366
|
+
}
|
|
367
|
+
// Use cached current token (updated after refresh)
|
|
368
|
+
if (currentToken) {
|
|
369
|
+
return currentToken;
|
|
370
|
+
}
|
|
371
|
+
// Custom token provider function (always fresh)
|
|
372
|
+
if (config.tokenProvider) {
|
|
373
|
+
const token = await config.tokenProvider();
|
|
374
|
+
currentToken = token; // Cache for future calls
|
|
375
|
+
return token;
|
|
376
|
+
}
|
|
377
|
+
// No token available
|
|
378
|
+
return null;
|
|
379
|
+
},
|
|
380
|
+
async getProjectKey() {
|
|
381
|
+
return config.projectKey || null;
|
|
382
|
+
},
|
|
383
|
+
async onTokenExpired() {
|
|
384
|
+
// Prevent concurrent refresh attempts
|
|
385
|
+
if (isRefreshing) {
|
|
386
|
+
if (refreshPromise) {
|
|
387
|
+
await refreshPromise;
|
|
388
|
+
}
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
// No refresh logic provided
|
|
392
|
+
if (!config.onTokenExpired) {
|
|
393
|
+
console.warn('Token expired but no refresh logic provided');
|
|
394
|
+
currentToken = null; // Clear expired token
|
|
395
|
+
return;
|
|
396
|
+
}
|
|
397
|
+
// Start refresh process
|
|
398
|
+
isRefreshing = true;
|
|
399
|
+
refreshPromise = (async () => {
|
|
400
|
+
try {
|
|
401
|
+
// Execute refresh logic (should update token source)
|
|
402
|
+
await config.onTokenExpired();
|
|
403
|
+
// After refresh, get the new token
|
|
404
|
+
if (config.tokenProvider) {
|
|
405
|
+
const newToken = await config.tokenProvider();
|
|
406
|
+
if (newToken && newToken !== currentToken) {
|
|
407
|
+
currentToken = newToken;
|
|
408
|
+
// Notify about successful token refresh
|
|
409
|
+
if (config.onTokenRefreshed) {
|
|
410
|
+
config.onTokenRefreshed(newToken);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
else {
|
|
414
|
+
console.warn('Token refresh completed but no new token received');
|
|
415
|
+
currentToken = null;
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
else {
|
|
419
|
+
// For static token configs, clear the token since we can't refresh
|
|
420
|
+
console.warn('Token expired for static token config - clearing token');
|
|
421
|
+
currentToken = null;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
catch (error) {
|
|
425
|
+
console.error('Token refresh failed:', error);
|
|
426
|
+
currentToken = null; // Clear token on refresh failure
|
|
427
|
+
throw error; // Re-throw to let SDK handle the error
|
|
428
|
+
}
|
|
429
|
+
finally {
|
|
430
|
+
isRefreshing = false;
|
|
431
|
+
refreshPromise = null;
|
|
432
|
+
}
|
|
433
|
+
})();
|
|
434
|
+
await refreshPromise;
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Platform-specific localStorage token provider for browsers
|
|
440
|
+
* This is a convenience function for browser environments
|
|
441
|
+
*/
|
|
442
|
+
/* export function createBrowserTokenProvider(tokenKey: string = 'userJwt'): () => Promise<string | null> {
|
|
443
|
+
return async () => {
|
|
444
|
+
if (typeof localStorage !== 'undefined') {
|
|
445
|
+
return localStorage.getItem(tokenKey);
|
|
446
|
+
}
|
|
447
|
+
return null;
|
|
448
|
+
};
|
|
449
|
+
} */
|
|
450
|
+
/**
|
|
451
|
+
* Platform-specific environment variable token provider for Node.js
|
|
452
|
+
* This is a convenience function for Node.js environments
|
|
453
|
+
*/
|
|
454
|
+
/* export function createNodeTokenProvider(envVar: string = 'JWT_TOKEN'): () => Promise<string | null> {
|
|
455
|
+
return async () => {
|
|
456
|
+
if (typeof process !== 'undefined' && process.env) {
|
|
457
|
+
return process.env[envVar] || null;
|
|
458
|
+
}
|
|
459
|
+
return null;
|
|
460
|
+
};
|
|
461
|
+
} */
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* PERS SDK - Minimal platform-agnostic client with built-in authentication
|
|
465
|
+
* Authentication is now handled at the SDK core level for better scalability
|
|
466
|
+
*/
|
|
467
|
+
/**
|
|
468
|
+
* Minimal PERS SDK - API client with authentication built-in
|
|
469
|
+
* Platform adapters provide auth providers and HTTP clients
|
|
470
|
+
*/
|
|
471
|
+
class PersSDK {
|
|
472
|
+
constructor(httpClient, config) {
|
|
473
|
+
this.apiClient = new PersApiClient(httpClient, config);
|
|
474
|
+
}
|
|
475
|
+
/**
|
|
476
|
+
* Get the API client for direct PERS API calls
|
|
477
|
+
* This is the main interface - keep it simple!
|
|
478
|
+
*/
|
|
479
|
+
api() {
|
|
480
|
+
return this.apiClient;
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* Quick config check
|
|
484
|
+
*/
|
|
485
|
+
isProduction() {
|
|
486
|
+
return this.apiClient.getConfig().environment === 'production';
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
/**
|
|
490
|
+
* Simple factory function
|
|
491
|
+
*/
|
|
492
|
+
function createPersSDK(httpClient, config) {
|
|
493
|
+
return new PersSDK(httpClient, config);
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
export { DEFAULT_PERS_CONFIG, PersApiClient, PersApiError, PersSDK, buildApiRoot, createAuthProvider, createPersSDK, mergeWithDefaults };
|
|
497
|
+
//# sourceMappingURL=core.js.map
|
package/dist/core.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"core.js","sources":["../src/core/pers-config.ts","../src/core/pers-api-client.ts","../src/core/auth/create-auth-provider.ts","../src/pers-sdk.ts"],"sourcesContent":[null,null,null,null],"names":[],"mappings":"AAAA;;AAEG;AAuBH;;AAEG;AACI,MAAM,mBAAmB,GAAG;AACjC,IAAA,WAAW,EAAE,YAA+B;AAC5C,IAAA,UAAU,EAAE,IAAsB;AAClC,IAAA,OAAO,EAAE,KAAK;AACd,IAAA,OAAO,EAAE;;AAGX;;;AAGG;SACa,YAAY,CAC1B,cAA+B,YAAY,EAC3C,UAA0B,IAAI,EAAA;AAE9B,IAAA,MAAM,QAAQ,GAAG;AACf,QAAA,WAAW,EAAE,oCAAoC;QACjD,OAAO,EAAE,CAAA,2BAAA,EAA8B,OAAO,CAAA,CAAE;QAChD,UAAU,EAAE,CAAA,uBAAA,EAA0B,OAAO,CAAA;KAC9C;AAED,IAAA,OAAO,GAAG,QAAQ,CAA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shared/interfaces/pers-shared-lib.interfaces';
|
|
3
|
+
/**
|
|
4
|
+
* Platform-Agnostic Donation API Client
|
|
5
|
+
*
|
|
6
|
+
* Handles donation operations using the PERS backend.
|
|
7
|
+
* Matches framework DonationApiService methods exactly.
|
|
8
|
+
*/
|
|
9
|
+
export declare class DonationApi {
|
|
10
|
+
private apiClient;
|
|
11
|
+
constructor(apiClient: PersApiClient);
|
|
12
|
+
/**
|
|
13
|
+
* PUBLIC: Get all donation types
|
|
14
|
+
* ✅ ONLY method actually used by framework
|
|
15
|
+
*/
|
|
16
|
+
getAllDonationTypes(): Promise<DonationTypeDTO[]>;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=donation-api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"donation-api.d.ts","sourceRoot":"","sources":["../../../src/donation/api/donation-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,oDAAoD,CAAC;AAErF;;;;;GAKG;AACH,qBAAa,WAAW;IACV,OAAO,CAAC,SAAS;gBAAT,SAAS,EAAE,aAAa;IAM5C;;;OAGG;IACG,mBAAmB,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;CAGxD"}
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
export { DonationApi } from './api/donation-api';
|
|
8
|
+
export { DonationService } from './services/donation-service';
|
|
9
|
+
export * from '../shared/interfaces/pers-shared-lib.interfaces';
|
|
10
|
+
import { PersApiClient } from '../core/pers-api-client';
|
|
11
|
+
import { DonationApi } from './api/donation-api';
|
|
12
|
+
import { DonationService } from './services/donation-service';
|
|
13
|
+
/**
|
|
14
|
+
* Create a complete Donation SDK instance
|
|
15
|
+
*
|
|
16
|
+
* @param apiClient - Configured PERS API client
|
|
17
|
+
* @returns Donation SDK with flattened structure for better DX
|
|
18
|
+
*/
|
|
19
|
+
export declare function createDonationSDK(apiClient: PersApiClient): {
|
|
20
|
+
getAllDonationTypes: () => Promise<import("@explorins/pers-shared/dist/cjs/dto/purchase/donationType.dto").DonationTypeDTO[]>;
|
|
21
|
+
api: DonationApi;
|
|
22
|
+
service: DonationService;
|
|
23
|
+
};
|
|
24
|
+
export type DonationSDK = ReturnType<typeof createDonationSDK>;
|
|
25
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/donation/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAGjD,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAG9D,cAAc,iDAAiD,CAAC;AAKhE,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAE9D;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,aAAa;;;;EAezD;AAED,MAAM,MAAM,WAAW,GAAG,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC"}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Donation Domain Models
|
|
3
|
-
*
|
|
4
|
-
* Re-exports from centralized pers-shared interfaces for consistency with backend
|
|
5
|
-
* and to provide a single import source for donation-related types.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export type {
|
|
10
|
-
DonationTypeDTO
|
|
11
|
-
} from '../../shared/interfaces/pers-shared-lib.interfaces';
|
|
1
|
+
/**
|
|
2
|
+
* Donation Domain Models
|
|
3
|
+
*
|
|
4
|
+
* Re-exports from centralized pers-shared interfaces for consistency with backend
|
|
5
|
+
* and to provide a single import source for donation-related types.
|
|
6
|
+
*/
|
|
7
|
+
export type { DonationTypeDTO } from '../../shared/interfaces/pers-shared-lib.interfaces';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/donation/models/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,YAAY,EACV,eAAe,EAChB,MAAM,oDAAoD,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { DonationApi } from '../api/donation-api';
|
|
2
|
+
import { DonationTypeDTO } from '../../shared/interfaces/pers-shared-lib.interfaces';
|
|
3
|
+
/**
|
|
4
|
+
* Platform-Agnostic Donation Service
|
|
5
|
+
*
|
|
6
|
+
* Contains donation business logic and operations that work across platforms.
|
|
7
|
+
* No framework dependencies - pure TypeScript business logic.
|
|
8
|
+
* Matches framework DonationApiService capabilities exactly.
|
|
9
|
+
*/
|
|
10
|
+
export declare class DonationService {
|
|
11
|
+
private donationApi;
|
|
12
|
+
constructor(donationApi: DonationApi);
|
|
13
|
+
/**
|
|
14
|
+
* PUBLIC: Get all donation types
|
|
15
|
+
* ✅ ONLY method actually used by framework
|
|
16
|
+
*/
|
|
17
|
+
getAllDonationTypes(): Promise<DonationTypeDTO[]>;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=donation-service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"donation-service.d.ts","sourceRoot":"","sources":["../../../src/donation/services/donation-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,oDAAoD,CAAC;AAErF;;;;;;GAMG;AACH,qBAAa,eAAe;IACd,OAAO,CAAC,WAAW;gBAAX,WAAW,EAAE,WAAW;IAM5C;;;OAGG;IACG,mBAAmB,IAAI,OAAO,CAAC,eAAe,EAAE,CAAC;CAGxD"}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Platform-Agnostic Donation API Client
|
|
5
|
+
*
|
|
6
|
+
* Handles donation operations using the PERS backend.
|
|
7
|
+
* Matches framework DonationApiService methods exactly.
|
|
8
|
+
*/
|
|
9
|
+
class DonationApi {
|
|
10
|
+
constructor(apiClient) {
|
|
11
|
+
this.apiClient = apiClient;
|
|
12
|
+
}
|
|
13
|
+
// ==========================================
|
|
14
|
+
// PUBLIC OPERATIONS
|
|
15
|
+
// ==========================================
|
|
16
|
+
/**
|
|
17
|
+
* PUBLIC: Get all donation types
|
|
18
|
+
* ✅ ONLY method actually used by framework
|
|
19
|
+
*/
|
|
20
|
+
async getAllDonationTypes() {
|
|
21
|
+
return this.apiClient.get('/purchase/donation/type');
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Platform-Agnostic Donation Service
|
|
27
|
+
*
|
|
28
|
+
* Contains donation business logic and operations that work across platforms.
|
|
29
|
+
* No framework dependencies - pure TypeScript business logic.
|
|
30
|
+
* Matches framework DonationApiService capabilities exactly.
|
|
31
|
+
*/
|
|
32
|
+
class DonationService {
|
|
33
|
+
constructor(donationApi) {
|
|
34
|
+
this.donationApi = donationApi;
|
|
35
|
+
}
|
|
36
|
+
// ==========================================
|
|
37
|
+
// PUBLIC OPERATIONS
|
|
38
|
+
// ==========================================
|
|
39
|
+
/**
|
|
40
|
+
* PUBLIC: Get all donation types
|
|
41
|
+
* ✅ ONLY method actually used by framework
|
|
42
|
+
*/
|
|
43
|
+
async getAllDonationTypes() {
|
|
44
|
+
return this.donationApi.getAllDonationTypes();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* @explorins/pers-sdk-donation
|
|
50
|
+
*
|
|
51
|
+
* Platform-agnostic Donation Domain SDK for PERS ecosystem
|
|
52
|
+
* Handles donation type retrieval for purchase flow integration
|
|
53
|
+
*/
|
|
54
|
+
// API Layer
|
|
55
|
+
/**
|
|
56
|
+
* Create a complete Donation SDK instance
|
|
57
|
+
*
|
|
58
|
+
* @param apiClient - Configured PERS API client
|
|
59
|
+
* @returns Donation SDK with flattened structure for better DX
|
|
60
|
+
*/
|
|
61
|
+
function createDonationSDK(apiClient) {
|
|
62
|
+
const donationApi = new DonationApi(apiClient);
|
|
63
|
+
const donationService = new DonationService(donationApi);
|
|
64
|
+
return {
|
|
65
|
+
// Direct access to service methods (primary interface)
|
|
66
|
+
// ✅ FRAMEWORK ALIGNED: Only method actually used by framework
|
|
67
|
+
// Public methods
|
|
68
|
+
getAllDonationTypes: () => donationService.getAllDonationTypes(),
|
|
69
|
+
// Advanced access for edge cases
|
|
70
|
+
api: donationApi,
|
|
71
|
+
service: donationService
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
exports.DonationApi = DonationApi;
|
|
76
|
+
exports.DonationService = DonationService;
|
|
77
|
+
exports.createDonationSDK = createDonationSDK;
|
|
78
|
+
//# sourceMappingURL=donation.cjs.map
|