@aifabrix/miso-client 1.8.0 → 1.9.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/README.md +63 -0
- package/dist/index.d.ts +216 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/{src/index.js → index.js} +103 -30
- package/dist/index.js.map +1 -0
- package/dist/{src/services → services}/auth.service.d.ts +13 -5
- package/dist/services/auth.service.d.ts.map +1 -0
- package/dist/{src/services → services}/auth.service.js +16 -8
- package/dist/services/auth.service.js.map +1 -0
- package/dist/services/cache.service.d.ts.map +1 -0
- package/dist/services/cache.service.js.map +1 -0
- package/dist/services/encryption.service.d.ts.map +1 -0
- package/dist/services/encryption.service.js.map +1 -0
- package/dist/services/logger.service.d.ts.map +1 -0
- package/dist/services/logger.service.js.map +1 -0
- package/dist/services/permission.service.d.ts +58 -0
- package/dist/services/permission.service.d.ts.map +1 -0
- package/dist/{src/services → services}/permission.service.js +29 -14
- package/dist/services/permission.service.js.map +1 -0
- package/dist/services/redis.service.d.ts.map +1 -0
- package/dist/services/redis.service.js.map +1 -0
- package/dist/services/role.service.d.ts +52 -0
- package/dist/services/role.service.d.ts.map +1 -0
- package/dist/{src/services → services}/role.service.js +25 -12
- package/dist/services/role.service.js.map +1 -0
- package/dist/{src/types → types}/config.types.d.ts +26 -0
- package/dist/types/config.types.d.ts.map +1 -0
- package/dist/types/config.types.js.map +1 -0
- package/dist/{src/types → types}/errors.types.d.ts +1 -1
- package/dist/types/errors.types.d.ts.map +1 -0
- package/dist/types/errors.types.js.map +1 -0
- package/dist/types/filter.types.d.ts.map +1 -0
- package/dist/types/filter.types.js.map +1 -0
- package/dist/types/pagination.types.d.ts.map +1 -0
- package/dist/types/pagination.types.js.map +1 -0
- package/dist/types/sort.types.d.ts.map +1 -0
- package/dist/types/sort.types.js.map +1 -0
- package/dist/utils/audit-log-queue.d.ts.map +1 -0
- package/dist/utils/audit-log-queue.js.map +1 -0
- package/dist/utils/auth-strategy.d.ts +38 -0
- package/dist/utils/auth-strategy.d.ts.map +1 -0
- package/dist/utils/auth-strategy.js +106 -0
- package/dist/utils/auth-strategy.js.map +1 -0
- package/dist/utils/config-loader.d.ts.map +1 -0
- package/dist/{src/utils → utils}/config-loader.js +19 -0
- package/dist/utils/config-loader.js.map +1 -0
- package/dist/utils/data-masker.d.ts.map +1 -0
- package/dist/utils/data-masker.js.map +1 -0
- package/dist/{src/utils → utils}/errors.d.ts +1 -1
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/{src/utils → utils}/errors.js +3 -3
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/filter.utils.d.ts.map +1 -0
- package/dist/utils/filter.utils.js.map +1 -0
- package/dist/utils/http-client-audit.d.ts.map +1 -0
- package/dist/utils/http-client-audit.js.map +1 -0
- package/dist/utils/http-client-masking.d.ts.map +1 -0
- package/dist/utils/http-client-masking.js.map +1 -0
- package/dist/utils/http-client-metadata.d.ts.map +1 -0
- package/dist/utils/http-client-metadata.js.map +1 -0
- package/dist/{src/utils → utils}/http-client.d.ts +13 -2
- package/dist/utils/http-client.d.ts.map +1 -0
- package/dist/{src/utils → utils}/http-client.js +16 -2
- package/dist/utils/http-client.js.map +1 -0
- package/dist/{src/utils → utils}/internal-http-client.d.ts +13 -2
- package/dist/utils/internal-http-client.d.ts.map +1 -0
- package/dist/{src/utils → utils}/internal-http-client.js +66 -8
- package/dist/utils/internal-http-client.js.map +1 -0
- package/dist/utils/pagination.utils.d.ts.map +1 -0
- package/dist/utils/pagination.utils.js.map +1 -0
- package/dist/utils/sensitive-fields.loader.d.ts.map +1 -0
- package/dist/utils/sensitive-fields.loader.js.map +1 -0
- package/dist/utils/sort.utils.d.ts.map +1 -0
- package/dist/utils/sort.utils.js.map +1 -0
- package/package.json +1 -1
- package/dist/examples/custom-sensitive-fields.example.d.ts +0 -48
- package/dist/examples/custom-sensitive-fields.example.d.ts.map +0 -1
- package/dist/examples/custom-sensitive-fields.example.js +0 -31
- package/dist/examples/custom-sensitive-fields.example.js.map +0 -1
- package/dist/examples/env-config-example.d.ts +0 -2
- package/dist/examples/env-config-example.d.ts.map +0 -1
- package/dist/examples/env-config-example.js +0 -31
- package/dist/examples/env-config-example.js.map +0 -1
- package/dist/examples/event-emission-mode.example.d.ts +0 -14
- package/dist/examples/event-emission-mode.example.d.ts.map +0 -1
- package/dist/examples/event-emission-mode.example.js +0 -121
- package/dist/examples/event-emission-mode.example.js.map +0 -1
- package/dist/examples/manual-config-example.d.ts +0 -2
- package/dist/examples/manual-config-example.d.ts.map +0 -1
- package/dist/examples/manual-config-example.js +0 -36
- package/dist/examples/manual-config-example.js.map +0 -1
- package/dist/examples/step-3-authentication.d.ts +0 -8
- package/dist/examples/step-3-authentication.d.ts.map +0 -1
- package/dist/examples/step-3-authentication.js +0 -41
- package/dist/examples/step-3-authentication.js.map +0 -1
- package/dist/examples/step-4-rbac.d.ts +0 -8
- package/dist/examples/step-4-rbac.d.ts.map +0 -1
- package/dist/examples/step-4-rbac.js +0 -46
- package/dist/examples/step-4-rbac.js.map +0 -1
- package/dist/examples/step-5-logging.d.ts +0 -8
- package/dist/examples/step-5-logging.d.ts.map +0 -1
- package/dist/examples/step-5-logging.js +0 -58
- package/dist/examples/step-5-logging.js.map +0 -1
- package/dist/examples/step-6-audit.d.ts +0 -8
- package/dist/examples/step-6-audit.d.ts.map +0 -1
- package/dist/examples/step-6-audit.js +0 -83
- package/dist/examples/step-6-audit.js.map +0 -1
- package/dist/examples/step-7-encryption-cache.d.ts +0 -8
- package/dist/examples/step-7-encryption-cache.d.ts.map +0 -1
- package/dist/examples/step-7-encryption-cache.js +0 -131
- package/dist/examples/step-7-encryption-cache.js.map +0 -1
- package/dist/examples/usage.d.ts +0 -6
- package/dist/examples/usage.d.ts.map +0 -1
- package/dist/examples/usage.js +0 -65
- package/dist/examples/usage.js.map +0 -1
- package/dist/src/index.d.ts +0 -154
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/index.js.map +0 -1
- package/dist/src/services/auth.service.d.ts.map +0 -1
- package/dist/src/services/auth.service.js.map +0 -1
- package/dist/src/services/cache.service.d.ts.map +0 -1
- package/dist/src/services/cache.service.js.map +0 -1
- package/dist/src/services/encryption.service.d.ts.map +0 -1
- package/dist/src/services/encryption.service.js.map +0 -1
- package/dist/src/services/logger.service.d.ts.map +0 -1
- package/dist/src/services/logger.service.js.map +0 -1
- package/dist/src/services/permission.service.d.ts +0 -42
- package/dist/src/services/permission.service.d.ts.map +0 -1
- package/dist/src/services/permission.service.js.map +0 -1
- package/dist/src/services/redis.service.d.ts.map +0 -1
- package/dist/src/services/redis.service.js.map +0 -1
- package/dist/src/services/role.service.d.ts +0 -38
- package/dist/src/services/role.service.d.ts.map +0 -1
- package/dist/src/services/role.service.js.map +0 -1
- package/dist/src/types/config.types.d.ts.map +0 -1
- package/dist/src/types/config.types.js.map +0 -1
- package/dist/src/types/errors.types.d.ts.map +0 -1
- package/dist/src/types/errors.types.js.map +0 -1
- package/dist/src/types/filter.types.d.ts.map +0 -1
- package/dist/src/types/filter.types.js.map +0 -1
- package/dist/src/types/pagination.types.d.ts.map +0 -1
- package/dist/src/types/pagination.types.js.map +0 -1
- package/dist/src/types/sort.types.d.ts.map +0 -1
- package/dist/src/types/sort.types.js.map +0 -1
- package/dist/src/utils/audit-log-queue.d.ts.map +0 -1
- package/dist/src/utils/audit-log-queue.js.map +0 -1
- package/dist/src/utils/config-loader.d.ts.map +0 -1
- package/dist/src/utils/config-loader.js.map +0 -1
- package/dist/src/utils/data-masker.d.ts.map +0 -1
- package/dist/src/utils/data-masker.js.map +0 -1
- package/dist/src/utils/errors.d.ts.map +0 -1
- package/dist/src/utils/errors.js.map +0 -1
- package/dist/src/utils/filter.utils.d.ts.map +0 -1
- package/dist/src/utils/filter.utils.js.map +0 -1
- package/dist/src/utils/http-client-audit.d.ts.map +0 -1
- package/dist/src/utils/http-client-audit.js.map +0 -1
- package/dist/src/utils/http-client-masking.d.ts.map +0 -1
- package/dist/src/utils/http-client-masking.js.map +0 -1
- package/dist/src/utils/http-client-metadata.d.ts.map +0 -1
- package/dist/src/utils/http-client-metadata.js.map +0 -1
- package/dist/src/utils/http-client.d.ts.map +0 -1
- package/dist/src/utils/http-client.js.map +0 -1
- package/dist/src/utils/internal-http-client.d.ts.map +0 -1
- package/dist/src/utils/internal-http-client.js.map +0 -1
- package/dist/src/utils/pagination.utils.d.ts.map +0 -1
- package/dist/src/utils/pagination.utils.js.map +0 -1
- package/dist/src/utils/sensitive-fields.loader.d.ts.map +0 -1
- package/dist/src/utils/sensitive-fields.loader.js.map +0 -1
- package/dist/src/utils/sort.utils.d.ts.map +0 -1
- package/dist/src/utils/sort.utils.js.map +0 -1
- /package/dist/{src/services → services}/cache.service.d.ts +0 -0
- /package/dist/{src/services → services}/cache.service.js +0 -0
- /package/dist/{src/services → services}/encryption.service.d.ts +0 -0
- /package/dist/{src/services → services}/encryption.service.js +0 -0
- /package/dist/{src/services → services}/logger.service.d.ts +0 -0
- /package/dist/{src/services → services}/logger.service.js +0 -0
- /package/dist/{src/services → services}/redis.service.d.ts +0 -0
- /package/dist/{src/services → services}/redis.service.js +0 -0
- /package/dist/{src/types → types}/config.types.js +0 -0
- /package/dist/{src/types → types}/errors.types.js +0 -0
- /package/dist/{src/types → types}/filter.types.d.ts +0 -0
- /package/dist/{src/types → types}/filter.types.js +0 -0
- /package/dist/{src/types → types}/pagination.types.d.ts +0 -0
- /package/dist/{src/types → types}/pagination.types.js +0 -0
- /package/dist/{src/types → types}/sort.types.d.ts +0 -0
- /package/dist/{src/types → types}/sort.types.js +0 -0
- /package/dist/{src/utils → utils}/audit-log-queue.d.ts +0 -0
- /package/dist/{src/utils → utils}/audit-log-queue.js +0 -0
- /package/dist/{src/utils → utils}/config-loader.d.ts +0 -0
- /package/dist/{src/utils → utils}/data-masker.d.ts +0 -0
- /package/dist/{src/utils → utils}/data-masker.js +0 -0
- /package/dist/{src/utils → utils}/filter.utils.d.ts +0 -0
- /package/dist/{src/utils → utils}/filter.utils.js +0 -0
- /package/dist/{src/utils → utils}/http-client-audit.d.ts +0 -0
- /package/dist/{src/utils → utils}/http-client-audit.js +0 -0
- /package/dist/{src/utils → utils}/http-client-masking.d.ts +0 -0
- /package/dist/{src/utils → utils}/http-client-masking.js +0 -0
- /package/dist/{src/utils → utils}/http-client-metadata.d.ts +0 -0
- /package/dist/{src/utils → utils}/http-client-metadata.js +0 -0
- /package/dist/{src/utils → utils}/pagination.utils.d.ts +0 -0
- /package/dist/{src/utils → utils}/pagination.utils.js +0 -0
- /package/dist/{src/utils → utils}/sensitive-fields.config.json +0 -0
- /package/dist/{src/utils → utils}/sensitive-fields.loader.d.ts +0 -0
- /package/dist/{src/utils → utils}/sensitive-fields.loader.js +0 -0
- /package/dist/{src/utils → utils}/sort.utils.d.ts +0 -0
- /package/dist/{src/utils → utils}/sort.utils.js +0 -0
package/README.md
CHANGED
|
@@ -481,6 +481,59 @@ const response = createPaginatedListResponse(
|
|
|
481
481
|
→ [Complete sort example](docs/examples.md#sorting)
|
|
482
482
|
→ [API Reference](docs/api-reference.md#pagination-utilities)
|
|
483
483
|
|
|
484
|
+
---
|
|
485
|
+
|
|
486
|
+
### Step 9: Multi-Authentication Strategy
|
|
487
|
+
|
|
488
|
+
**What happens:** Configure flexible authentication methods with priority-based fallback for advanced authentication scenarios.
|
|
489
|
+
|
|
490
|
+
```typescript
|
|
491
|
+
import { MisoClient, loadConfig } from '@aifabrix/miso-client';
|
|
492
|
+
|
|
493
|
+
const client = new MisoClient(loadConfig());
|
|
494
|
+
await client.initialize();
|
|
495
|
+
|
|
496
|
+
// Global strategy configuration
|
|
497
|
+
const client = new MisoClient({
|
|
498
|
+
...loadConfig(),
|
|
499
|
+
authStrategy: {
|
|
500
|
+
methods: ['bearer', 'client-token', 'client-credentials']
|
|
501
|
+
}
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
// Per-request strategy override
|
|
505
|
+
const strategy = client.createAuthStrategy(['bearer', 'api-key'], 'token-123', 'api-key-456');
|
|
506
|
+
await client.getRoles(token, strategy);
|
|
507
|
+
|
|
508
|
+
// Using requestWithAuthStrategy for custom requests
|
|
509
|
+
await client.requestWithAuthStrategy('GET', '/api/data', {
|
|
510
|
+
methods: ['client-token']
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
// Get default strategy
|
|
514
|
+
const defaultStrategy = client.getDefaultAuthStrategy(token);
|
|
515
|
+
// Returns: { methods: ['bearer', 'client-token'], bearerToken: token }
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
**Supported Authentication Methods:**
|
|
519
|
+
- `bearer` - Bearer token authentication (Authorization: Bearer <token>)
|
|
520
|
+
- `client-token` - Client token authentication (x-client-token header)
|
|
521
|
+
- `client-credentials` - Client credentials authentication (X-Client-Id and X-Client-Secret headers)
|
|
522
|
+
- `api-key` - API key authentication (Authorization: Bearer <api-key>)
|
|
523
|
+
|
|
524
|
+
**Priority-Based Fallback:** Methods are tried in the order specified in the strategy array until one succeeds.
|
|
525
|
+
|
|
526
|
+
**Environment Variable Configuration:**
|
|
527
|
+
```bash
|
|
528
|
+
MISO_AUTH_STRATEGY=bearer,client-token,api-key
|
|
529
|
+
MISO_BEARER_TOKEN=optional-bearer-token
|
|
530
|
+
MISO_API_KEY=optional-api-key
|
|
531
|
+
```
|
|
532
|
+
|
|
533
|
+
**Backward Compatibility:** All existing code continues to work without changes. If no strategy is specified, defaults to `['bearer', 'client-token']` (existing behavior).
|
|
534
|
+
|
|
535
|
+
→ [Complete authentication strategy example](docs/examples.md#authentication-strategy)
|
|
536
|
+
→ [API Reference](docs/api-reference.md#authentication-strategy)
|
|
484
537
|
|
|
485
538
|
---
|
|
486
539
|
|
|
@@ -496,12 +549,19 @@ interface MisoClientConfig {
|
|
|
496
549
|
encryptionKey?: string; // Optional: Encryption key (or use ENCRYPTION_KEY env var)
|
|
497
550
|
sensitiveFieldsConfig?: string; // Optional: Path to ISO 27001 sensitive fields config JSON
|
|
498
551
|
emitEvents?: boolean; // Optional: Emit log events instead of HTTP/Redis (for direct SDK embedding)
|
|
552
|
+
authStrategy?: AuthStrategy; // Optional: Default authentication strategy
|
|
499
553
|
cache?: {
|
|
500
554
|
roleTTL?: number; // Role cache TTL (default: 900s)
|
|
501
555
|
permissionTTL?: number; // Permission cache TTL (default: 900s)
|
|
502
556
|
};
|
|
503
557
|
audit?: AuditConfig; // Optional: Audit logging configuration
|
|
504
558
|
}
|
|
559
|
+
|
|
560
|
+
interface AuthStrategy {
|
|
561
|
+
methods: ('bearer' | 'client-token' | 'client-credentials' | 'api-key')[];
|
|
562
|
+
bearerToken?: string; // Optional: Bearer token for bearer authentication
|
|
563
|
+
apiKey?: string; // Optional: API key for api-key authentication
|
|
564
|
+
}
|
|
505
565
|
```
|
|
506
566
|
|
|
507
567
|
**Recommended:** Use `loadConfig()` to load from `.env` file automatically.
|
|
@@ -607,6 +667,9 @@ REDIS_PORT=6379
|
|
|
607
667
|
MISO_LOG_LEVEL=info
|
|
608
668
|
MISO_SENSITIVE_FIELDS_CONFIG=/path/to/sensitive-fields.config.json # Optional: ISO 27001 config
|
|
609
669
|
MISO_EMIT_EVENTS=true # Optional: Enable event emission mode (for direct SDK embedding)
|
|
670
|
+
MISO_AUTH_STRATEGY=bearer,client-token,api-key # Optional: Authentication strategy (comma-separated)
|
|
671
|
+
MISO_BEARER_TOKEN=optional-bearer-token # Optional: Default bearer token
|
|
672
|
+
MISO_API_KEY=optional-api-key # Optional: Default API key
|
|
610
673
|
```
|
|
611
674
|
|
|
612
675
|
---
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Main MisoClient SDK class
|
|
3
|
+
*/
|
|
4
|
+
import { LoggerService } from './services/logger.service';
|
|
5
|
+
import { EncryptionService } from './services/encryption.service';
|
|
6
|
+
import { CacheService } from './services/cache.service';
|
|
7
|
+
import { MisoClientConfig, UserInfo, AuthStrategy } from './types/config.types';
|
|
8
|
+
export declare class MisoClient {
|
|
9
|
+
private config;
|
|
10
|
+
private httpClient;
|
|
11
|
+
private redis;
|
|
12
|
+
private auth;
|
|
13
|
+
private roles;
|
|
14
|
+
private permissions;
|
|
15
|
+
private logger;
|
|
16
|
+
private encryptionService?;
|
|
17
|
+
private cacheService;
|
|
18
|
+
private initialized;
|
|
19
|
+
constructor(config: MisoClientConfig);
|
|
20
|
+
/**
|
|
21
|
+
* Initialize the client (connect to Redis if configured)
|
|
22
|
+
*/
|
|
23
|
+
initialize(): Promise<void>;
|
|
24
|
+
/**
|
|
25
|
+
* Disconnect from Redis
|
|
26
|
+
*/
|
|
27
|
+
disconnect(): Promise<void>;
|
|
28
|
+
/**
|
|
29
|
+
* Check if client is initialized
|
|
30
|
+
*/
|
|
31
|
+
isInitialized(): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Extract Bearer token from request headers
|
|
34
|
+
* Supports common request object patterns (Express, Fastify, Next.js)
|
|
35
|
+
*/
|
|
36
|
+
getToken(req: {
|
|
37
|
+
headers: {
|
|
38
|
+
authorization?: string;
|
|
39
|
+
};
|
|
40
|
+
}): string | null;
|
|
41
|
+
/**
|
|
42
|
+
* Get environment token using client credentials
|
|
43
|
+
* This is called automatically by HttpClient but can be called manually
|
|
44
|
+
*/
|
|
45
|
+
getEnvironmentToken(): Promise<string>;
|
|
46
|
+
/**
|
|
47
|
+
* Initiate login flow by redirecting to controller
|
|
48
|
+
* Returns the login URL for browser redirect or manual navigation
|
|
49
|
+
*/
|
|
50
|
+
login(redirectUri: string): string;
|
|
51
|
+
/**
|
|
52
|
+
* Validate token with controller
|
|
53
|
+
* @param token - User authentication token
|
|
54
|
+
* @param authStrategy - Optional authentication strategy override
|
|
55
|
+
*/
|
|
56
|
+
validateToken(token: string, authStrategy?: AuthStrategy): Promise<boolean>;
|
|
57
|
+
/**
|
|
58
|
+
* Get user information from token
|
|
59
|
+
* @param token - User authentication token
|
|
60
|
+
* @param authStrategy - Optional authentication strategy override
|
|
61
|
+
*/
|
|
62
|
+
getUser(token: string, authStrategy?: AuthStrategy): Promise<UserInfo | null>;
|
|
63
|
+
/**
|
|
64
|
+
* Get user information from GET /api/auth/user endpoint
|
|
65
|
+
* @param token - User authentication token
|
|
66
|
+
* @param authStrategy - Optional authentication strategy override
|
|
67
|
+
*/
|
|
68
|
+
getUserInfo(token: string, authStrategy?: AuthStrategy): Promise<UserInfo | null>;
|
|
69
|
+
/**
|
|
70
|
+
* Check if user is authenticated
|
|
71
|
+
* @param token - User authentication token
|
|
72
|
+
* @param authStrategy - Optional authentication strategy override
|
|
73
|
+
*/
|
|
74
|
+
isAuthenticated(token: string, authStrategy?: AuthStrategy): Promise<boolean>;
|
|
75
|
+
/**
|
|
76
|
+
* Logout user
|
|
77
|
+
*/
|
|
78
|
+
logout(): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Get user roles (cached in Redis if available)
|
|
81
|
+
* @param token - User authentication token
|
|
82
|
+
* @param authStrategy - Optional authentication strategy override
|
|
83
|
+
*/
|
|
84
|
+
getRoles(token: string, authStrategy?: AuthStrategy): Promise<string[]>;
|
|
85
|
+
/**
|
|
86
|
+
* Check if user has specific role
|
|
87
|
+
* @param token - User authentication token
|
|
88
|
+
* @param role - Role to check
|
|
89
|
+
* @param authStrategy - Optional authentication strategy override
|
|
90
|
+
*/
|
|
91
|
+
hasRole(token: string, role: string, authStrategy?: AuthStrategy): Promise<boolean>;
|
|
92
|
+
/**
|
|
93
|
+
* Check if user has any of the specified roles
|
|
94
|
+
* @param token - User authentication token
|
|
95
|
+
* @param roles - Roles to check
|
|
96
|
+
* @param authStrategy - Optional authentication strategy override
|
|
97
|
+
*/
|
|
98
|
+
hasAnyRole(token: string, roles: string[], authStrategy?: AuthStrategy): Promise<boolean>;
|
|
99
|
+
/**
|
|
100
|
+
* Check if user has all of the specified roles
|
|
101
|
+
* @param token - User authentication token
|
|
102
|
+
* @param roles - Roles to check
|
|
103
|
+
* @param authStrategy - Optional authentication strategy override
|
|
104
|
+
*/
|
|
105
|
+
hasAllRoles(token: string, roles: string[], authStrategy?: AuthStrategy): Promise<boolean>;
|
|
106
|
+
/**
|
|
107
|
+
* Force refresh roles from controller (bypass cache)
|
|
108
|
+
* @param token - User authentication token
|
|
109
|
+
* @param authStrategy - Optional authentication strategy override
|
|
110
|
+
*/
|
|
111
|
+
refreshRoles(token: string, authStrategy?: AuthStrategy): Promise<string[]>;
|
|
112
|
+
/**
|
|
113
|
+
* Get user permissions (cached in Redis if available)
|
|
114
|
+
* @param token - User authentication token
|
|
115
|
+
* @param authStrategy - Optional authentication strategy override
|
|
116
|
+
*/
|
|
117
|
+
getPermissions(token: string, authStrategy?: AuthStrategy): Promise<string[]>;
|
|
118
|
+
/**
|
|
119
|
+
* Check if user has specific permission
|
|
120
|
+
* @param token - User authentication token
|
|
121
|
+
* @param permission - Permission to check
|
|
122
|
+
* @param authStrategy - Optional authentication strategy override
|
|
123
|
+
*/
|
|
124
|
+
hasPermission(token: string, permission: string, authStrategy?: AuthStrategy): Promise<boolean>;
|
|
125
|
+
/**
|
|
126
|
+
* Check if user has any of the specified permissions
|
|
127
|
+
* @param token - User authentication token
|
|
128
|
+
* @param permissions - Permissions to check
|
|
129
|
+
* @param authStrategy - Optional authentication strategy override
|
|
130
|
+
*/
|
|
131
|
+
hasAnyPermission(token: string, permissions: string[], authStrategy?: AuthStrategy): Promise<boolean>;
|
|
132
|
+
/**
|
|
133
|
+
* Check if user has all of the specified permissions
|
|
134
|
+
* @param token - User authentication token
|
|
135
|
+
* @param permissions - Permissions to check
|
|
136
|
+
* @param authStrategy - Optional authentication strategy override
|
|
137
|
+
*/
|
|
138
|
+
hasAllPermissions(token: string, permissions: string[], authStrategy?: AuthStrategy): Promise<boolean>;
|
|
139
|
+
/**
|
|
140
|
+
* Force refresh permissions from controller (bypass cache)
|
|
141
|
+
* @param token - User authentication token
|
|
142
|
+
* @param authStrategy - Optional authentication strategy override
|
|
143
|
+
*/
|
|
144
|
+
refreshPermissions(token: string, authStrategy?: AuthStrategy): Promise<string[]>;
|
|
145
|
+
/**
|
|
146
|
+
* Clear cached permissions for a user
|
|
147
|
+
* @param token - User authentication token
|
|
148
|
+
* @param authStrategy - Optional authentication strategy override
|
|
149
|
+
*/
|
|
150
|
+
clearPermissionsCache(token: string, authStrategy?: AuthStrategy): Promise<void>;
|
|
151
|
+
/**
|
|
152
|
+
* Get logger service for application logging
|
|
153
|
+
*/
|
|
154
|
+
get log(): LoggerService;
|
|
155
|
+
/**
|
|
156
|
+
* Get encryption service for data encryption/decryption
|
|
157
|
+
* Returns undefined if encryption key is not configured
|
|
158
|
+
*/
|
|
159
|
+
get encryption(): EncryptionService | undefined;
|
|
160
|
+
/**
|
|
161
|
+
* Get cache service for generic caching
|
|
162
|
+
*/
|
|
163
|
+
get cache(): CacheService;
|
|
164
|
+
/**
|
|
165
|
+
* Get current configuration
|
|
166
|
+
*/
|
|
167
|
+
getConfig(): MisoClientConfig;
|
|
168
|
+
/**
|
|
169
|
+
* Check if Redis is connected
|
|
170
|
+
*/
|
|
171
|
+
isRedisConnected(): boolean;
|
|
172
|
+
/**
|
|
173
|
+
* Make request with authentication strategy
|
|
174
|
+
* Tries authentication methods in priority order based on strategy
|
|
175
|
+
* @param method - HTTP method
|
|
176
|
+
* @param url - Request URL
|
|
177
|
+
* @param authStrategy - Authentication strategy configuration
|
|
178
|
+
* @param data - Optional request data
|
|
179
|
+
* @param config - Optional Axios request config
|
|
180
|
+
* @returns Response data
|
|
181
|
+
*/
|
|
182
|
+
requestWithAuthStrategy<T>(method: 'GET' | 'POST' | 'PUT' | 'DELETE', url: string, authStrategy: AuthStrategy, data?: unknown, config?: import('axios').AxiosRequestConfig): Promise<T>;
|
|
183
|
+
/**
|
|
184
|
+
* Create authentication strategy helper
|
|
185
|
+
* @param methods - Array of authentication methods in priority order
|
|
186
|
+
* @param bearerToken - Optional bearer token
|
|
187
|
+
* @param apiKey - Optional API key
|
|
188
|
+
* @returns Authentication strategy
|
|
189
|
+
*/
|
|
190
|
+
createAuthStrategy(methods: ('bearer' | 'client-token' | 'client-credentials' | 'api-key')[], bearerToken?: string, apiKey?: string): AuthStrategy;
|
|
191
|
+
/**
|
|
192
|
+
* Get default authentication strategy
|
|
193
|
+
* Uses bearer token and client token in that order
|
|
194
|
+
* @param bearerToken - Optional bearer token
|
|
195
|
+
* @returns Default authentication strategy
|
|
196
|
+
*/
|
|
197
|
+
getDefaultAuthStrategy(bearerToken?: string): AuthStrategy;
|
|
198
|
+
}
|
|
199
|
+
export * from './types/config.types';
|
|
200
|
+
export * from './types/pagination.types';
|
|
201
|
+
export * from './types/filter.types';
|
|
202
|
+
export * from './types/sort.types';
|
|
203
|
+
export type { ErrorResponse as ErrorResponseFromErrors, ErrorEnvelope } from './types/errors.types';
|
|
204
|
+
export { AuthService } from './services/auth.service';
|
|
205
|
+
export { RoleService } from './services/role.service';
|
|
206
|
+
export { LoggerService } from './services/logger.service';
|
|
207
|
+
export { RedisService } from './services/redis.service';
|
|
208
|
+
export { EncryptionService } from './services/encryption.service';
|
|
209
|
+
export { CacheService } from './services/cache.service';
|
|
210
|
+
export { HttpClient } from './utils/http-client';
|
|
211
|
+
export { loadConfig } from './utils/config-loader';
|
|
212
|
+
export * from './utils/pagination.utils';
|
|
213
|
+
export * from './utils/filter.utils';
|
|
214
|
+
export * from './utils/sort.utils';
|
|
215
|
+
export { MisoClientError, ApiErrorException, transformError, handleApiError } from './utils/errors';
|
|
216
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAKxD,OAAO,EAAE,gBAAgB,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM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AE,MAAM,sBAAsB,CAAC;AAGpG,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGjD,OAAO,EAAE,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAGnD,cAAc,0BAA0B,CAAC;AACzC,cAAc,sBAAsB,CAAC;AACrC,cAAc,oBAAoB,CAAC;AAGnC,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -28,6 +28,7 @@ const cache_service_1 = require("./services/cache.service");
|
|
|
28
28
|
const http_client_1 = require("./utils/http-client");
|
|
29
29
|
const internal_http_client_1 = require("./utils/internal-http-client");
|
|
30
30
|
const data_masker_1 = require("./utils/data-masker");
|
|
31
|
+
const auth_strategy_1 = require("./utils/auth-strategy");
|
|
31
32
|
class MisoClient {
|
|
32
33
|
constructor(config) {
|
|
33
34
|
this.initialized = false;
|
|
@@ -130,27 +131,35 @@ class MisoClient {
|
|
|
130
131
|
}
|
|
131
132
|
/**
|
|
132
133
|
* Validate token with controller
|
|
134
|
+
* @param token - User authentication token
|
|
135
|
+
* @param authStrategy - Optional authentication strategy override
|
|
133
136
|
*/
|
|
134
|
-
async validateToken(token) {
|
|
135
|
-
return this.auth.validateToken(token);
|
|
137
|
+
async validateToken(token, authStrategy) {
|
|
138
|
+
return this.auth.validateToken(token, authStrategy);
|
|
136
139
|
}
|
|
137
140
|
/**
|
|
138
141
|
* Get user information from token
|
|
142
|
+
* @param token - User authentication token
|
|
143
|
+
* @param authStrategy - Optional authentication strategy override
|
|
139
144
|
*/
|
|
140
|
-
async getUser(token) {
|
|
141
|
-
return this.auth.getUser(token);
|
|
145
|
+
async getUser(token, authStrategy) {
|
|
146
|
+
return this.auth.getUser(token, authStrategy);
|
|
142
147
|
}
|
|
143
148
|
/**
|
|
144
149
|
* Get user information from GET /api/auth/user endpoint
|
|
150
|
+
* @param token - User authentication token
|
|
151
|
+
* @param authStrategy - Optional authentication strategy override
|
|
145
152
|
*/
|
|
146
|
-
async getUserInfo(token) {
|
|
147
|
-
return this.auth.getUserInfo(token);
|
|
153
|
+
async getUserInfo(token, authStrategy) {
|
|
154
|
+
return this.auth.getUserInfo(token, authStrategy);
|
|
148
155
|
}
|
|
149
156
|
/**
|
|
150
157
|
* Check if user is authenticated
|
|
158
|
+
* @param token - User authentication token
|
|
159
|
+
* @param authStrategy - Optional authentication strategy override
|
|
151
160
|
*/
|
|
152
|
-
async isAuthenticated(token) {
|
|
153
|
-
return this.auth.isAuthenticated(token);
|
|
161
|
+
async isAuthenticated(token, authStrategy) {
|
|
162
|
+
return this.auth.isAuthenticated(token, authStrategy);
|
|
154
163
|
}
|
|
155
164
|
/**
|
|
156
165
|
* Logout user
|
|
@@ -161,69 +170,97 @@ class MisoClient {
|
|
|
161
170
|
// ==================== AUTHORIZATION METHODS ====================
|
|
162
171
|
/**
|
|
163
172
|
* Get user roles (cached in Redis if available)
|
|
173
|
+
* @param token - User authentication token
|
|
174
|
+
* @param authStrategy - Optional authentication strategy override
|
|
164
175
|
*/
|
|
165
|
-
async getRoles(token) {
|
|
166
|
-
return this.roles.getRoles(token);
|
|
176
|
+
async getRoles(token, authStrategy) {
|
|
177
|
+
return this.roles.getRoles(token, authStrategy);
|
|
167
178
|
}
|
|
168
179
|
/**
|
|
169
180
|
* Check if user has specific role
|
|
181
|
+
* @param token - User authentication token
|
|
182
|
+
* @param role - Role to check
|
|
183
|
+
* @param authStrategy - Optional authentication strategy override
|
|
170
184
|
*/
|
|
171
|
-
async hasRole(token, role) {
|
|
172
|
-
return this.roles.hasRole(token, role);
|
|
185
|
+
async hasRole(token, role, authStrategy) {
|
|
186
|
+
return this.roles.hasRole(token, role, authStrategy);
|
|
173
187
|
}
|
|
174
188
|
/**
|
|
175
189
|
* Check if user has any of the specified roles
|
|
190
|
+
* @param token - User authentication token
|
|
191
|
+
* @param roles - Roles to check
|
|
192
|
+
* @param authStrategy - Optional authentication strategy override
|
|
176
193
|
*/
|
|
177
|
-
async hasAnyRole(token, roles) {
|
|
178
|
-
return this.roles.hasAnyRole(token, roles);
|
|
194
|
+
async hasAnyRole(token, roles, authStrategy) {
|
|
195
|
+
return this.roles.hasAnyRole(token, roles, authStrategy);
|
|
179
196
|
}
|
|
180
197
|
/**
|
|
181
198
|
* Check if user has all of the specified roles
|
|
199
|
+
* @param token - User authentication token
|
|
200
|
+
* @param roles - Roles to check
|
|
201
|
+
* @param authStrategy - Optional authentication strategy override
|
|
182
202
|
*/
|
|
183
|
-
async hasAllRoles(token, roles) {
|
|
184
|
-
return this.roles.hasAllRoles(token, roles);
|
|
203
|
+
async hasAllRoles(token, roles, authStrategy) {
|
|
204
|
+
return this.roles.hasAllRoles(token, roles, authStrategy);
|
|
185
205
|
}
|
|
186
206
|
/**
|
|
187
207
|
* Force refresh roles from controller (bypass cache)
|
|
208
|
+
* @param token - User authentication token
|
|
209
|
+
* @param authStrategy - Optional authentication strategy override
|
|
188
210
|
*/
|
|
189
|
-
async refreshRoles(token) {
|
|
190
|
-
return this.roles.refreshRoles(token);
|
|
211
|
+
async refreshRoles(token, authStrategy) {
|
|
212
|
+
return this.roles.refreshRoles(token, authStrategy);
|
|
191
213
|
}
|
|
192
214
|
/**
|
|
193
215
|
* Get user permissions (cached in Redis if available)
|
|
216
|
+
* @param token - User authentication token
|
|
217
|
+
* @param authStrategy - Optional authentication strategy override
|
|
194
218
|
*/
|
|
195
|
-
async getPermissions(token) {
|
|
196
|
-
return this.permissions.getPermissions(token);
|
|
219
|
+
async getPermissions(token, authStrategy) {
|
|
220
|
+
return this.permissions.getPermissions(token, authStrategy);
|
|
197
221
|
}
|
|
198
222
|
/**
|
|
199
223
|
* Check if user has specific permission
|
|
224
|
+
* @param token - User authentication token
|
|
225
|
+
* @param permission - Permission to check
|
|
226
|
+
* @param authStrategy - Optional authentication strategy override
|
|
200
227
|
*/
|
|
201
|
-
async hasPermission(token, permission) {
|
|
202
|
-
return this.permissions.hasPermission(token, permission);
|
|
228
|
+
async hasPermission(token, permission, authStrategy) {
|
|
229
|
+
return this.permissions.hasPermission(token, permission, authStrategy);
|
|
203
230
|
}
|
|
204
231
|
/**
|
|
205
232
|
* Check if user has any of the specified permissions
|
|
233
|
+
* @param token - User authentication token
|
|
234
|
+
* @param permissions - Permissions to check
|
|
235
|
+
* @param authStrategy - Optional authentication strategy override
|
|
206
236
|
*/
|
|
207
|
-
async hasAnyPermission(token, permissions) {
|
|
208
|
-
return this.permissions.hasAnyPermission(token, permissions);
|
|
237
|
+
async hasAnyPermission(token, permissions, authStrategy) {
|
|
238
|
+
return this.permissions.hasAnyPermission(token, permissions, authStrategy);
|
|
209
239
|
}
|
|
210
240
|
/**
|
|
211
241
|
* Check if user has all of the specified permissions
|
|
242
|
+
* @param token - User authentication token
|
|
243
|
+
* @param permissions - Permissions to check
|
|
244
|
+
* @param authStrategy - Optional authentication strategy override
|
|
212
245
|
*/
|
|
213
|
-
async hasAllPermissions(token, permissions) {
|
|
214
|
-
return this.permissions.hasAllPermissions(token, permissions);
|
|
246
|
+
async hasAllPermissions(token, permissions, authStrategy) {
|
|
247
|
+
return this.permissions.hasAllPermissions(token, permissions, authStrategy);
|
|
215
248
|
}
|
|
216
249
|
/**
|
|
217
250
|
* Force refresh permissions from controller (bypass cache)
|
|
251
|
+
* @param token - User authentication token
|
|
252
|
+
* @param authStrategy - Optional authentication strategy override
|
|
218
253
|
*/
|
|
219
|
-
async refreshPermissions(token) {
|
|
220
|
-
return this.permissions.refreshPermissions(token);
|
|
254
|
+
async refreshPermissions(token, authStrategy) {
|
|
255
|
+
return this.permissions.refreshPermissions(token, authStrategy);
|
|
221
256
|
}
|
|
222
257
|
/**
|
|
223
258
|
* Clear cached permissions for a user
|
|
259
|
+
* @param token - User authentication token
|
|
260
|
+
* @param authStrategy - Optional authentication strategy override
|
|
224
261
|
*/
|
|
225
|
-
async clearPermissionsCache(token) {
|
|
226
|
-
return this.permissions.clearPermissionsCache(token);
|
|
262
|
+
async clearPermissionsCache(token, authStrategy) {
|
|
263
|
+
return this.permissions.clearPermissionsCache(token, authStrategy);
|
|
227
264
|
}
|
|
228
265
|
// ==================== LOGGING METHODS ====================
|
|
229
266
|
/**
|
|
@@ -260,6 +297,42 @@ class MisoClient {
|
|
|
260
297
|
isRedisConnected() {
|
|
261
298
|
return this.redis.isConnected();
|
|
262
299
|
}
|
|
300
|
+
/**
|
|
301
|
+
* Make request with authentication strategy
|
|
302
|
+
* Tries authentication methods in priority order based on strategy
|
|
303
|
+
* @param method - HTTP method
|
|
304
|
+
* @param url - Request URL
|
|
305
|
+
* @param authStrategy - Authentication strategy configuration
|
|
306
|
+
* @param data - Optional request data
|
|
307
|
+
* @param config - Optional Axios request config
|
|
308
|
+
* @returns Response data
|
|
309
|
+
*/
|
|
310
|
+
async requestWithAuthStrategy(method, url, authStrategy, data, config) {
|
|
311
|
+
return this.httpClient.requestWithAuthStrategy(method, url, authStrategy, data, config);
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Create authentication strategy helper
|
|
315
|
+
* @param methods - Array of authentication methods in priority order
|
|
316
|
+
* @param bearerToken - Optional bearer token
|
|
317
|
+
* @param apiKey - Optional API key
|
|
318
|
+
* @returns Authentication strategy
|
|
319
|
+
*/
|
|
320
|
+
createAuthStrategy(methods, bearerToken, apiKey) {
|
|
321
|
+
return {
|
|
322
|
+
methods,
|
|
323
|
+
bearerToken,
|
|
324
|
+
apiKey
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
/**
|
|
328
|
+
* Get default authentication strategy
|
|
329
|
+
* Uses bearer token and client token in that order
|
|
330
|
+
* @param bearerToken - Optional bearer token
|
|
331
|
+
* @returns Default authentication strategy
|
|
332
|
+
*/
|
|
333
|
+
getDefaultAuthStrategy(bearerToken) {
|
|
334
|
+
return auth_strategy_1.AuthStrategyHandler.getDefaultStrategy(bearerToken);
|
|
335
|
+
}
|
|
263
336
|
}
|
|
264
337
|
exports.MisoClient = MisoClient;
|
|
265
338
|
// Export types
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;;AAEH,0DAAsD;AACtD,0DAAsD;AACtD,sEAAkE;AAClE,8DAA0D;AAC1D,4DAAwD;AACxD,sEAAkE;AAClE,4DAAwD;AACxD,qDAAiD;AACjD,uEAAkE;AAClE,qDAAiD;AACjD,yDAA4D;AAG5D,MAAa,UAAU;IAYrB,YAAY,MAAwB;QAF5B,gBAAW,GAAG,KAAK,CAAC;QAG1B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QAErB,4DAA4D;QAC5D,IAAI,MAAM,CAAC,qBAAqB,EAAE,CAAC;YACjC,wBAAU,CAAC,aAAa,CAAC,MAAM,CAAC,qBAAqB,CAAC,CAAC;QACzD,CAAC;QAED,4DAA4D;QAC5D,MAAM,cAAc,GAAG,IAAI,yCAAkB,CAAC,MAAM,CAAC,CAAC;QAEtD,uBAAuB;QACvB,IAAI,CAAC,KAAK,GAAG,IAAI,4BAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAE5C,wGAAwG;QACxG,kEAAkE;QAClE,4FAA4F;QAC5F,IAAI,CAAC,MAAM,GAAG,IAAI,8BAAa,CAAC,cAAuC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QAErF,qEAAqE;QACrE,IAAI,CAAC,UAAU,GAAG,IAAI,wBAAU,CAAC,MAAM,EAAE,IAAI,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A3F,yGAAA,eAAe,OAAA;AAAE,2GAAA,iBAAiB,OAAA;AAAE,wGAAA,cAAc,OAAA;AAAE,wGAAA,cAAc,OAAA"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { HttpClient } from '../utils/http-client';
|
|
5
5
|
import { RedisService } from './redis.service';
|
|
6
|
-
import { UserInfo } from '../types/config.types';
|
|
6
|
+
import { UserInfo, AuthStrategy } from '../types/config.types';
|
|
7
7
|
export declare class AuthService {
|
|
8
8
|
private httpClient;
|
|
9
9
|
private redis;
|
|
@@ -27,25 +27,33 @@ export declare class AuthService {
|
|
|
27
27
|
/**
|
|
28
28
|
* Validate token with controller
|
|
29
29
|
* If API_KEY is configured and token matches, returns true without calling controller
|
|
30
|
+
* @param token - User authentication token
|
|
31
|
+
* @param authStrategy - Optional authentication strategy override
|
|
30
32
|
*/
|
|
31
|
-
validateToken(token: string): Promise<boolean>;
|
|
33
|
+
validateToken(token: string, authStrategy?: AuthStrategy): Promise<boolean>;
|
|
32
34
|
/**
|
|
33
35
|
* Get user information from token
|
|
34
36
|
* If API_KEY is configured and token matches, returns null (by design for testing)
|
|
37
|
+
* @param token - User authentication token
|
|
38
|
+
* @param authStrategy - Optional authentication strategy override
|
|
35
39
|
*/
|
|
36
|
-
getUser(token: string): Promise<UserInfo | null>;
|
|
40
|
+
getUser(token: string, authStrategy?: AuthStrategy): Promise<UserInfo | null>;
|
|
37
41
|
/**
|
|
38
42
|
* Get user information from GET /api/auth/user endpoint
|
|
39
43
|
* If API_KEY is configured and token matches, returns null (by design for testing)
|
|
44
|
+
* @param token - User authentication token
|
|
45
|
+
* @param authStrategy - Optional authentication strategy override
|
|
40
46
|
*/
|
|
41
|
-
getUserInfo(token: string): Promise<UserInfo | null>;
|
|
47
|
+
getUserInfo(token: string, authStrategy?: AuthStrategy): Promise<UserInfo | null>;
|
|
42
48
|
/**
|
|
43
49
|
* Logout user
|
|
44
50
|
*/
|
|
45
51
|
logout(): Promise<void>;
|
|
46
52
|
/**
|
|
47
53
|
* Check if user is authenticated (has valid token)
|
|
54
|
+
* @param token - User authentication token
|
|
55
|
+
* @param authStrategy - Optional authentication strategy override
|
|
48
56
|
*/
|
|
49
|
-
isAuthenticated(token: string): Promise<boolean>;
|
|
57
|
+
isAuthenticated(token: string, authStrategy?: AuthStrategy): Promise<boolean>;
|
|
50
58
|
}
|
|
51
59
|
//# sourceMappingURL=auth.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.service.d.ts","sourceRoot":"","sources":["../../src/services/auth.service.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAoB,QAAQ,EAAc,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAE7F,qBAAa,WAAW;IACtB,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,KAAK,CAAe;IAC5B,OAAO,CAAC,MAAM,CAAmB;gBAErB,UAAU,EAAE,UAAU,EAAE,KAAK,EAAE,YAAY;IAMvD;;;OAGG;IACH,OAAO,CAAC,aAAa;IAIrB;;;OAGG;IACG,mBAAmB,IAAI,OAAO,CAAC,MAAM,CAAC;IA+B5C;;;OAGG;IACH,KAAK,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM;IAKlC;;;;;OAKG;IACG,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;IAuBjF;;;;;OAKG;IACG,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IA2BnF;;;;;OAKG;IACG,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC;IAuBvF;;OAEG;IACG,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC;IAY7B;;;;OAIG;IACG,eAAe,CAAC,KAAK,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,OAAO,CAAC;CAGpF"}
|
|
@@ -89,15 +89,17 @@ class AuthService {
|
|
|
89
89
|
/**
|
|
90
90
|
* Validate token with controller
|
|
91
91
|
* If API_KEY is configured and token matches, returns true without calling controller
|
|
92
|
+
* @param token - User authentication token
|
|
93
|
+
* @param authStrategy - Optional authentication strategy override
|
|
92
94
|
*/
|
|
93
|
-
async validateToken(token) {
|
|
95
|
+
async validateToken(token, authStrategy) {
|
|
94
96
|
// Check API_KEY bypass for testing
|
|
95
97
|
if (this.isApiKeyToken(token)) {
|
|
96
98
|
return true;
|
|
97
99
|
}
|
|
98
100
|
try {
|
|
99
101
|
const result = await this.httpClient.authenticatedRequest('POST', '/api/auth/validate', // Backend knows app/env from client token
|
|
100
|
-
token);
|
|
102
|
+
token, undefined, undefined, authStrategy);
|
|
101
103
|
return result.authenticated;
|
|
102
104
|
}
|
|
103
105
|
catch (error) {
|
|
@@ -108,14 +110,16 @@ class AuthService {
|
|
|
108
110
|
/**
|
|
109
111
|
* Get user information from token
|
|
110
112
|
* If API_KEY is configured and token matches, returns null (by design for testing)
|
|
113
|
+
* @param token - User authentication token
|
|
114
|
+
* @param authStrategy - Optional authentication strategy override
|
|
111
115
|
*/
|
|
112
|
-
async getUser(token) {
|
|
116
|
+
async getUser(token, authStrategy) {
|
|
113
117
|
// Check API_KEY bypass for testing - return null by design
|
|
114
118
|
if (this.isApiKeyToken(token)) {
|
|
115
119
|
return null;
|
|
116
120
|
}
|
|
117
121
|
try {
|
|
118
|
-
const result = await this.httpClient.authenticatedRequest('POST', '/api/auth/validate', token);
|
|
122
|
+
const result = await this.httpClient.authenticatedRequest('POST', '/api/auth/validate', token, undefined, undefined, authStrategy);
|
|
119
123
|
if (result.authenticated && result.user) {
|
|
120
124
|
return result.user;
|
|
121
125
|
}
|
|
@@ -129,14 +133,16 @@ class AuthService {
|
|
|
129
133
|
/**
|
|
130
134
|
* Get user information from GET /api/auth/user endpoint
|
|
131
135
|
* If API_KEY is configured and token matches, returns null (by design for testing)
|
|
136
|
+
* @param token - User authentication token
|
|
137
|
+
* @param authStrategy - Optional authentication strategy override
|
|
132
138
|
*/
|
|
133
|
-
async getUserInfo(token) {
|
|
139
|
+
async getUserInfo(token, authStrategy) {
|
|
134
140
|
// Check API_KEY bypass for testing - return null by design
|
|
135
141
|
if (this.isApiKeyToken(token)) {
|
|
136
142
|
return null;
|
|
137
143
|
}
|
|
138
144
|
try {
|
|
139
|
-
const user = await this.httpClient.authenticatedRequest('GET', '/api/auth/user', token);
|
|
145
|
+
const user = await this.httpClient.authenticatedRequest('GET', '/api/auth/user', token, undefined, undefined, authStrategy);
|
|
140
146
|
return user;
|
|
141
147
|
}
|
|
142
148
|
catch (error) {
|
|
@@ -159,9 +165,11 @@ class AuthService {
|
|
|
159
165
|
}
|
|
160
166
|
/**
|
|
161
167
|
* Check if user is authenticated (has valid token)
|
|
168
|
+
* @param token - User authentication token
|
|
169
|
+
* @param authStrategy - Optional authentication strategy override
|
|
162
170
|
*/
|
|
163
|
-
async isAuthenticated(token) {
|
|
164
|
-
return this.validateToken(token);
|
|
171
|
+
async isAuthenticated(token, authStrategy) {
|
|
172
|
+
return this.validateToken(token, authStrategy);
|
|
165
173
|
}
|
|
166
174
|
}
|
|
167
175
|
exports.AuthService = AuthService;
|