@explorins/pers-sdk 1.1.0-beta.0 → 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/dist/analytics/index.d.ts +28 -0
- 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/{src/business/models/index.ts → dist/business/models/index.d.ts} +8 -13
- 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/dist/donation/models/index.d.ts +8 -0
- 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/dist/user/models/index.d.ts +12 -0
- 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/dist/user-status/models/index.d.ts +8 -0
- 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/dist/web3-chain/models/index.d.ts +38 -0
- 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 +105 -17
- package/explorins-pers-sdk-1.0.0-alpha.1.tgz +0 -0
- package/rollup.config.js +0 -84
- package/src/business/api/business-api.ts +0 -72
- package/src/business/business/tsconfig.json +0 -18
- package/src/business/index.ts +0 -52
- package/src/business/services/business-service.ts +0 -88
- package/src/core/abstractions/core-interfaces.ts +0 -56
- package/src/core/abstractions/http-client.ts +0 -23
- 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/core.ts +0 -30
- package/src/core/pers-api-client.ts +0 -151
- package/src/core/pers-config.ts +0 -38
- package/src/core.ts +0 -30
- package/src/index.ts +0 -16
- package/src/pers-sdk.ts +0 -45
- package/tsconfig.json +0 -28
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
import { AuthProvider } 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): AuthProvider {
|
|
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/core.ts
DELETED
|
@@ -1,30 +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
|
|
11
|
-
export * from './pers-config';
|
|
12
|
-
|
|
13
|
-
// Authentication interfaces
|
|
14
|
-
export {
|
|
15
|
-
AuthProvider,
|
|
16
|
-
SimpleAuthConfig,
|
|
17
|
-
createAuthProvider,
|
|
18
|
-
createBrowserTokenProvider,
|
|
19
|
-
createNodeTokenProvider
|
|
20
|
-
} from './auth/auth-provider.interface';
|
|
21
|
-
export type { RequestOptions as AuthRequestOptions } from './auth/auth-provider.interface';
|
|
22
|
-
|
|
23
|
-
// Platform abstractions
|
|
24
|
-
export * from './abstractions/http-client';
|
|
25
|
-
|
|
26
|
-
// Main SDK class
|
|
27
|
-
export * from '../pers-sdk';
|
|
28
|
-
|
|
29
|
-
// Version
|
|
30
|
-
export const PERS_SDK_VERSION = '1.0.0-alpha.1';
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* PERS API Client - Core platform-agnostic client for PERS backend
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { HttpClient, RequestOptions } from './abstractions/http-client';
|
|
6
|
-
import { PersConfig, buildApiRoot } from './pers-config';
|
|
7
|
-
|
|
8
|
-
export class PersApiClient {
|
|
9
|
-
private readonly apiRoot: string;
|
|
10
|
-
|
|
11
|
-
constructor(
|
|
12
|
-
private httpClient: HttpClient,
|
|
13
|
-
private config: PersConfig
|
|
14
|
-
) {
|
|
15
|
-
// Build API root from environment and version
|
|
16
|
-
this.apiRoot = buildApiRoot(config.environment, config.apiVersion);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Get request headers including auth token and project key
|
|
21
|
-
*/
|
|
22
|
-
private async getHeaders(): Promise<Record<string, string>> {
|
|
23
|
-
const headers: Record<string, string> = {
|
|
24
|
-
'Content-Type': 'application/json',
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
// Add authentication token
|
|
28
|
-
if (this.config.authProvider) {
|
|
29
|
-
const token = await this.config.authProvider.getToken();
|
|
30
|
-
if (token) {
|
|
31
|
-
headers['Authorization'] = `Bearer ${token}`;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
// Add project key
|
|
36
|
-
if (this.config.authProvider) {
|
|
37
|
-
const projectKey = await this.config.authProvider.getProjectKey();
|
|
38
|
-
if (projectKey) {
|
|
39
|
-
headers['x-project-key'] = projectKey;
|
|
40
|
-
}
|
|
41
|
-
} else {
|
|
42
|
-
// Fallback to config project key if no auth provider
|
|
43
|
-
headers['x-project-key'] = this.config.apiProjectKey;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return headers;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Make a request with proper headers, auth, and error handling
|
|
51
|
-
*/
|
|
52
|
-
private async request<T>(
|
|
53
|
-
method: 'GET' | 'POST' | 'PUT' | 'DELETE',
|
|
54
|
-
endpoint: string,
|
|
55
|
-
body?: any,
|
|
56
|
-
options?: { retryCount?: number }
|
|
57
|
-
): Promise<T> {
|
|
58
|
-
const { retryCount = 0 } = options || {};
|
|
59
|
-
const url = `${this.apiRoot}${endpoint}`;
|
|
60
|
-
|
|
61
|
-
const requestOptions: RequestOptions = {
|
|
62
|
-
headers: await this.getHeaders(),
|
|
63
|
-
timeout: this.config.timeout || 30000,
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
try {
|
|
67
|
-
switch (method) {
|
|
68
|
-
case 'GET':
|
|
69
|
-
return await this.httpClient.get<T>(url, requestOptions);
|
|
70
|
-
case 'POST':
|
|
71
|
-
return await this.httpClient.post<T>(url, body, requestOptions);
|
|
72
|
-
case 'PUT':
|
|
73
|
-
return await this.httpClient.put<T>(url, body, requestOptions);
|
|
74
|
-
case 'DELETE':
|
|
75
|
-
return await this.httpClient.delete<T>(url, requestOptions);
|
|
76
|
-
default:
|
|
77
|
-
throw new Error(`Unsupported HTTP method: ${method}`);
|
|
78
|
-
}
|
|
79
|
-
} catch (error: any) {
|
|
80
|
-
// Handle 401 errors with automatic token refresh
|
|
81
|
-
if (error.status === 401 && retryCount === 0 && this.config.authProvider?.onTokenExpired) {
|
|
82
|
-
try {
|
|
83
|
-
await this.config.authProvider.onTokenExpired();
|
|
84
|
-
// Retry once with refreshed token
|
|
85
|
-
return this.request<T>(method, endpoint, body, { ...options, retryCount: 1 });
|
|
86
|
-
} catch (refreshError) {
|
|
87
|
-
throw new PersApiError(
|
|
88
|
-
`Authentication refresh failed: ${refreshError}`,
|
|
89
|
-
endpoint,
|
|
90
|
-
method,
|
|
91
|
-
401
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
throw new PersApiError(
|
|
97
|
-
`PERS API request failed: ${error.message || error}`,
|
|
98
|
-
endpoint,
|
|
99
|
-
method,
|
|
100
|
-
error.status
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Generic GET request
|
|
107
|
-
*/
|
|
108
|
-
async get<T>(endpoint: string): Promise<T> {
|
|
109
|
-
return this.request<T>('GET', endpoint);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* Generic POST request
|
|
114
|
-
*/
|
|
115
|
-
async post<T>(endpoint: string, body?: any): Promise<T> {
|
|
116
|
-
return this.request<T>('POST', endpoint, body);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Generic PUT request
|
|
121
|
-
*/
|
|
122
|
-
async put<T>(endpoint: string, body?: any): Promise<T> {
|
|
123
|
-
return this.request<T>('PUT', endpoint, body);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Generic DELETE request
|
|
128
|
-
*/
|
|
129
|
-
async delete<T>(endpoint: string): Promise<T> {
|
|
130
|
-
return this.request<T>('DELETE', endpoint);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* Get current configuration
|
|
135
|
-
*/
|
|
136
|
-
getConfig(): PersConfig {
|
|
137
|
-
return this.config;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export class PersApiError extends Error {
|
|
142
|
-
constructor(
|
|
143
|
-
message: string,
|
|
144
|
-
public endpoint: string,
|
|
145
|
-
public method: string,
|
|
146
|
-
public statusCode?: number
|
|
147
|
-
) {
|
|
148
|
-
super(message);
|
|
149
|
-
this.name = 'PersApiError';
|
|
150
|
-
}
|
|
151
|
-
}
|
package/src/core/pers-config.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* PERS SDK Configuration interfaces
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import { AuthProvider } 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?: AuthProvider;
|
|
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
|
-
* Internal function to construct API root from environment
|
|
28
|
-
*/
|
|
29
|
-
|
|
30
|
-
export function buildApiRoot(environment: PersEnvironment, version: PersApiVersion = 'v2'): string {
|
|
31
|
-
const baseUrls = {
|
|
32
|
-
development: 'https://explorins-loyalty.ngrok.io',
|
|
33
|
-
staging: `https://dev.api.pers.ninja/${version}`,
|
|
34
|
-
production: `https://dev.api.pers.ninja/${version}`
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
return `${baseUrls[environment]}`;
|
|
38
|
-
}
|
package/src/core.ts
DELETED
|
@@ -1,30 +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 './core/pers-api-client';
|
|
9
|
-
|
|
10
|
-
// Configuration interfaces
|
|
11
|
-
export * from './core/pers-config';
|
|
12
|
-
|
|
13
|
-
// Authentication interfaces
|
|
14
|
-
export {
|
|
15
|
-
AuthProvider,
|
|
16
|
-
SimpleAuthConfig,
|
|
17
|
-
createAuthProvider,
|
|
18
|
-
createBrowserTokenProvider,
|
|
19
|
-
createNodeTokenProvider
|
|
20
|
-
} from './core/auth/auth-provider.interface';
|
|
21
|
-
export type { RequestOptions as AuthRequestOptions } from './core/auth/auth-provider.interface';
|
|
22
|
-
|
|
23
|
-
// Platform abstractions
|
|
24
|
-
export * from './core/abstractions/http-client';
|
|
25
|
-
|
|
26
|
-
// Main SDK class
|
|
27
|
-
export * from './pers-sdk';
|
|
28
|
-
|
|
29
|
-
// Version
|
|
30
|
-
export const PERS_SDK_VERSION = '1.0.0-alpha.1';
|
package/src/index.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @explorins/pers-sdk - Main Entry Point
|
|
3
|
-
*
|
|
4
|
-
* Platform-agnostic PERS SDK - Core and Business domains only
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
// Re-export everything from core
|
|
8
|
-
export * from './core/core';
|
|
9
|
-
|
|
10
|
-
// Re-export everything from business domain
|
|
11
|
-
export * from './business';
|
|
12
|
-
|
|
13
|
-
// NOTE: Angular integration available in separate package '@explorins/pers-sdk-angular'
|
|
14
|
-
// Future domains will be added here
|
|
15
|
-
// export * from './campaign';
|
|
16
|
-
// export * from './challenge';
|
package/src/pers-sdk.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
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
|
-
|
|
6
|
-
import { HttpClient } from './core/abstractions/http-client';
|
|
7
|
-
import { PersConfig } from './core/pers-config';
|
|
8
|
-
import { PersApiClient } from './core/pers-api-client';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Minimal PERS SDK - API client with authentication built-in
|
|
12
|
-
* Platform adapters provide auth providers and HTTP clients
|
|
13
|
-
*/
|
|
14
|
-
export class PersSDK {
|
|
15
|
-
private apiClient: PersApiClient;
|
|
16
|
-
|
|
17
|
-
constructor(httpClient: HttpClient, config: PersConfig) {
|
|
18
|
-
this.apiClient = new PersApiClient(httpClient, config);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Get the API client for direct PERS API calls
|
|
23
|
-
* This is the main interface - keep it simple!
|
|
24
|
-
*/
|
|
25
|
-
api(): PersApiClient {
|
|
26
|
-
return this.apiClient;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Quick config check
|
|
31
|
-
*/
|
|
32
|
-
isProduction(): boolean {
|
|
33
|
-
return this.apiClient.getConfig().environment === 'production';
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Simple factory function
|
|
39
|
-
*/
|
|
40
|
-
export function createPersSDK(
|
|
41
|
-
httpClient: HttpClient,
|
|
42
|
-
config: PersConfig
|
|
43
|
-
): PersSDK {
|
|
44
|
-
return new PersSDK(httpClient, config);
|
|
45
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2020",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"moduleResolution": "node",
|
|
6
|
-
"strict": true,
|
|
7
|
-
"esModuleInterop": true,
|
|
8
|
-
"skipLibCheck": true,
|
|
9
|
-
"forceConsistentCasingInFileNames": true,
|
|
10
|
-
"declaration": true,
|
|
11
|
-
"declarationMap": true,
|
|
12
|
-
"sourceMap": true,
|
|
13
|
-
"outDir": "./dist",
|
|
14
|
-
"baseUrl": ".",
|
|
15
|
-
"paths": {
|
|
16
|
-
"@explorins/pers-shared": ["../../framework/entities"]
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
"include": [
|
|
20
|
-
"src/**/*"
|
|
21
|
-
],
|
|
22
|
-
"exclude": [
|
|
23
|
-
"node_modules",
|
|
24
|
-
"dist",
|
|
25
|
-
"**/*.test.ts",
|
|
26
|
-
"**/*.spec.ts"
|
|
27
|
-
]
|
|
28
|
-
}
|