@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/payment.cjs
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Platform-Agnostic Purchase API Client (RESTful Architecture)
|
|
5
|
+
*
|
|
6
|
+
* Handles purchase and payment operations using the PERS backend's new RESTful endpoints.
|
|
7
|
+
* Uses @explorins/pers-shared DTOs for consistency with backend.
|
|
8
|
+
*
|
|
9
|
+
* Migration Status: Updated to match /purchases controller (replaces /purchase endpoints)
|
|
10
|
+
*
|
|
11
|
+
* Available Access Levels:
|
|
12
|
+
* - PUBLIC: Project key authentication for catalog browsing and payment operations
|
|
13
|
+
* - USER: Requires user authentication JWT (purchase creation, history access)
|
|
14
|
+
* - ADMIN: Requires tenant admin privileges (not implemented in this client)
|
|
15
|
+
*
|
|
16
|
+
* Note: This SDK focuses on backend purchase operations only.
|
|
17
|
+
* Payment provider integrations (Stripe, etc.) should remain in infrastructure layer.
|
|
18
|
+
*/
|
|
19
|
+
class PurchaseApi {
|
|
20
|
+
constructor(apiClient) {
|
|
21
|
+
this.apiClient = apiClient;
|
|
22
|
+
this.basePath = '/purchases';
|
|
23
|
+
}
|
|
24
|
+
// ==========================================
|
|
25
|
+
// PUBLIC OPERATIONS (Project Key)
|
|
26
|
+
// ==========================================
|
|
27
|
+
/**
|
|
28
|
+
* PUBLIC: Get purchase tokens (Intelligent Access)
|
|
29
|
+
*
|
|
30
|
+
* RESTful endpoint: GET /purchases/tokens
|
|
31
|
+
* Replaces: GET /purchase/token
|
|
32
|
+
*
|
|
33
|
+
* INTELLIGENT ACCESS:
|
|
34
|
+
* - PUBLIC (Project Key): Returns active tokens only (active parameter ignored)
|
|
35
|
+
* - ADMIN (Tenant Admin JWT): Returns filtered results based on active parameter
|
|
36
|
+
*/
|
|
37
|
+
async getPurchaseTokens(active) {
|
|
38
|
+
let url = `${this.basePath}/tokens`;
|
|
39
|
+
if (active !== undefined) {
|
|
40
|
+
url += `?active=${active}`;
|
|
41
|
+
}
|
|
42
|
+
return this.apiClient.get(url);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* PUBLIC: Get donation types
|
|
46
|
+
*
|
|
47
|
+
* RESTful endpoint: GET /purchases/donation-types
|
|
48
|
+
* Replaces: GET /purchase/donation/type
|
|
49
|
+
*/
|
|
50
|
+
async getDonationTypes() {
|
|
51
|
+
return this.apiClient.get(`${this.basePath}/donation-types`);
|
|
52
|
+
}
|
|
53
|
+
// ==========================================
|
|
54
|
+
// PAYMENT OPERATIONS (FINANCIAL - CRITICAL)
|
|
55
|
+
// ==========================================
|
|
56
|
+
/**
|
|
57
|
+
* PUBLIC: Create payment intent (FINANCIAL OPERATION)
|
|
58
|
+
*
|
|
59
|
+
* RESTful endpoint: POST /purchases/payment-intents
|
|
60
|
+
* Replaces: POST /purchase/payment-intent
|
|
61
|
+
*
|
|
62
|
+
* CRITICAL: Handles real money operations - tenant context required
|
|
63
|
+
*/
|
|
64
|
+
async createPaymentIntent(amount, currency, receiptEmail, description) {
|
|
65
|
+
const body = {
|
|
66
|
+
amount,
|
|
67
|
+
currency,
|
|
68
|
+
receiptEmail,
|
|
69
|
+
description
|
|
70
|
+
};
|
|
71
|
+
return this.apiClient.post(`${this.basePath}/payment-intents`, body);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* PUBLIC: Update payment intent (FINANCIAL OPERATION)
|
|
75
|
+
*
|
|
76
|
+
* RESTful endpoint: PUT /purchases/payment-intents/{paymentIntentId}
|
|
77
|
+
* Replaces: PUT /purchase/payment-intent/{paymentIntentId}
|
|
78
|
+
*
|
|
79
|
+
* CRITICAL: Handles real money operations - tenant context required
|
|
80
|
+
*/
|
|
81
|
+
async updatePaymentIntent(paymentIntentId, amount, currency, receiptEmail, description) {
|
|
82
|
+
const body = {
|
|
83
|
+
amount,
|
|
84
|
+
currency,
|
|
85
|
+
receiptEmail,
|
|
86
|
+
description
|
|
87
|
+
};
|
|
88
|
+
return this.apiClient.put(`${this.basePath}/payment-intents/${paymentIntentId}`, body);
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* PUBLIC: Cancel payment intent (FINANCIAL OPERATION)
|
|
92
|
+
*
|
|
93
|
+
* RESTful endpoint: DELETE /purchases/payment-intents/{paymentIntentId}
|
|
94
|
+
* Replaces: DELETE /purchase/payment-intent/{paymentIntentId}
|
|
95
|
+
*
|
|
96
|
+
* CRITICAL: Handles real money operations - tenant context required
|
|
97
|
+
*/
|
|
98
|
+
async cancelPaymentIntent(paymentIntentId) {
|
|
99
|
+
return this.apiClient.delete(`${this.basePath}/payment-intents/${paymentIntentId}`);
|
|
100
|
+
}
|
|
101
|
+
// ==========================================
|
|
102
|
+
// USER OPERATIONS (JWT + Project Key)
|
|
103
|
+
// ==========================================
|
|
104
|
+
/**
|
|
105
|
+
* USER: Create purchase (BUSINESS CRITICAL - FINANCIAL TRANSACTION)
|
|
106
|
+
*
|
|
107
|
+
* RESTful endpoint: POST /purchases
|
|
108
|
+
* Replaces: POST /purchase/auth
|
|
109
|
+
*
|
|
110
|
+
* USER-ONLY: Requires user authentication JWT for purchase creation
|
|
111
|
+
* CRITICAL: Real financial transaction with Stripe integration
|
|
112
|
+
*/
|
|
113
|
+
async createUserPurchase(paymentIntentId, amount, purchaseTokenId, donationTypeId, donationAccountAddress) {
|
|
114
|
+
const body = {
|
|
115
|
+
quantity: amount,
|
|
116
|
+
purchaseTokenId: purchaseTokenId || '',
|
|
117
|
+
donationTypeId,
|
|
118
|
+
donationAccountAddress,
|
|
119
|
+
paymentIntentId
|
|
120
|
+
};
|
|
121
|
+
return this.apiClient.post(`${this.basePath}`, body);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* USER: Get user purchase history
|
|
125
|
+
*
|
|
126
|
+
* RESTful endpoint: GET /purchases/me/history
|
|
127
|
+
* Replaces: GET /purchase/auth
|
|
128
|
+
*
|
|
129
|
+
* USER-ONLY: Get authenticated user's purchase history
|
|
130
|
+
* FINANCIAL RECORDS: User attribution critical for compliance
|
|
131
|
+
*/
|
|
132
|
+
async getUserPurchaseHistory() {
|
|
133
|
+
return this.apiClient.get(`${this.basePath}/me/history`);
|
|
134
|
+
}
|
|
135
|
+
// ==========================================
|
|
136
|
+
// CONVENIENCE METHODS (Backward Compatibility)
|
|
137
|
+
// ==========================================
|
|
138
|
+
/**
|
|
139
|
+
* @deprecated Use getPurchaseTokens() instead
|
|
140
|
+
* Backward compatibility alias for getActivePurchaseTokens
|
|
141
|
+
*/
|
|
142
|
+
async getActivePurchaseTokens(active = true) {
|
|
143
|
+
return this.getPurchaseTokens(active);
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* @deprecated Use createUserPurchase() instead
|
|
147
|
+
* Backward compatibility alias for createPurchase
|
|
148
|
+
*/
|
|
149
|
+
async createPurchase(paymentIntentId, amount, purchaseTokenId, donationTypeId, donationAccountAddress) {
|
|
150
|
+
return this.createUserPurchase(paymentIntentId, amount, purchaseTokenId, donationTypeId, donationAccountAddress);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* @deprecated Use getUserPurchaseHistory() instead
|
|
154
|
+
* Backward compatibility alias for getAllUserPurchases
|
|
155
|
+
*/
|
|
156
|
+
async getAllUserPurchases() {
|
|
157
|
+
return this.getUserPurchaseHistory();
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Platform-Agnostic Payment Service
|
|
163
|
+
*
|
|
164
|
+
* Contains payment business logic and operations that work across platforms.
|
|
165
|
+
* No framework dependencies - pure TypeScript business logic.
|
|
166
|
+
*
|
|
167
|
+
* Focuses only on actual backend capabilities.
|
|
168
|
+
* Payment provider logic (Stripe, etc.) should remain in infrastructure layer.
|
|
169
|
+
*/
|
|
170
|
+
class PaymentService {
|
|
171
|
+
constructor(paymentApi) {
|
|
172
|
+
this.paymentApi = paymentApi;
|
|
173
|
+
}
|
|
174
|
+
// ==========================================
|
|
175
|
+
// PUBLIC OPERATIONS
|
|
176
|
+
// ==========================================
|
|
177
|
+
/**
|
|
178
|
+
* PUBLIC: Get active purchase tokens
|
|
179
|
+
*/
|
|
180
|
+
async getActivePurchaseTokens(active = true) {
|
|
181
|
+
return this.paymentApi.getActivePurchaseTokens(active);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* PUBLIC: Create payment intent
|
|
185
|
+
*/
|
|
186
|
+
async createPaymentIntent(amount, currency, receiptEmail, description) {
|
|
187
|
+
return this.paymentApi.createPaymentIntent(amount, currency, receiptEmail, description);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* PUBLIC: Update payment intent
|
|
191
|
+
*/
|
|
192
|
+
async updatePaymentIntent(paymentIntentId, amount, currency, receiptEmail, description) {
|
|
193
|
+
return this.paymentApi.updatePaymentIntent(paymentIntentId, amount, currency, receiptEmail, description);
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* PUBLIC: Cancel payment intent
|
|
197
|
+
*/
|
|
198
|
+
async cancelPaymentIntent(paymentIntentId) {
|
|
199
|
+
return this.paymentApi.cancelPaymentIntent(paymentIntentId);
|
|
200
|
+
}
|
|
201
|
+
// ==========================================
|
|
202
|
+
// AUTHENTICATED OPERATIONS
|
|
203
|
+
// ==========================================
|
|
204
|
+
/**
|
|
205
|
+
* AUTH: Create purchase
|
|
206
|
+
*/
|
|
207
|
+
async createPurchase(paymentIntentId, amount, purchaseTokenId, donationTypeId, donationAccountAddress) {
|
|
208
|
+
return this.paymentApi.createPurchase(paymentIntentId, amount, purchaseTokenId, donationTypeId, donationAccountAddress);
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* AUTH: Get all user purchases
|
|
212
|
+
*/
|
|
213
|
+
async getAllUserPurchases() {
|
|
214
|
+
return this.paymentApi.getAllUserPurchases();
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* @explorins/pers-sdk-payment
|
|
220
|
+
*
|
|
221
|
+
* Platform-agnostic Payment Domain SDK for PERS ecosystem
|
|
222
|
+
* Handles payment intents, purchases, and purchase tokens
|
|
223
|
+
*
|
|
224
|
+
* Note: Payment provider integrations (Stripe, etc.) are kept separate
|
|
225
|
+
* in the infrastructure layer to maintain platform-agnostic principles.
|
|
226
|
+
*/
|
|
227
|
+
// API Layer
|
|
228
|
+
/**
|
|
229
|
+
* Create a complete Payment SDK instance
|
|
230
|
+
*
|
|
231
|
+
* @param apiClient - Configured PERS API client
|
|
232
|
+
* @returns Payment SDK with flattened structure for better DX
|
|
233
|
+
*/
|
|
234
|
+
function createPaymentSDK(apiClient) {
|
|
235
|
+
const paymentApi = new PurchaseApi(apiClient);
|
|
236
|
+
const paymentService = new PaymentService(paymentApi);
|
|
237
|
+
return {
|
|
238
|
+
// Direct access to service methods (primary interface)
|
|
239
|
+
// Public methods
|
|
240
|
+
getActivePurchaseTokens: (active) => paymentService.getActivePurchaseTokens(active),
|
|
241
|
+
// ✅ FIXED: Proper type instead of any
|
|
242
|
+
createPaymentIntent: (amount, currency, receiptEmail, description) => paymentService.createPaymentIntent(amount, currency, receiptEmail, description),
|
|
243
|
+
// ✅ FIXED: Proper type instead of any
|
|
244
|
+
updatePaymentIntent: (paymentIntentId, amount, currency, receiptEmail, description) => paymentService.updatePaymentIntent(paymentIntentId, amount, currency, receiptEmail, description),
|
|
245
|
+
cancelPaymentIntent: (paymentIntentId) => paymentService.cancelPaymentIntent(paymentIntentId),
|
|
246
|
+
// Auth methods
|
|
247
|
+
createPurchase: (paymentIntentId, amount, purchaseTokenId, donationTypeId, donationAccountAddress) => paymentService.createPurchase(paymentIntentId, amount, purchaseTokenId, donationTypeId, donationAccountAddress),
|
|
248
|
+
getAllUserPurchases: () => paymentService.getAllUserPurchases(),
|
|
249
|
+
// Advanced access for edge cases
|
|
250
|
+
api: paymentApi,
|
|
251
|
+
service: paymentService
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
exports.PaymentApi = PurchaseApi;
|
|
256
|
+
exports.PaymentService = PaymentService;
|
|
257
|
+
exports.createPaymentSDK = createPaymentSDK;
|
|
258
|
+
//# sourceMappingURL=payment.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment.cjs","sources":["../src/payment/api/payment-api.ts","../src/payment/services/payment-service.ts","../src/payment/index.ts"],"sourcesContent":[null,null,null],"names":["PaymentApi"],"mappings":";;AAYA;;;;;;;;;;;;;;;AAeG;MACU,WAAW,CAAA;AACtB,IAAA,WAAA,CAAoB,SAAwB,EAAA;QAAxB,IAAA,CAAA,SAAS,GAAT,SAAS;QAEZ,IAAA,CAAA,QAAQ,GAAG,YAAY;IAFO;;;;AAQ/C;;;;;;;;;AASG;IACH,MAAM,iBAAiB,CAAC,MAAgB,EAAA;AACtC,QAAA,IAAI,GAAG,GAAG,CAAA,EAAG,IAAI,CAAC,QAAQ,SAAS;AACnC,QAAA,IAAI,MAAM,KAAK,SAA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,CAAC,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,CAAC;;QAEjF,mBAAmB,EAAE,CAAC,eAAuB,EAAE,MAAc,EAAE,QAA0B,EAAE,YAAoB,EAAE,WAAmB,KAClI,cAAc,CAAC,mBAAmB,CAAC,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,CAAC;QAClG,mBAAmB,EAAE,CAAC,eAAuB,KAAK,cAAc,CAAC,mBAAmB,CAAC,eAAe,CAAC;;QAGrG,cAAc,EAAE,CAAC,eAAuB,EAAE,MAAc,EAAE,eAAwB,EAAE,cAAuB,EAAE,sBAA+B,KAC1I,cAAc,CAAC,cAAc,CAAC,eAAe,EAAE,MAAM,EAAE,eAAe,EAAE,cAAc,EAAE,sBAAsB,CAAC;AACjH,QAAA,mBAAmB,EAAE,MAAM,cAAc,CAAC,mBAAmB,EAAE;;AAG/D,QAAA,GAAG,EAAE,UAAU;AACf,QAAA,OAAO,EAAE;KACV;AACH;;;;;;"}
|
package/dist/payment.js
ADDED
|
@@ -0,0 +1,254 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform-Agnostic Purchase API Client (RESTful Architecture)
|
|
3
|
+
*
|
|
4
|
+
* Handles purchase and payment operations using the PERS backend's new RESTful endpoints.
|
|
5
|
+
* Uses @explorins/pers-shared DTOs for consistency with backend.
|
|
6
|
+
*
|
|
7
|
+
* Migration Status: Updated to match /purchases controller (replaces /purchase endpoints)
|
|
8
|
+
*
|
|
9
|
+
* Available Access Levels:
|
|
10
|
+
* - PUBLIC: Project key authentication for catalog browsing and payment operations
|
|
11
|
+
* - USER: Requires user authentication JWT (purchase creation, history access)
|
|
12
|
+
* - ADMIN: Requires tenant admin privileges (not implemented in this client)
|
|
13
|
+
*
|
|
14
|
+
* Note: This SDK focuses on backend purchase operations only.
|
|
15
|
+
* Payment provider integrations (Stripe, etc.) should remain in infrastructure layer.
|
|
16
|
+
*/
|
|
17
|
+
class PurchaseApi {
|
|
18
|
+
constructor(apiClient) {
|
|
19
|
+
this.apiClient = apiClient;
|
|
20
|
+
this.basePath = '/purchases';
|
|
21
|
+
}
|
|
22
|
+
// ==========================================
|
|
23
|
+
// PUBLIC OPERATIONS (Project Key)
|
|
24
|
+
// ==========================================
|
|
25
|
+
/**
|
|
26
|
+
* PUBLIC: Get purchase tokens (Intelligent Access)
|
|
27
|
+
*
|
|
28
|
+
* RESTful endpoint: GET /purchases/tokens
|
|
29
|
+
* Replaces: GET /purchase/token
|
|
30
|
+
*
|
|
31
|
+
* INTELLIGENT ACCESS:
|
|
32
|
+
* - PUBLIC (Project Key): Returns active tokens only (active parameter ignored)
|
|
33
|
+
* - ADMIN (Tenant Admin JWT): Returns filtered results based on active parameter
|
|
34
|
+
*/
|
|
35
|
+
async getPurchaseTokens(active) {
|
|
36
|
+
let url = `${this.basePath}/tokens`;
|
|
37
|
+
if (active !== undefined) {
|
|
38
|
+
url += `?active=${active}`;
|
|
39
|
+
}
|
|
40
|
+
return this.apiClient.get(url);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* PUBLIC: Get donation types
|
|
44
|
+
*
|
|
45
|
+
* RESTful endpoint: GET /purchases/donation-types
|
|
46
|
+
* Replaces: GET /purchase/donation/type
|
|
47
|
+
*/
|
|
48
|
+
async getDonationTypes() {
|
|
49
|
+
return this.apiClient.get(`${this.basePath}/donation-types`);
|
|
50
|
+
}
|
|
51
|
+
// ==========================================
|
|
52
|
+
// PAYMENT OPERATIONS (FINANCIAL - CRITICAL)
|
|
53
|
+
// ==========================================
|
|
54
|
+
/**
|
|
55
|
+
* PUBLIC: Create payment intent (FINANCIAL OPERATION)
|
|
56
|
+
*
|
|
57
|
+
* RESTful endpoint: POST /purchases/payment-intents
|
|
58
|
+
* Replaces: POST /purchase/payment-intent
|
|
59
|
+
*
|
|
60
|
+
* CRITICAL: Handles real money operations - tenant context required
|
|
61
|
+
*/
|
|
62
|
+
async createPaymentIntent(amount, currency, receiptEmail, description) {
|
|
63
|
+
const body = {
|
|
64
|
+
amount,
|
|
65
|
+
currency,
|
|
66
|
+
receiptEmail,
|
|
67
|
+
description
|
|
68
|
+
};
|
|
69
|
+
return this.apiClient.post(`${this.basePath}/payment-intents`, body);
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* PUBLIC: Update payment intent (FINANCIAL OPERATION)
|
|
73
|
+
*
|
|
74
|
+
* RESTful endpoint: PUT /purchases/payment-intents/{paymentIntentId}
|
|
75
|
+
* Replaces: PUT /purchase/payment-intent/{paymentIntentId}
|
|
76
|
+
*
|
|
77
|
+
* CRITICAL: Handles real money operations - tenant context required
|
|
78
|
+
*/
|
|
79
|
+
async updatePaymentIntent(paymentIntentId, amount, currency, receiptEmail, description) {
|
|
80
|
+
const body = {
|
|
81
|
+
amount,
|
|
82
|
+
currency,
|
|
83
|
+
receiptEmail,
|
|
84
|
+
description
|
|
85
|
+
};
|
|
86
|
+
return this.apiClient.put(`${this.basePath}/payment-intents/${paymentIntentId}`, body);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* PUBLIC: Cancel payment intent (FINANCIAL OPERATION)
|
|
90
|
+
*
|
|
91
|
+
* RESTful endpoint: DELETE /purchases/payment-intents/{paymentIntentId}
|
|
92
|
+
* Replaces: DELETE /purchase/payment-intent/{paymentIntentId}
|
|
93
|
+
*
|
|
94
|
+
* CRITICAL: Handles real money operations - tenant context required
|
|
95
|
+
*/
|
|
96
|
+
async cancelPaymentIntent(paymentIntentId) {
|
|
97
|
+
return this.apiClient.delete(`${this.basePath}/payment-intents/${paymentIntentId}`);
|
|
98
|
+
}
|
|
99
|
+
// ==========================================
|
|
100
|
+
// USER OPERATIONS (JWT + Project Key)
|
|
101
|
+
// ==========================================
|
|
102
|
+
/**
|
|
103
|
+
* USER: Create purchase (BUSINESS CRITICAL - FINANCIAL TRANSACTION)
|
|
104
|
+
*
|
|
105
|
+
* RESTful endpoint: POST /purchases
|
|
106
|
+
* Replaces: POST /purchase/auth
|
|
107
|
+
*
|
|
108
|
+
* USER-ONLY: Requires user authentication JWT for purchase creation
|
|
109
|
+
* CRITICAL: Real financial transaction with Stripe integration
|
|
110
|
+
*/
|
|
111
|
+
async createUserPurchase(paymentIntentId, amount, purchaseTokenId, donationTypeId, donationAccountAddress) {
|
|
112
|
+
const body = {
|
|
113
|
+
quantity: amount,
|
|
114
|
+
purchaseTokenId: purchaseTokenId || '',
|
|
115
|
+
donationTypeId,
|
|
116
|
+
donationAccountAddress,
|
|
117
|
+
paymentIntentId
|
|
118
|
+
};
|
|
119
|
+
return this.apiClient.post(`${this.basePath}`, body);
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* USER: Get user purchase history
|
|
123
|
+
*
|
|
124
|
+
* RESTful endpoint: GET /purchases/me/history
|
|
125
|
+
* Replaces: GET /purchase/auth
|
|
126
|
+
*
|
|
127
|
+
* USER-ONLY: Get authenticated user's purchase history
|
|
128
|
+
* FINANCIAL RECORDS: User attribution critical for compliance
|
|
129
|
+
*/
|
|
130
|
+
async getUserPurchaseHistory() {
|
|
131
|
+
return this.apiClient.get(`${this.basePath}/me/history`);
|
|
132
|
+
}
|
|
133
|
+
// ==========================================
|
|
134
|
+
// CONVENIENCE METHODS (Backward Compatibility)
|
|
135
|
+
// ==========================================
|
|
136
|
+
/**
|
|
137
|
+
* @deprecated Use getPurchaseTokens() instead
|
|
138
|
+
* Backward compatibility alias for getActivePurchaseTokens
|
|
139
|
+
*/
|
|
140
|
+
async getActivePurchaseTokens(active = true) {
|
|
141
|
+
return this.getPurchaseTokens(active);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* @deprecated Use createUserPurchase() instead
|
|
145
|
+
* Backward compatibility alias for createPurchase
|
|
146
|
+
*/
|
|
147
|
+
async createPurchase(paymentIntentId, amount, purchaseTokenId, donationTypeId, donationAccountAddress) {
|
|
148
|
+
return this.createUserPurchase(paymentIntentId, amount, purchaseTokenId, donationTypeId, donationAccountAddress);
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* @deprecated Use getUserPurchaseHistory() instead
|
|
152
|
+
* Backward compatibility alias for getAllUserPurchases
|
|
153
|
+
*/
|
|
154
|
+
async getAllUserPurchases() {
|
|
155
|
+
return this.getUserPurchaseHistory();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* Platform-Agnostic Payment Service
|
|
161
|
+
*
|
|
162
|
+
* Contains payment business logic and operations that work across platforms.
|
|
163
|
+
* No framework dependencies - pure TypeScript business logic.
|
|
164
|
+
*
|
|
165
|
+
* Focuses only on actual backend capabilities.
|
|
166
|
+
* Payment provider logic (Stripe, etc.) should remain in infrastructure layer.
|
|
167
|
+
*/
|
|
168
|
+
class PaymentService {
|
|
169
|
+
constructor(paymentApi) {
|
|
170
|
+
this.paymentApi = paymentApi;
|
|
171
|
+
}
|
|
172
|
+
// ==========================================
|
|
173
|
+
// PUBLIC OPERATIONS
|
|
174
|
+
// ==========================================
|
|
175
|
+
/**
|
|
176
|
+
* PUBLIC: Get active purchase tokens
|
|
177
|
+
*/
|
|
178
|
+
async getActivePurchaseTokens(active = true) {
|
|
179
|
+
return this.paymentApi.getActivePurchaseTokens(active);
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* PUBLIC: Create payment intent
|
|
183
|
+
*/
|
|
184
|
+
async createPaymentIntent(amount, currency, receiptEmail, description) {
|
|
185
|
+
return this.paymentApi.createPaymentIntent(amount, currency, receiptEmail, description);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* PUBLIC: Update payment intent
|
|
189
|
+
*/
|
|
190
|
+
async updatePaymentIntent(paymentIntentId, amount, currency, receiptEmail, description) {
|
|
191
|
+
return this.paymentApi.updatePaymentIntent(paymentIntentId, amount, currency, receiptEmail, description);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* PUBLIC: Cancel payment intent
|
|
195
|
+
*/
|
|
196
|
+
async cancelPaymentIntent(paymentIntentId) {
|
|
197
|
+
return this.paymentApi.cancelPaymentIntent(paymentIntentId);
|
|
198
|
+
}
|
|
199
|
+
// ==========================================
|
|
200
|
+
// AUTHENTICATED OPERATIONS
|
|
201
|
+
// ==========================================
|
|
202
|
+
/**
|
|
203
|
+
* AUTH: Create purchase
|
|
204
|
+
*/
|
|
205
|
+
async createPurchase(paymentIntentId, amount, purchaseTokenId, donationTypeId, donationAccountAddress) {
|
|
206
|
+
return this.paymentApi.createPurchase(paymentIntentId, amount, purchaseTokenId, donationTypeId, donationAccountAddress);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* AUTH: Get all user purchases
|
|
210
|
+
*/
|
|
211
|
+
async getAllUserPurchases() {
|
|
212
|
+
return this.paymentApi.getAllUserPurchases();
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* @explorins/pers-sdk-payment
|
|
218
|
+
*
|
|
219
|
+
* Platform-agnostic Payment Domain SDK for PERS ecosystem
|
|
220
|
+
* Handles payment intents, purchases, and purchase tokens
|
|
221
|
+
*
|
|
222
|
+
* Note: Payment provider integrations (Stripe, etc.) are kept separate
|
|
223
|
+
* in the infrastructure layer to maintain platform-agnostic principles.
|
|
224
|
+
*/
|
|
225
|
+
// API Layer
|
|
226
|
+
/**
|
|
227
|
+
* Create a complete Payment SDK instance
|
|
228
|
+
*
|
|
229
|
+
* @param apiClient - Configured PERS API client
|
|
230
|
+
* @returns Payment SDK with flattened structure for better DX
|
|
231
|
+
*/
|
|
232
|
+
function createPaymentSDK(apiClient) {
|
|
233
|
+
const paymentApi = new PurchaseApi(apiClient);
|
|
234
|
+
const paymentService = new PaymentService(paymentApi);
|
|
235
|
+
return {
|
|
236
|
+
// Direct access to service methods (primary interface)
|
|
237
|
+
// Public methods
|
|
238
|
+
getActivePurchaseTokens: (active) => paymentService.getActivePurchaseTokens(active),
|
|
239
|
+
// ✅ FIXED: Proper type instead of any
|
|
240
|
+
createPaymentIntent: (amount, currency, receiptEmail, description) => paymentService.createPaymentIntent(amount, currency, receiptEmail, description),
|
|
241
|
+
// ✅ FIXED: Proper type instead of any
|
|
242
|
+
updatePaymentIntent: (paymentIntentId, amount, currency, receiptEmail, description) => paymentService.updatePaymentIntent(paymentIntentId, amount, currency, receiptEmail, description),
|
|
243
|
+
cancelPaymentIntent: (paymentIntentId) => paymentService.cancelPaymentIntent(paymentIntentId),
|
|
244
|
+
// Auth methods
|
|
245
|
+
createPurchase: (paymentIntentId, amount, purchaseTokenId, donationTypeId, donationAccountAddress) => paymentService.createPurchase(paymentIntentId, amount, purchaseTokenId, donationTypeId, donationAccountAddress),
|
|
246
|
+
getAllUserPurchases: () => paymentService.getAllUserPurchases(),
|
|
247
|
+
// Advanced access for edge cases
|
|
248
|
+
api: paymentApi,
|
|
249
|
+
service: paymentService
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
export { PurchaseApi as PaymentApi, PaymentService, createPaymentSDK };
|
|
254
|
+
//# sourceMappingURL=payment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payment.js","sources":["../src/payment/api/payment-api.ts","../src/payment/services/payment-service.ts","../src/payment/index.ts"],"sourcesContent":[null,null,null],"names":["PaymentApi"],"mappings":"AAYA;;;;;;;;;;;;;;;AAeG;MACU,WAAW,CAAA;AACtB,IAAA,WAAA,CAAoB,SAAwB,EAAA;QAAxB,IAAA,CAAA,SAAS,GAAT,SAAS;QAEZ,IAAA,CAAA,QAAQ,GAAG,YAAY;IAFO;;;;AAQ/C;;;;;;;;;AASG;IACH,MAAM,iBAAiB,CAAC,MAAgB,EAAA;AACtC,QAAA,IAAI,GAAG,GAAG,CAAA,EAAG,IAAI,CAAC,QAAQ,SAAS;AACnC,QAAA,IAAI,MAAM,KAAK,SAAS,EAAE;AACxB,YAAA,GAAG,IAAI,CAAA,QAAA,EAAW,MAAM,CAAA,CAAE;QAC5B;QACA,OAAO,IAA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B,EAAE,MAAc,EAAE,QAA0B,EAAE,YAAoB,EAAE,WAAmB,KAClI,cAAc,CAAC,mBAAmB,CAAC,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,YAAY,EAAE,WAAW,CAAC;QAClG,mBAAmB,EAAE,CAAC,eAAuB,KAAK,cAAc,CAAC,mBAAmB,CAAC,eAAe,CAAC;;QAGrG,cAAc,EAAE,CAAC,eAAuB,EAAE,MAAc,EAAE,eAAwB,EAAE,cAAuB,EAAE,sBAA+B,KAC1I,cAAc,CAAC,cAAc,CAAC,eAAe,EAAE,MAAM,EAAE,eAAe,EAAE,cAAc,EAAE,sBAAsB,CAAC;AACjH,QAAA,mBAAmB,EAAE,MAAM,cAAc,CAAC,mBAAmB,EAAE;;AAG/D,QAAA,GAAG,EAAE,UAAU;AACf,QAAA,OAAO,EAAE;KACV;AACH;;;;"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PERS SDK - Minimal platform-agnostic client with built-in authentication
|
|
3
|
+
* Authentication is now handled at the SDK core level for better scalability
|
|
4
|
+
*/
|
|
5
|
+
import { HttpClient } from './core/abstractions/http-client';
|
|
6
|
+
import { PersConfig } from './core/pers-config';
|
|
7
|
+
import { PersApiClient } from './core/pers-api-client';
|
|
8
|
+
/**
|
|
9
|
+
* Minimal PERS SDK - API client with authentication built-in
|
|
10
|
+
* Platform adapters provide auth providers and HTTP clients
|
|
11
|
+
*/
|
|
12
|
+
export declare class PersSDK {
|
|
13
|
+
private apiClient;
|
|
14
|
+
constructor(httpClient: HttpClient, config: PersConfig);
|
|
15
|
+
/**
|
|
16
|
+
* Get the API client for direct PERS API calls
|
|
17
|
+
* This is the main interface - keep it simple!
|
|
18
|
+
*/
|
|
19
|
+
api(): PersApiClient;
|
|
20
|
+
/**
|
|
21
|
+
* Quick config check
|
|
22
|
+
*/
|
|
23
|
+
isProduction(): boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Simple factory function
|
|
27
|
+
*/
|
|
28
|
+
export declare function createPersSDK(httpClient: HttpClient, config: PersConfig): PersSDK;
|
|
29
|
+
//# sourceMappingURL=pers-sdk.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pers-sdk.d.ts","sourceRoot":"","sources":["../src/pers-sdk.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD;;;GAGG;AACH,qBAAa,OAAO;IAClB,OAAO,CAAC,SAAS,CAAgB;gBAErB,UAAU,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU;IAItD;;;OAGG;IACH,GAAG,IAAI,aAAa;IAIpB;;OAEG;IACH,YAAY,IAAI,OAAO;CAGxB;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,UAAU,GACjB,OAAO,CAET"}
|