iom-sdk 0.1.8 → 0.1.10
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/client.d.ts +43 -94
- package/dist/config/index.d.ts +1 -0
- package/dist/config/service-config.d.ts +93 -0
- package/dist/core/auth-manager.d.ts +110 -0
- package/dist/core/base-service-client.d.ts +81 -0
- package/dist/core/index.d.ts +3 -1
- package/dist/core/logger.d.ts +8 -2
- package/dist/core/service-factory.d.ts +59 -0
- package/dist/core/token-storage.d.ts +63 -0
- package/dist/index.d.ts +7 -2064
- package/dist/index.esm.js +1 -1
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/services/auth/auth-client.d.ts +10 -0
- package/dist/services/auth/index.d.ts +1 -0
- package/dist/services/index.d.ts +7 -9
- package/dist/services/node/index.d.ts +1 -0
- package/dist/services/node/node-client.d.ts +86 -0
- package/dist/services/registry/index.d.ts +1 -0
- package/dist/services/registry/registry-client.d.ts +33 -0
- package/dist/types/aggregates.d.ts +260 -0
- package/dist/types/auth.d.ts +62 -0
- package/dist/types/config.d.ts +5 -0
- package/dist/types/index.d.ts +6 -455
- package/dist/types/services.d.ts +148 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/jwt-utils.d.ts +42 -0
- package/package.json +8 -10
- package/dist/core/http-client.d.ts +0 -32
- package/dist/facade/address-facade.d.ts +0 -62
- package/dist/facade/aggregate-facade.d.ts +0 -59
- package/dist/facade/common-facade.d.ts +0 -33
- package/dist/facade/file-facade.d.ts +0 -84
- package/dist/facade/index.d.ts +0 -6
- package/dist/facade/object-facade.d.ts +0 -19
- package/dist/facade/property-facade.d.ts +0 -39
- package/dist/facade/property-value-facade.d.ts +0 -37
- package/dist/services/address-service.d.ts +0 -87
- package/dist/services/aggregate-service.d.ts +0 -69
- package/dist/services/common-service.d.ts +0 -33
- package/dist/services/file-service.d.ts +0 -84
- package/dist/services/object-service.d.ts +0 -50
- package/dist/services/property-service.d.ts +0 -68
- package/dist/services/property-value-service.d.ts +0 -50
- package/dist/services/statement-service.d.ts +0 -175
- package/dist/services/uuid-service.d.ts +0 -97
package/dist/client.d.ts
CHANGED
|
@@ -1,96 +1,45 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AxiosInstance } from 'axios';
|
|
2
|
+
import { SDKConfig } from './config';
|
|
3
|
+
import { AuthServiceClient } from './services/auth/auth-client';
|
|
4
|
+
import { RegistryServiceClient } from './services/registry/registry-client';
|
|
5
|
+
import { NodeServiceClient } from './services/node/node-client';
|
|
6
|
+
import { AuthResponse } from './types';
|
|
7
|
+
export type AuthChangeListener = (state: {
|
|
8
|
+
isAuthenticated: boolean;
|
|
9
|
+
user: AuthResponse | null;
|
|
10
|
+
}) => void;
|
|
2
11
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* @param config - Client configuration including baseUrl and optional certificate
|
|
12
|
+
* Simplified IOM Client
|
|
13
|
+
* acts as the single source of truth for auth state
|
|
6
14
|
*/
|
|
7
|
-
export declare
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
delete: (uuid: UUID) => Promise<import("./types").ApiResponse<any>>;
|
|
39
|
-
};
|
|
40
|
-
values: {
|
|
41
|
-
setForProperty: (propertyUuid: UUID, value: Partial<UUPropertyValueDTO>) => Promise<import("./types").ApiResponse<UUPropertyValueDTO>>;
|
|
42
|
-
create: (value: UUPropertyValueDTO) => Promise<import("./types").ApiResponse<UUPropertyValueDTO>>;
|
|
43
|
-
getPropertyValues: (params?: QueryParams) => Promise<import("./types").ApiResponse<UUPropertyValueDTO[]>>;
|
|
44
|
-
delete: (uuid: UUID) => Promise<import("./types").ApiResponse<any>>;
|
|
45
|
-
};
|
|
46
|
-
files: {
|
|
47
|
-
create: (file: UUFileDTO) => Promise<import("./types").ApiResponse<UUFileDTO>>;
|
|
48
|
-
getFiles: (params?: QueryParams) => Promise<import("./types").ApiResponse<UUFileDTO[]>>;
|
|
49
|
-
delete: (uuid: UUID) => Promise<import("./types").ApiResponse<any>>;
|
|
50
|
-
uploadByReference: (input: {
|
|
51
|
-
fileReference: string;
|
|
52
|
-
uuidToAttach: UUID;
|
|
53
|
-
label?: string;
|
|
54
|
-
}) => Promise<import("./types").ApiResponse<UUFileDTO | null>>;
|
|
55
|
-
uploadDirect: (input: {
|
|
56
|
-
file: File | Blob | ArrayBuffer | FormData;
|
|
57
|
-
uuidToAttach: UUID;
|
|
58
|
-
}) => Promise<import("./types").ApiResponse<UUFileDTO | null>>;
|
|
59
|
-
uploadFormData: (input: {
|
|
60
|
-
formData: FormData;
|
|
61
|
-
uuidFile: UUID;
|
|
62
|
-
uuidToAttach: UUID;
|
|
63
|
-
}) => Promise<import("./types").ApiResponse<any>>;
|
|
64
|
-
download: (uuid: UUID) => Promise<import("./types").ApiResponse<ArrayBuffer>>;
|
|
65
|
-
};
|
|
66
|
-
statements: {
|
|
67
|
-
getStatements: (params?: StatementQueryParams) => Promise<import("./types").ApiResponse<UUStatementDTO[]>>;
|
|
68
|
-
create: (statement: UUStatementDTO) => Promise<import("./types").ApiResponse<UUStatementDTO>>;
|
|
69
|
-
delete: (statement: UUStatementDTO) => Promise<import("./types").ApiResponse<any>>;
|
|
70
|
-
};
|
|
71
|
-
uuid: {
|
|
72
|
-
create: () => Promise<import("./types").ApiResponse<{
|
|
73
|
-
uuid: UUID;
|
|
74
|
-
}>>;
|
|
75
|
-
getOwned: () => Promise<import("./types").ApiResponse<any>>;
|
|
76
|
-
getRecord: (uuid: UUID) => Promise<import("./types").ApiResponse<any>>;
|
|
77
|
-
updateRecordMeta: (params: {
|
|
78
|
-
uuid?: UUID;
|
|
79
|
-
nodeType: string;
|
|
80
|
-
}) => Promise<import("./types").ApiResponse<any>>;
|
|
81
|
-
authorize: (params: {
|
|
82
|
-
userUUID: UUID;
|
|
83
|
-
resourceId: UUID;
|
|
84
|
-
}) => Promise<import("./types").ApiResponse<any>>;
|
|
85
|
-
};
|
|
86
|
-
addresses: {
|
|
87
|
-
create: (address: Omit<UUAddressDTO, "uuid">) => Promise<import("./types").ApiResponse<UUAddressDTO>>;
|
|
88
|
-
update: (address: UUAddressDTO) => Promise<import("./types").ApiResponse<UUAddressDTO>>;
|
|
89
|
-
get: (params?: QueryParams) => Promise<import("./types").ApiResponse<UUAddressDTO[]>>;
|
|
90
|
-
delete: (uuid: UUID) => Promise<import("./types").ApiResponse<any>>;
|
|
91
|
-
createForObject: (objectUuid: UUID, address: Omit<UUAddressDTO, "uuid">) => Promise<import("./types").ApiResponse<{
|
|
92
|
-
address: UUAddressDTO;
|
|
93
|
-
statement: any;
|
|
94
|
-
}>>;
|
|
95
|
-
};
|
|
96
|
-
};
|
|
15
|
+
export declare class Client {
|
|
16
|
+
private config;
|
|
17
|
+
private axiosInstance;
|
|
18
|
+
private token;
|
|
19
|
+
private user;
|
|
20
|
+
private listeners;
|
|
21
|
+
auth: AuthServiceClient;
|
|
22
|
+
registry: RegistryServiceClient;
|
|
23
|
+
node: NodeServiceClient;
|
|
24
|
+
private readonly STORAGE_KEY;
|
|
25
|
+
constructor(config: SDKConfig);
|
|
26
|
+
private createServiceAxiosInstance;
|
|
27
|
+
private loadState;
|
|
28
|
+
private saveState;
|
|
29
|
+
private notifyListeners;
|
|
30
|
+
onAuthStateChange(listener: AuthChangeListener): () => void;
|
|
31
|
+
login(): Promise<{
|
|
32
|
+
success: boolean;
|
|
33
|
+
user?: AuthResponse;
|
|
34
|
+
}>;
|
|
35
|
+
logout(): void;
|
|
36
|
+
isAuthenticated(): boolean;
|
|
37
|
+
getUser(): AuthResponse | null;
|
|
38
|
+
getToken(): string | null;
|
|
39
|
+
getAxios(): AxiosInstance;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Initialize the Client
|
|
43
|
+
*/
|
|
44
|
+
export declare function initClient(config: SDKConfig): Client;
|
|
45
|
+
export declare const createClient: typeof initClient;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './service-config';
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service configuration interfaces for the IOB SDK
|
|
3
|
+
* Provides type-safe configuration for individual services
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Configuration for an individual service
|
|
7
|
+
*/
|
|
8
|
+
export interface ServiceConfig {
|
|
9
|
+
/** Base URL for the service */
|
|
10
|
+
baseUrl: string;
|
|
11
|
+
/** Request timeout in milliseconds (default: 30000) */
|
|
12
|
+
timeout?: number;
|
|
13
|
+
/** Number of retry attempts for failed requests (default: 3) */
|
|
14
|
+
retries?: number;
|
|
15
|
+
/** Additional headers to include with requests */
|
|
16
|
+
headers?: Record<string, string>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Error handling configuration
|
|
20
|
+
*/
|
|
21
|
+
export interface ErrorHandlingConfig {
|
|
22
|
+
/** Global handler for authentication errors */
|
|
23
|
+
onAuthError?: (error: SDKError) => void;
|
|
24
|
+
/** Global handler for network errors */
|
|
25
|
+
onNetworkError?: (error: SDKError) => void;
|
|
26
|
+
/** Global handler for service-specific errors */
|
|
27
|
+
onServiceError?: (error: SDKError, service: string) => void;
|
|
28
|
+
/** Enable debug logging for requests/responses */
|
|
29
|
+
debug?: boolean;
|
|
30
|
+
/** Automatically retry authentication failures */
|
|
31
|
+
autoRetryAuth?: boolean;
|
|
32
|
+
/** Network retry configuration */
|
|
33
|
+
autoRetryNetwork?: {
|
|
34
|
+
maxRetries: number;
|
|
35
|
+
delay?: number;
|
|
36
|
+
backoff?: 'linear' | 'exponential';
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* SDK Error interface with service context
|
|
41
|
+
*/
|
|
42
|
+
export interface SDKError extends Error {
|
|
43
|
+
/** Service that generated the error */
|
|
44
|
+
service?: string;
|
|
45
|
+
/** Error type classification */
|
|
46
|
+
type?: 'authentication' | 'network' | 'validation' | 'service' | 'unknown';
|
|
47
|
+
/** HTTP status code if applicable */
|
|
48
|
+
status?: number;
|
|
49
|
+
/** Additional error details */
|
|
50
|
+
details?: any;
|
|
51
|
+
/** Request context */
|
|
52
|
+
context?: {
|
|
53
|
+
method: string;
|
|
54
|
+
url: string;
|
|
55
|
+
timestamp: Date;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Main SDK configuration interface
|
|
60
|
+
*/
|
|
61
|
+
export interface SDKConfig {
|
|
62
|
+
/** Auth service configuration */
|
|
63
|
+
auth: ServiceConfig;
|
|
64
|
+
/** Registry/UUID service configuration */
|
|
65
|
+
registry: ServiceConfig;
|
|
66
|
+
/** Node service configuration */
|
|
67
|
+
node: ServiceConfig;
|
|
68
|
+
/** Client certificate for mTLS authentication (optional - browser will handle cert selection) */
|
|
69
|
+
certificate?: {
|
|
70
|
+
cert: string;
|
|
71
|
+
key: string;
|
|
72
|
+
};
|
|
73
|
+
/** Token storage strategy */
|
|
74
|
+
tokenStorage?: 'localStorage' | 'sessionStorage' | 'memory';
|
|
75
|
+
/** Error handling configuration */
|
|
76
|
+
errorHandling?: ErrorHandlingConfig;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Validates a service configuration
|
|
80
|
+
*/
|
|
81
|
+
export declare function validateServiceConfig(config: ServiceConfig, serviceName: string): void;
|
|
82
|
+
/**
|
|
83
|
+
* Validates the complete SDK configuration
|
|
84
|
+
*/
|
|
85
|
+
export declare function validateSDKConfig(config: SDKConfig): void;
|
|
86
|
+
/**
|
|
87
|
+
* Creates a default service configuration with sensible defaults
|
|
88
|
+
*/
|
|
89
|
+
export declare function createDefaultServiceConfig(baseUrl: string): ServiceConfig;
|
|
90
|
+
/**
|
|
91
|
+
* Creates default error handling configuration
|
|
92
|
+
*/
|
|
93
|
+
export declare function createDefaultErrorHandling(): ErrorHandlingConfig;
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { JWTToken, JWTAuthResponse, TokenRefreshConfig, AuthState } from '../types';
|
|
2
|
+
import { SDKConfig } from '../config';
|
|
3
|
+
import { TokenStorage } from './token-storage';
|
|
4
|
+
/**
|
|
5
|
+
* Central JWT token management system with persistent storage
|
|
6
|
+
* Handles token storage, validation, and automatic refresh
|
|
7
|
+
*/
|
|
8
|
+
export declare class AuthManager {
|
|
9
|
+
private config;
|
|
10
|
+
private loginFunction;
|
|
11
|
+
private tokenStorage;
|
|
12
|
+
private authState;
|
|
13
|
+
private refreshConfig;
|
|
14
|
+
private refreshPromise;
|
|
15
|
+
private refreshTimeoutId;
|
|
16
|
+
private readyPromise;
|
|
17
|
+
private stateListeners;
|
|
18
|
+
constructor(config: SDKConfig, loginFunction: () => Promise<JWTAuthResponse>, tokenStorage: TokenStorage, refreshConfig?: Partial<TokenRefreshConfig>);
|
|
19
|
+
/**
|
|
20
|
+
* Wait for AuthManager to be ready (storage initialized)
|
|
21
|
+
* Prevents race conditions where isAuthenticated() is called before storage is checked
|
|
22
|
+
*/
|
|
23
|
+
ready(): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Initialize auth state from stored token and user data
|
|
26
|
+
*/
|
|
27
|
+
private initializeFromStorage;
|
|
28
|
+
/**
|
|
29
|
+
* Get the current JWT token, refreshing if necessary
|
|
30
|
+
* Does NOT perform initial authentication - user must call login() first
|
|
31
|
+
*/
|
|
32
|
+
getValidToken(): Promise<string | null>;
|
|
33
|
+
/**
|
|
34
|
+
* Public method for user-initiated login
|
|
35
|
+
* Call this when user clicks "Authorize/Login" button
|
|
36
|
+
*/
|
|
37
|
+
login(): Promise<JWTToken | null>;
|
|
38
|
+
/**
|
|
39
|
+
* Public method for user-initiated logout
|
|
40
|
+
* Call this when user clicks "Logout" button
|
|
41
|
+
*/
|
|
42
|
+
logout(): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Perform initial authentication to get JWT token
|
|
45
|
+
* Private method - use login() for user-initiated authentication
|
|
46
|
+
* Fails fast - no retries, no loops
|
|
47
|
+
*/
|
|
48
|
+
private authenticate;
|
|
49
|
+
/**
|
|
50
|
+
* Refresh the current JWT token
|
|
51
|
+
*/
|
|
52
|
+
refreshToken(): Promise<JWTToken | null>;
|
|
53
|
+
/**
|
|
54
|
+
* Perform the actual token refresh - single attempt, no retries
|
|
55
|
+
*/
|
|
56
|
+
private performTokenRefresh;
|
|
57
|
+
/**
|
|
58
|
+
* Check if the current user is authenticated
|
|
59
|
+
*/
|
|
60
|
+
isAuthenticated(): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Get the current authentication state
|
|
63
|
+
*/
|
|
64
|
+
getAuthState(): Readonly<AuthState>;
|
|
65
|
+
/**
|
|
66
|
+
* Subscribe to auth state changes
|
|
67
|
+
*/
|
|
68
|
+
onAuthStateChange(listener: (state: Readonly<AuthState>) => void): () => void;
|
|
69
|
+
/**
|
|
70
|
+
* Clear the current token and authentication state
|
|
71
|
+
*/
|
|
72
|
+
clearToken(): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Force token refresh on next request
|
|
75
|
+
*/
|
|
76
|
+
invalidateToken(): void;
|
|
77
|
+
/**
|
|
78
|
+
* Create a JWTToken from the auth response
|
|
79
|
+
*/
|
|
80
|
+
private createTokenFromResponse;
|
|
81
|
+
/**
|
|
82
|
+
* Set the current token and update auth state
|
|
83
|
+
*/
|
|
84
|
+
private setToken;
|
|
85
|
+
/**
|
|
86
|
+
* Check if a token is still valid (not expired)
|
|
87
|
+
*/
|
|
88
|
+
private isTokenValid;
|
|
89
|
+
/**
|
|
90
|
+
* Check if a token is expired
|
|
91
|
+
*/
|
|
92
|
+
private isTokenExpired;
|
|
93
|
+
/**
|
|
94
|
+
* Check if a token should be refreshed (within threshold of expiry)
|
|
95
|
+
*/
|
|
96
|
+
private shouldRefreshToken;
|
|
97
|
+
/**
|
|
98
|
+
* Schedule automatic token refresh
|
|
99
|
+
*/
|
|
100
|
+
private scheduleTokenRefresh;
|
|
101
|
+
private notifyAuthStateChange;
|
|
102
|
+
/**
|
|
103
|
+
* Cleanup resources
|
|
104
|
+
*/
|
|
105
|
+
destroy(): void;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Create a new AuthManager instance
|
|
109
|
+
*/
|
|
110
|
+
export declare const createAuthManager: (config: SDKConfig, loginFunction: () => Promise<JWTAuthResponse>, tokenStorage: TokenStorage, refreshConfig?: Partial<TokenRefreshConfig>) => AuthManager;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base service client with common functionality
|
|
3
|
+
* Provides HTTP operations, error handling, and retry logic
|
|
4
|
+
*/
|
|
5
|
+
import { AxiosInstance, AxiosRequestConfig, AxiosResponse } from 'axios';
|
|
6
|
+
import { ServiceConfig, SDKError, ErrorHandlingConfig } from '../config';
|
|
7
|
+
import { ApiResponse } from '../types';
|
|
8
|
+
/**
|
|
9
|
+
* Base service client class
|
|
10
|
+
*/
|
|
11
|
+
export declare abstract class BaseServiceClient {
|
|
12
|
+
protected client: AxiosInstance;
|
|
13
|
+
protected config: ServiceConfig;
|
|
14
|
+
protected errorHandling: ErrorHandlingConfig;
|
|
15
|
+
protected serviceName: string;
|
|
16
|
+
constructor(config: ServiceConfig, errorHandling: ErrorHandlingConfig, serviceName: string, certificate?: {
|
|
17
|
+
cert: string;
|
|
18
|
+
key: string;
|
|
19
|
+
});
|
|
20
|
+
/**
|
|
21
|
+
* Setup request and response interceptors
|
|
22
|
+
*/
|
|
23
|
+
protected setupInterceptors(): void;
|
|
24
|
+
/**
|
|
25
|
+
* Create standardized SDK error from axios error
|
|
26
|
+
*/
|
|
27
|
+
protected createSDKError(error: any): SDKError;
|
|
28
|
+
/**
|
|
29
|
+
* Handle error with global handlers
|
|
30
|
+
*/
|
|
31
|
+
protected handleError(error: SDKError): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Determine if request should be retried
|
|
34
|
+
*/
|
|
35
|
+
protected shouldRetry(error: SDKError): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Retry failed request with backoff
|
|
38
|
+
*/
|
|
39
|
+
protected retryRequest(config: AxiosRequestConfig, error: SDKError): Promise<AxiosResponse>;
|
|
40
|
+
/**
|
|
41
|
+
* Make GET request
|
|
42
|
+
*/
|
|
43
|
+
protected get<T>(url: string, params?: Record<string, any>): Promise<ApiResponse<T>>;
|
|
44
|
+
/**
|
|
45
|
+
* Make POST request
|
|
46
|
+
*/
|
|
47
|
+
protected post<T>(url: string, data?: any, config?: AxiosRequestConfig): Promise<ApiResponse<T>>;
|
|
48
|
+
/**
|
|
49
|
+
* Make PUT request
|
|
50
|
+
*/
|
|
51
|
+
protected put<T>(url: string, data?: any): Promise<ApiResponse<T>>;
|
|
52
|
+
/**
|
|
53
|
+
* Make DELETE request
|
|
54
|
+
*/
|
|
55
|
+
protected delete<T>(url: string, data?: any): Promise<ApiResponse<T>>;
|
|
56
|
+
/**
|
|
57
|
+
* Make GET request for binary data
|
|
58
|
+
*/
|
|
59
|
+
protected getBinary<T = ArrayBuffer>(url: string): Promise<ApiResponse<T>>;
|
|
60
|
+
/**
|
|
61
|
+
* Make POST request with form data
|
|
62
|
+
*/
|
|
63
|
+
protected postForm<T>(url: string, formData: any): Promise<ApiResponse<T>>;
|
|
64
|
+
/**
|
|
65
|
+
* Create standardized API response
|
|
66
|
+
*/
|
|
67
|
+
protected createApiResponse<T>(response: AxiosResponse): ApiResponse<T>;
|
|
68
|
+
/**
|
|
69
|
+
* Add authorization header
|
|
70
|
+
*/
|
|
71
|
+
protected setAuthorizationHeader(token: string): void;
|
|
72
|
+
/**
|
|
73
|
+
* Remove authorization header
|
|
74
|
+
*/
|
|
75
|
+
protected removeAuthorizationHeader(): void;
|
|
76
|
+
}
|
|
77
|
+
declare module 'axios' {
|
|
78
|
+
interface AxiosRequestConfig {
|
|
79
|
+
_retryCount?: number;
|
|
80
|
+
}
|
|
81
|
+
}
|
package/dist/core/index.d.ts
CHANGED
package/dist/core/logger.d.ts
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
interface DebugConfig {
|
|
2
|
+
enabled: boolean;
|
|
3
|
+
logLevel?: 'error' | 'info';
|
|
4
|
+
logToConsole?: boolean;
|
|
5
|
+
logCallback?: (message: string, data?: any) => void;
|
|
6
|
+
}
|
|
2
7
|
/**
|
|
3
8
|
* Configure the logger with the provided debug options
|
|
4
9
|
*/
|
|
5
|
-
export declare const configureLogger: (config?:
|
|
10
|
+
export declare const configureLogger: (config?: DebugConfig) => void;
|
|
6
11
|
/**
|
|
7
12
|
* Log a message if debug is enabled
|
|
8
13
|
*/
|
|
@@ -15,3 +20,4 @@ export declare const logHttp: (method: string, url: string, status?: number, dat
|
|
|
15
20
|
* Log error information
|
|
16
21
|
*/
|
|
17
22
|
export declare const logError: (operation: string, error: any) => void;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service factory for creating individual service clients
|
|
3
|
+
* Implements factory pattern with dependency injection
|
|
4
|
+
*/
|
|
5
|
+
import { SDKConfig, ErrorHandlingConfig } from '../config';
|
|
6
|
+
import { AuthManager } from './auth-manager';
|
|
7
|
+
import { TokenStorage } from './token-storage';
|
|
8
|
+
import { AuthServiceClient } from '../services/auth/auth-client';
|
|
9
|
+
import { RegistryServiceClient } from '../services/registry/registry-client';
|
|
10
|
+
import { NodeServiceClient } from '../services/node/node-client';
|
|
11
|
+
/**
|
|
12
|
+
* Service factory class that manages service client creation and lifecycle
|
|
13
|
+
*/
|
|
14
|
+
export declare class ServiceFactory {
|
|
15
|
+
private config;
|
|
16
|
+
private errorHandling;
|
|
17
|
+
private tokenStorage;
|
|
18
|
+
private authManager;
|
|
19
|
+
private authClient?;
|
|
20
|
+
private registryClient?;
|
|
21
|
+
private nodeClient?;
|
|
22
|
+
constructor(config: SDKConfig);
|
|
23
|
+
/**
|
|
24
|
+
* Get or create auth service client
|
|
25
|
+
*/
|
|
26
|
+
getAuthClient(): AuthServiceClient;
|
|
27
|
+
/**
|
|
28
|
+
* Get or create registry service client
|
|
29
|
+
*/
|
|
30
|
+
getRegistryClient(): RegistryServiceClient;
|
|
31
|
+
/**
|
|
32
|
+
* Get or create node service client
|
|
33
|
+
*/
|
|
34
|
+
getNodeClient(): NodeServiceClient;
|
|
35
|
+
/**
|
|
36
|
+
* Get auth manager instance
|
|
37
|
+
*/
|
|
38
|
+
getAuthManager(): AuthManager;
|
|
39
|
+
/**
|
|
40
|
+
* Get token storage instance
|
|
41
|
+
*/
|
|
42
|
+
getTokenStorage(): TokenStorage;
|
|
43
|
+
/**
|
|
44
|
+
* Get current configuration
|
|
45
|
+
*/
|
|
46
|
+
getConfig(): SDKConfig;
|
|
47
|
+
/**
|
|
48
|
+
* Update error handling configuration
|
|
49
|
+
*/
|
|
50
|
+
updateErrorHandling(newConfig: Partial<ErrorHandlingConfig>): void;
|
|
51
|
+
/**
|
|
52
|
+
* Destroy all service clients and cleanup resources
|
|
53
|
+
*/
|
|
54
|
+
destroy(): void;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Create service factory with configuration validation
|
|
58
|
+
*/
|
|
59
|
+
export declare function createServiceFactory(config: SDKConfig): ServiceFactory;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token storage abstraction for persistent JWT token management
|
|
3
|
+
* Supports localStorage, sessionStorage, and memory storage with graceful fallbacks
|
|
4
|
+
*/
|
|
5
|
+
import { JWTToken, AuthResponse } from '../types';
|
|
6
|
+
/**
|
|
7
|
+
* Stored auth data including token and user info
|
|
8
|
+
*/
|
|
9
|
+
export interface StoredAuthData {
|
|
10
|
+
token: JWTToken;
|
|
11
|
+
user?: AuthResponse;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Storage interface for token persistence
|
|
15
|
+
*/
|
|
16
|
+
export interface TokenStorage {
|
|
17
|
+
/** Get stored token */
|
|
18
|
+
getToken(): Promise<JWTToken | null>;
|
|
19
|
+
/** Store token */
|
|
20
|
+
setToken(token: JWTToken): Promise<void>;
|
|
21
|
+
/** Remove stored token */
|
|
22
|
+
removeToken(): Promise<void>;
|
|
23
|
+
/** Check if storage is available */
|
|
24
|
+
isAvailable(): boolean;
|
|
25
|
+
/** Get stored auth data (token + user) */
|
|
26
|
+
getAuthData(): Promise<StoredAuthData | null>;
|
|
27
|
+
/** Store auth data (token + user) */
|
|
28
|
+
setAuthData(data: StoredAuthData): Promise<void>;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Storage type options
|
|
32
|
+
*/
|
|
33
|
+
export type StorageType = 'localStorage' | 'sessionStorage' | 'memory';
|
|
34
|
+
/**
|
|
35
|
+
* Creates appropriate token storage based on environment and preferences
|
|
36
|
+
*/
|
|
37
|
+
export declare function createTokenStorage(storageType?: StorageType, enableCrossTabSync?: boolean): TokenStorage;
|
|
38
|
+
/**
|
|
39
|
+
* Token storage with automatic cleanup
|
|
40
|
+
*/
|
|
41
|
+
export declare class ManagedTokenStorage implements TokenStorage {
|
|
42
|
+
private storage;
|
|
43
|
+
private cleanupInterval;
|
|
44
|
+
constructor(storage: TokenStorage, cleanupIntervalMs?: number);
|
|
45
|
+
isAvailable(): boolean;
|
|
46
|
+
getToken(): Promise<JWTToken | null>;
|
|
47
|
+
setToken(token: JWTToken): Promise<void>;
|
|
48
|
+
removeToken(): Promise<void>;
|
|
49
|
+
getAuthData(): Promise<StoredAuthData | null>;
|
|
50
|
+
setAuthData(data: StoredAuthData): Promise<void>;
|
|
51
|
+
/**
|
|
52
|
+
* Cleanup expired tokens
|
|
53
|
+
*/
|
|
54
|
+
private cleanup;
|
|
55
|
+
/**
|
|
56
|
+
* Destroy the storage and cleanup resources
|
|
57
|
+
*/
|
|
58
|
+
destroy(): void;
|
|
59
|
+
/**
|
|
60
|
+
* Add cross-tab synchronization listener if supported
|
|
61
|
+
*/
|
|
62
|
+
onTokenChange(listener: (token: JWTToken | null) => void): (() => void) | null;
|
|
63
|
+
}
|