@tritonium/api-client 2.1.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 +313 -0
- package/dist/auth.d.mts +86 -0
- package/dist/auth.d.ts +86 -0
- package/dist/auth.js +77 -0
- package/dist/auth.js.map +1 -0
- package/dist/auth.mjs +71 -0
- package/dist/auth.mjs.map +1 -0
- package/dist/index.d.mts +1885 -0
- package/dist/index.d.ts +1885 -0
- package/dist/index.js +3045 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2992 -0
- package/dist/index.mjs.map +1 -0
- package/dist/webhooks.d.mts +191 -0
- package/dist/webhooks.d.ts +191 -0
- package/dist/webhooks.js +125 -0
- package/dist/webhooks.js.map +1 -0
- package/dist/webhooks.mjs +95 -0
- package/dist/webhooks.mjs.map +1 -0
- package/package.json +72 -0
package/README.md
ADDED
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
# @tritonium/api-client
|
|
2
|
+
|
|
3
|
+
Official TypeScript/JavaScript SDK for the Tritonium API - Customer feedback analytics platform.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @tritonium/api-client
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
### Using API Key Authentication
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { configureApiKey, AppsService } from '@tritonium/api-client';
|
|
17
|
+
|
|
18
|
+
// Configure authentication
|
|
19
|
+
configureApiKey('trtn_live_your_key_here');
|
|
20
|
+
|
|
21
|
+
// Make API calls
|
|
22
|
+
const apps = await AppsService.getApps();
|
|
23
|
+
console.log(apps);
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
### Using Bearer Token (JWT)
|
|
27
|
+
|
|
28
|
+
```typescript
|
|
29
|
+
import { configureBearerToken, AppsService } from '@tritonium/api-client';
|
|
30
|
+
|
|
31
|
+
// Configure with Cognito JWT token
|
|
32
|
+
configureBearerToken('your_jwt_token');
|
|
33
|
+
|
|
34
|
+
// Make API calls
|
|
35
|
+
const apps = await AppsService.getApps();
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Authentication
|
|
39
|
+
|
|
40
|
+
The SDK supports two authentication methods:
|
|
41
|
+
|
|
42
|
+
### API Key Authentication
|
|
43
|
+
|
|
44
|
+
Best for server-side applications and integrations.
|
|
45
|
+
|
|
46
|
+
```typescript
|
|
47
|
+
import { configureApiKey } from '@tritonium/api-client/auth';
|
|
48
|
+
|
|
49
|
+
configureApiKey('trtn_live_abc123...');
|
|
50
|
+
|
|
51
|
+
// Or with a custom base URL
|
|
52
|
+
configureApiKey('trtn_test_abc123...', 'https://staging-api.tritonium.com');
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Bearer Token Authentication
|
|
56
|
+
|
|
57
|
+
Best for applications with existing Cognito authentication.
|
|
58
|
+
|
|
59
|
+
```typescript
|
|
60
|
+
import { configureBearerToken } from '@tritonium/api-client/auth';
|
|
61
|
+
|
|
62
|
+
configureBearerToken('eyJhbGciOiJSUzI1NiIs...');
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
### Advanced Configuration
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
import { configure, getConfiguration, clearAuth } from '@tritonium/api-client/auth';
|
|
69
|
+
|
|
70
|
+
// Configure with multiple options
|
|
71
|
+
configure({
|
|
72
|
+
apiKey: 'trtn_live_abc123...',
|
|
73
|
+
baseUrl: 'https://staging-api.tritonium.com',
|
|
74
|
+
headers: { 'X-Custom-Header': 'value' },
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// Check current configuration
|
|
78
|
+
const config = getConfiguration();
|
|
79
|
+
console.log(config.hasApiKey); // true
|
|
80
|
+
|
|
81
|
+
// Clear authentication
|
|
82
|
+
clearAuth();
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## Webhook Verification
|
|
86
|
+
|
|
87
|
+
Verify incoming webhooks from Tritonium to ensure they're authentic.
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
import express from 'express';
|
|
91
|
+
import {
|
|
92
|
+
verifyWebhook,
|
|
93
|
+
WebhookVerificationError,
|
|
94
|
+
EventTypes,
|
|
95
|
+
} from '@tritonium/api-client/webhooks';
|
|
96
|
+
|
|
97
|
+
const app = express();
|
|
98
|
+
const WEBHOOK_SECRET = 'whsec_your_secret';
|
|
99
|
+
|
|
100
|
+
app.post('/webhook', express.raw({ type: 'application/json' }), (req, res) => {
|
|
101
|
+
try {
|
|
102
|
+
const event = verifyWebhook({
|
|
103
|
+
payload: req.body,
|
|
104
|
+
signature: req.headers['x-tritonium-signature'] as string,
|
|
105
|
+
timestamp: req.headers['x-tritonium-timestamp'] as string,
|
|
106
|
+
secret: WEBHOOK_SECRET,
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
switch (event.eventType) {
|
|
110
|
+
case EventTypes.REVIEW_RECEIVED:
|
|
111
|
+
console.log('New review:', event.data);
|
|
112
|
+
break;
|
|
113
|
+
case EventTypes.ALERT_TRIGGERED:
|
|
114
|
+
console.log('Alert:', event.data);
|
|
115
|
+
break;
|
|
116
|
+
case EventTypes.CRISIS_DETECTED:
|
|
117
|
+
console.log('Crisis detected:', event.data);
|
|
118
|
+
break;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
res.json({ status: 'ok' });
|
|
122
|
+
} catch (e) {
|
|
123
|
+
if (e instanceof WebhookVerificationError) {
|
|
124
|
+
console.error('Webhook verification failed:', e.message);
|
|
125
|
+
res.status(401).json({ error: e.message });
|
|
126
|
+
} else {
|
|
127
|
+
throw e;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
### Webhook Event Types
|
|
134
|
+
|
|
135
|
+
| Event Type | Description |
|
|
136
|
+
|------------|-------------|
|
|
137
|
+
| `review.received` | New review was received |
|
|
138
|
+
| `alert.triggered` | Alert rule was triggered |
|
|
139
|
+
| `crisis.detected` | Crisis event was detected |
|
|
140
|
+
| `insight.generated` | New insight was generated |
|
|
141
|
+
| `analysis.completed` | Analysis job completed |
|
|
142
|
+
| `test.ping` | Test webhook (manual trigger) |
|
|
143
|
+
|
|
144
|
+
### Typed Event Data
|
|
145
|
+
|
|
146
|
+
```typescript
|
|
147
|
+
import type {
|
|
148
|
+
ReviewReceivedData,
|
|
149
|
+
AlertTriggeredData,
|
|
150
|
+
CrisisDetectedData,
|
|
151
|
+
} from '@tritonium/api-client/webhooks';
|
|
152
|
+
|
|
153
|
+
// Type-safe event handling
|
|
154
|
+
const event = verifyWebhook<ReviewReceivedData>({ ... });
|
|
155
|
+
console.log(event.data.review_id);
|
|
156
|
+
console.log(event.data.rating);
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Available Services
|
|
160
|
+
|
|
161
|
+
| Service | Description |
|
|
162
|
+
|---------|-------------|
|
|
163
|
+
| `AppsService` | Manage connected apps and platforms |
|
|
164
|
+
| `ReviewsService` | Access and manage reviews |
|
|
165
|
+
| `AlertsService` | Configure and manage alerts |
|
|
166
|
+
| `InsightsService` | Access generated insights |
|
|
167
|
+
| `IntegrationsService` | Manage integrations (Slack, etc.) |
|
|
168
|
+
| `RatingsService` | Access ratings and analytics |
|
|
169
|
+
| `PredictionsService` | ML predictions and forecasting |
|
|
170
|
+
| `BillingService` | Subscription and billing |
|
|
171
|
+
| `CredentialsService` | Manage API credentials (Admin) |
|
|
172
|
+
| `WorkflowsService` | Workflow automation |
|
|
173
|
+
| `UsersService` | User management |
|
|
174
|
+
| `HealthService` | API health checks |
|
|
175
|
+
|
|
176
|
+
### Service Examples
|
|
177
|
+
|
|
178
|
+
**Managing Apps:**
|
|
179
|
+
```typescript
|
|
180
|
+
import { AppsService } from '@tritonium/api-client';
|
|
181
|
+
|
|
182
|
+
// List all connected apps
|
|
183
|
+
const apps = await AppsService.getApps();
|
|
184
|
+
|
|
185
|
+
// Connect a new app
|
|
186
|
+
const newApp = await AppsService.connectApp({
|
|
187
|
+
platform: 'app_store',
|
|
188
|
+
external_app_id: '123456789',
|
|
189
|
+
credential_id: 'cred-abc'
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
// Trigger review sync
|
|
193
|
+
await AppsService.syncReviews({ app_uuid: 'app-123' });
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
**Working with Reviews:**
|
|
197
|
+
```typescript
|
|
198
|
+
import { ReviewsService } from '@tritonium/api-client';
|
|
199
|
+
|
|
200
|
+
// Get reviews with filters
|
|
201
|
+
const reviews = await ReviewsService.getReviews({
|
|
202
|
+
app_uuid: 'app-123',
|
|
203
|
+
rating_min: 1,
|
|
204
|
+
rating_max: 3,
|
|
205
|
+
limit: 50
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
// Generate AI reply suggestion
|
|
209
|
+
const reply = await ReviewsService.generateReply({
|
|
210
|
+
app_uuid: 'app-123',
|
|
211
|
+
review_id: 'review-456'
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
// Post reply to store
|
|
215
|
+
await ReviewsService.postReply({
|
|
216
|
+
app_uuid: 'app-123',
|
|
217
|
+
review_id: 'review-456',
|
|
218
|
+
text: reply.suggested_text
|
|
219
|
+
});
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
**Predictions & Forecasting:**
|
|
223
|
+
```typescript
|
|
224
|
+
import { PredictionsService } from '@tritonium/api-client';
|
|
225
|
+
|
|
226
|
+
// Get rating forecast
|
|
227
|
+
const forecast = await PredictionsService.getRatingForecast({
|
|
228
|
+
app_uuid: 'app-123',
|
|
229
|
+
horizon: 30
|
|
230
|
+
});
|
|
231
|
+
console.log(`Predicted rating: ${forecast.forecasted_rating}`);
|
|
232
|
+
|
|
233
|
+
// Estimate feature impact
|
|
234
|
+
const impact = await PredictionsService.estimateFeatureImpact({
|
|
235
|
+
app_uuid: 'app-123',
|
|
236
|
+
feature_type: 'bug_fix',
|
|
237
|
+
affected_topics: ['crashes', 'performance']
|
|
238
|
+
});
|
|
239
|
+
```
|
|
240
|
+
|
|
241
|
+
**Managing Credentials (Admin only):**
|
|
242
|
+
```typescript
|
|
243
|
+
import { CredentialsService } from '@tritonium/api-client';
|
|
244
|
+
|
|
245
|
+
// List credentials
|
|
246
|
+
const credentials = await CredentialsService.listCredentials();
|
|
247
|
+
|
|
248
|
+
// Create new credential
|
|
249
|
+
await CredentialsService.createCredential({
|
|
250
|
+
name: 'App Store Connect',
|
|
251
|
+
platform: 'app_store',
|
|
252
|
+
credentials: {
|
|
253
|
+
key_id: 'ABC123',
|
|
254
|
+
issuer_id: 'xxx-yyy-zzz',
|
|
255
|
+
private_key: '-----BEGIN PRIVATE KEY-----...'
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
**Workflow Automation:**
|
|
261
|
+
```typescript
|
|
262
|
+
import { WorkflowsService } from '@tritonium/api-client';
|
|
263
|
+
|
|
264
|
+
// List workflow templates
|
|
265
|
+
const templates = await WorkflowsService.listTemplates();
|
|
266
|
+
|
|
267
|
+
// Create workflow from template
|
|
268
|
+
const workflow = await WorkflowsService.createFromTemplate({
|
|
269
|
+
name: 'Daily Digest',
|
|
270
|
+
template_id: 'weekly-digest',
|
|
271
|
+
config: {
|
|
272
|
+
schedule: '0 9 * * *',
|
|
273
|
+
channels: ['slack']
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
// Pause a workflow
|
|
278
|
+
await WorkflowsService.pauseWorkflow({ workflow_id: workflow.id });
|
|
279
|
+
```
|
|
280
|
+
|
|
281
|
+
## Error Handling
|
|
282
|
+
|
|
283
|
+
```typescript
|
|
284
|
+
import { ApiError } from '@tritonium/api-client';
|
|
285
|
+
|
|
286
|
+
try {
|
|
287
|
+
const apps = await AppsService.getApps();
|
|
288
|
+
} catch (error) {
|
|
289
|
+
if (error instanceof ApiError) {
|
|
290
|
+
console.error(`API Error ${error.status}: ${error.message}`);
|
|
291
|
+
console.error('Response body:', error.body);
|
|
292
|
+
} else {
|
|
293
|
+
throw error;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
```
|
|
297
|
+
|
|
298
|
+
## TypeScript Support
|
|
299
|
+
|
|
300
|
+
This SDK is written in TypeScript and includes full type definitions. All models and services are fully typed.
|
|
301
|
+
|
|
302
|
+
```typescript
|
|
303
|
+
import type { AppSummary, ReviewSummary, Alert } from '@tritonium/api-client';
|
|
304
|
+
```
|
|
305
|
+
|
|
306
|
+
## Requirements
|
|
307
|
+
|
|
308
|
+
- Node.js >= 18.0.0
|
|
309
|
+
- TypeScript >= 5.0 (for TypeScript users)
|
|
310
|
+
|
|
311
|
+
## License
|
|
312
|
+
|
|
313
|
+
MIT
|
package/dist/auth.d.mts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication helpers for the Tritonium API.
|
|
3
|
+
*
|
|
4
|
+
* This module provides utilities for API key authentication and token management.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { configureApiKey, configureBearerToken } from './auth';
|
|
9
|
+
*
|
|
10
|
+
* // Using API key
|
|
11
|
+
* configureApiKey('trtn_live_your_key_here');
|
|
12
|
+
*
|
|
13
|
+
* // Using Bearer token
|
|
14
|
+
* configureBearerToken('your_jwt_token');
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Configure the SDK to use API key authentication.
|
|
19
|
+
*
|
|
20
|
+
* @param apiKey - Your Tritonium API key (starts with trtn_live_ or trtn_test_)
|
|
21
|
+
* @param baseUrl - Optional custom base URL (defaults to production)
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* import { configureApiKey } from '@tritonium/api-client/auth';
|
|
26
|
+
* import { AppsService } from '@tritonium/api-client';
|
|
27
|
+
*
|
|
28
|
+
* configureApiKey('trtn_live_abc123...');
|
|
29
|
+
*
|
|
30
|
+
* const apps = await AppsService.getApps();
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
declare function configureApiKey(apiKey: string, baseUrl?: string): void;
|
|
34
|
+
/**
|
|
35
|
+
* Configure the SDK to use Bearer token authentication.
|
|
36
|
+
*
|
|
37
|
+
* @param token - Your Cognito JWT access token
|
|
38
|
+
* @param baseUrl - Optional custom base URL (defaults to production)
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* import { configureBearerToken } from '@tritonium/api-client/auth';
|
|
43
|
+
* import { AppsService } from '@tritonium/api-client';
|
|
44
|
+
*
|
|
45
|
+
* configureBearerToken('eyJhbGciOiJSUzI1NiIs...');
|
|
46
|
+
*
|
|
47
|
+
* const apps = await AppsService.getApps();
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
declare function configureBearerToken(token: string, baseUrl?: string): void;
|
|
51
|
+
/**
|
|
52
|
+
* Configure the SDK with custom settings.
|
|
53
|
+
*
|
|
54
|
+
* @param config - Configuration options
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* import { configure } from '@tritonium/api-client/auth';
|
|
59
|
+
*
|
|
60
|
+
* configure({
|
|
61
|
+
* apiKey: 'trtn_live_abc123...',
|
|
62
|
+
* baseUrl: 'https://staging-api.tritonium.com',
|
|
63
|
+
* headers: { 'X-Custom-Header': 'value' },
|
|
64
|
+
* });
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
declare function configure(config: {
|
|
68
|
+
apiKey?: string;
|
|
69
|
+
token?: string;
|
|
70
|
+
baseUrl?: string;
|
|
71
|
+
headers?: Record<string, string>;
|
|
72
|
+
}): void;
|
|
73
|
+
/**
|
|
74
|
+
* Get the current configuration.
|
|
75
|
+
*/
|
|
76
|
+
declare function getConfiguration(): {
|
|
77
|
+
baseUrl: string;
|
|
78
|
+
hasApiKey: boolean;
|
|
79
|
+
hasToken: boolean;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Clear all authentication configuration.
|
|
83
|
+
*/
|
|
84
|
+
declare function clearAuth(): void;
|
|
85
|
+
|
|
86
|
+
export { clearAuth, configure, configureApiKey, configureBearerToken, getConfiguration };
|
package/dist/auth.d.ts
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication helpers for the Tritonium API.
|
|
3
|
+
*
|
|
4
|
+
* This module provides utilities for API key authentication and token management.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```typescript
|
|
8
|
+
* import { configureApiKey, configureBearerToken } from './auth';
|
|
9
|
+
*
|
|
10
|
+
* // Using API key
|
|
11
|
+
* configureApiKey('trtn_live_your_key_here');
|
|
12
|
+
*
|
|
13
|
+
* // Using Bearer token
|
|
14
|
+
* configureBearerToken('your_jwt_token');
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
/**
|
|
18
|
+
* Configure the SDK to use API key authentication.
|
|
19
|
+
*
|
|
20
|
+
* @param apiKey - Your Tritonium API key (starts with trtn_live_ or trtn_test_)
|
|
21
|
+
* @param baseUrl - Optional custom base URL (defaults to production)
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* import { configureApiKey } from '@tritonium/api-client/auth';
|
|
26
|
+
* import { AppsService } from '@tritonium/api-client';
|
|
27
|
+
*
|
|
28
|
+
* configureApiKey('trtn_live_abc123...');
|
|
29
|
+
*
|
|
30
|
+
* const apps = await AppsService.getApps();
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
declare function configureApiKey(apiKey: string, baseUrl?: string): void;
|
|
34
|
+
/**
|
|
35
|
+
* Configure the SDK to use Bearer token authentication.
|
|
36
|
+
*
|
|
37
|
+
* @param token - Your Cognito JWT access token
|
|
38
|
+
* @param baseUrl - Optional custom base URL (defaults to production)
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```typescript
|
|
42
|
+
* import { configureBearerToken } from '@tritonium/api-client/auth';
|
|
43
|
+
* import { AppsService } from '@tritonium/api-client';
|
|
44
|
+
*
|
|
45
|
+
* configureBearerToken('eyJhbGciOiJSUzI1NiIs...');
|
|
46
|
+
*
|
|
47
|
+
* const apps = await AppsService.getApps();
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
declare function configureBearerToken(token: string, baseUrl?: string): void;
|
|
51
|
+
/**
|
|
52
|
+
* Configure the SDK with custom settings.
|
|
53
|
+
*
|
|
54
|
+
* @param config - Configuration options
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```typescript
|
|
58
|
+
* import { configure } from '@tritonium/api-client/auth';
|
|
59
|
+
*
|
|
60
|
+
* configure({
|
|
61
|
+
* apiKey: 'trtn_live_abc123...',
|
|
62
|
+
* baseUrl: 'https://staging-api.tritonium.com',
|
|
63
|
+
* headers: { 'X-Custom-Header': 'value' },
|
|
64
|
+
* });
|
|
65
|
+
* ```
|
|
66
|
+
*/
|
|
67
|
+
declare function configure(config: {
|
|
68
|
+
apiKey?: string;
|
|
69
|
+
token?: string;
|
|
70
|
+
baseUrl?: string;
|
|
71
|
+
headers?: Record<string, string>;
|
|
72
|
+
}): void;
|
|
73
|
+
/**
|
|
74
|
+
* Get the current configuration.
|
|
75
|
+
*/
|
|
76
|
+
declare function getConfiguration(): {
|
|
77
|
+
baseUrl: string;
|
|
78
|
+
hasApiKey: boolean;
|
|
79
|
+
hasToken: boolean;
|
|
80
|
+
};
|
|
81
|
+
/**
|
|
82
|
+
* Clear all authentication configuration.
|
|
83
|
+
*/
|
|
84
|
+
declare function clearAuth(): void;
|
|
85
|
+
|
|
86
|
+
export { clearAuth, configure, configureApiKey, configureBearerToken, getConfiguration };
|
package/dist/auth.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// core/OpenAPI.ts
|
|
4
|
+
var OpenAPI = {
|
|
5
|
+
BASE: "https://api.tritonium.com",
|
|
6
|
+
TOKEN: void 0,
|
|
7
|
+
HEADERS: void 0};
|
|
8
|
+
|
|
9
|
+
// auth.ts
|
|
10
|
+
function configureApiKey(apiKey, baseUrl = "https://api.tritonium.com") {
|
|
11
|
+
OpenAPI.BASE = baseUrl;
|
|
12
|
+
const existingHeaders = typeof OpenAPI.HEADERS === "object" && OpenAPI.HEADERS !== null ? OpenAPI.HEADERS : {};
|
|
13
|
+
OpenAPI.HEADERS = {
|
|
14
|
+
...existingHeaders,
|
|
15
|
+
"X-API-Key": apiKey
|
|
16
|
+
};
|
|
17
|
+
if (OpenAPI.TOKEN) {
|
|
18
|
+
OpenAPI.TOKEN = void 0;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function configureBearerToken(token, baseUrl = "https://api.tritonium.com") {
|
|
22
|
+
OpenAPI.BASE = baseUrl;
|
|
23
|
+
OpenAPI.TOKEN = token;
|
|
24
|
+
if (OpenAPI.HEADERS && "X-API-Key" in OpenAPI.HEADERS) {
|
|
25
|
+
const { "X-API-Key": _, ...rest } = OpenAPI.HEADERS;
|
|
26
|
+
OpenAPI.HEADERS = rest;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
function configure(config) {
|
|
30
|
+
if (config.baseUrl) {
|
|
31
|
+
OpenAPI.BASE = config.baseUrl;
|
|
32
|
+
}
|
|
33
|
+
if (config.apiKey) {
|
|
34
|
+
OpenAPI.HEADERS = {
|
|
35
|
+
...OpenAPI.HEADERS,
|
|
36
|
+
...config.headers,
|
|
37
|
+
"X-API-Key": config.apiKey
|
|
38
|
+
};
|
|
39
|
+
OpenAPI.TOKEN = void 0;
|
|
40
|
+
} else if (config.token) {
|
|
41
|
+
OpenAPI.TOKEN = config.token;
|
|
42
|
+
OpenAPI.HEADERS = {
|
|
43
|
+
...OpenAPI.HEADERS,
|
|
44
|
+
...config.headers
|
|
45
|
+
};
|
|
46
|
+
} else if (config.headers) {
|
|
47
|
+
OpenAPI.HEADERS = {
|
|
48
|
+
...OpenAPI.HEADERS,
|
|
49
|
+
...config.headers
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function getConfiguration() {
|
|
54
|
+
const headers = OpenAPI.HEADERS;
|
|
55
|
+
const hasApiKey = typeof headers === "object" && headers !== null && "X-API-Key" in headers;
|
|
56
|
+
return {
|
|
57
|
+
baseUrl: OpenAPI.BASE,
|
|
58
|
+
hasApiKey,
|
|
59
|
+
hasToken: Boolean(OpenAPI.TOKEN)
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function clearAuth() {
|
|
63
|
+
OpenAPI.TOKEN = void 0;
|
|
64
|
+
const headers = OpenAPI.HEADERS;
|
|
65
|
+
if (typeof headers === "object" && headers !== null && "X-API-Key" in headers) {
|
|
66
|
+
const { "X-API-Key": _, ...rest } = headers;
|
|
67
|
+
OpenAPI.HEADERS = rest;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
exports.clearAuth = clearAuth;
|
|
72
|
+
exports.configure = configure;
|
|
73
|
+
exports.configureApiKey = configureApiKey;
|
|
74
|
+
exports.configureBearerToken = configureBearerToken;
|
|
75
|
+
exports.getConfiguration = getConfiguration;
|
|
76
|
+
//# sourceMappingURL=auth.js.map
|
|
77
|
+
//# sourceMappingURL=auth.js.map
|
package/dist/auth.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../core/OpenAPI.ts","../auth.ts"],"names":[],"mappings":";;;AAqBO,IAAM,OAAA,GAAyB;AAAA,EAClC,IAAA,EAAM,2BAAA;AAAA,EAIN,KAAA,EAAO,MAAA;AAAA,EAGP,OAAA,EAAS,MAEb,CAAA;;;ACIO,SAAS,eAAA,CACd,MAAA,EACA,OAAA,GAAkB,2BAAA,EACZ;AACN,EAAA,OAAA,CAAQ,IAAA,GAAO,OAAA;AACf,EAAA,MAAM,eAAA,GAAkB,OAAO,OAAA,CAAQ,OAAA,KAAY,QAAA,IAAY,QAAQ,OAAA,KAAY,IAAA,GAAO,OAAA,CAAQ,OAAA,GAAU,EAAC;AAC7G,EAAA,OAAA,CAAQ,OAAA,GAAU;AAAA,IAChB,GAAG,eAAA;AAAA,IACH,WAAA,EAAa;AAAA,GACf;AAEA,EAAA,IAAI,QAAQ,KAAA,EAAO;AACjB,IAAA,OAAA,CAAQ,KAAA,GAAQ,MAAA;AAAA,EAClB;AACF;AAkBO,SAAS,oBAAA,CACd,KAAA,EACA,OAAA,GAAkB,2BAAA,EACZ;AACN,EAAA,OAAA,CAAQ,IAAA,GAAO,OAAA;AACf,EAAA,OAAA,CAAQ,KAAA,GAAQ,KAAA;AAEhB,EAAA,IAAI,OAAA,CAAQ,OAAA,IAAW,WAAA,IAAe,OAAA,CAAQ,OAAA,EAAS;AACrD,IAAA,MAAM,EAAE,WAAA,EAAa,CAAA,EAAG,GAAG,IAAA,KAAS,OAAA,CAAQ,OAAA;AAC5C,IAAA,OAAA,CAAQ,OAAA,GAAU,IAAA;AAAA,EACpB;AACF;AAkBO,SAAS,UAAU,MAAA,EAKjB;AACP,EAAA,IAAI,OAAO,OAAA,EAAS;AAClB,IAAA,OAAA,CAAQ,OAAO,MAAA,CAAO,OAAA;AAAA,EACxB;AAEA,EAAA,IAAI,OAAO,MAAA,EAAQ;AACjB,IAAA,OAAA,CAAQ,OAAA,GAAU;AAAA,MAChB,GAAG,OAAA,CAAQ,OAAA;AAAA,MACX,GAAG,MAAA,CAAO,OAAA;AAAA,MACV,aAAa,MAAA,CAAO;AAAA,KACtB;AACA,IAAA,OAAA,CAAQ,KAAA,GAAQ,MAAA;AAAA,EAClB,CAAA,MAAA,IAAW,OAAO,KAAA,EAAO;AACvB,IAAA,OAAA,CAAQ,QAAQ,MAAA,CAAO,KAAA;AACvB,IAAA,OAAA,CAAQ,OAAA,GAAU;AAAA,MAChB,GAAG,OAAA,CAAQ,OAAA;AAAA,MACX,GAAG,MAAA,CAAO;AAAA,KACZ;AAAA,EACF,CAAA,MAAA,IAAW,OAAO,OAAA,EAAS;AACzB,IAAA,OAAA,CAAQ,OAAA,GAAU;AAAA,MAChB,GAAG,OAAA,CAAQ,OAAA;AAAA,MACX,GAAG,MAAA,CAAO;AAAA,KACZ;AAAA,EACF;AACF;AAKO,SAAS,gBAAA,GAId;AACA,EAAA,MAAM,UAAU,OAAA,CAAQ,OAAA;AACxB,EAAA,MAAM,YAAY,OAAO,OAAA,KAAY,QAAA,IAAY,OAAA,KAAY,QAAQ,WAAA,IAAe,OAAA;AACpF,EAAA,OAAO;AAAA,IACL,SAAS,OAAA,CAAQ,IAAA;AAAA,IACjB,SAAA;AAAA,IACA,QAAA,EAAU,OAAA,CAAQ,OAAA,CAAQ,KAAK;AAAA,GACjC;AACF;AAKO,SAAS,SAAA,GAAkB;AAChC,EAAA,OAAA,CAAQ,KAAA,GAAQ,MAAA;AAChB,EAAA,MAAM,UAAU,OAAA,CAAQ,OAAA;AACxB,EAAA,IAAI,OAAO,OAAA,KAAY,QAAA,IAAY,OAAA,KAAY,IAAA,IAAQ,eAAe,OAAA,EAAS;AAC7E,IAAA,MAAM,EAAE,WAAA,EAAa,CAAA,EAAG,GAAG,MAAK,GAAI,OAAA;AACpC,IAAA,OAAA,CAAQ,OAAA,GAAU,IAAA;AAAA,EACpB;AACF","file":"auth.js","sourcesContent":["/* generated using openapi-typescript-codegen -- do not edit */\n/* istanbul ignore file */\n/* tslint:disable */\n/* eslint-disable */\nimport type { ApiRequestOptions } from './ApiRequestOptions';\n\ntype Resolver<T> = (options: ApiRequestOptions) => Promise<T>;\ntype Headers = Record<string, string>;\n\nexport type OpenAPIConfig = {\n BASE: string;\n VERSION: string;\n WITH_CREDENTIALS: boolean;\n CREDENTIALS: 'include' | 'omit' | 'same-origin';\n TOKEN?: string | Resolver<string> | undefined;\n USERNAME?: string | Resolver<string> | undefined;\n PASSWORD?: string | Resolver<string> | undefined;\n HEADERS?: Headers | Resolver<Headers> | undefined;\n ENCODE_PATH?: ((path: string) => string) | undefined;\n};\n\nexport const OpenAPI: OpenAPIConfig = {\n BASE: 'https://api.tritonium.com',\n VERSION: '1.0.0',\n WITH_CREDENTIALS: false,\n CREDENTIALS: 'include',\n TOKEN: undefined,\n USERNAME: undefined,\n PASSWORD: undefined,\n HEADERS: undefined,\n ENCODE_PATH: undefined,\n};\n","/**\n * Authentication helpers for the Tritonium API.\n *\n * This module provides utilities for API key authentication and token management.\n *\n * @example\n * ```typescript\n * import { configureApiKey, configureBearerToken } from './auth';\n *\n * // Using API key\n * configureApiKey('trtn_live_your_key_here');\n *\n * // Using Bearer token\n * configureBearerToken('your_jwt_token');\n * ```\n */\n\nimport { OpenAPI } from './core/OpenAPI';\n\n/**\n * Configure the SDK to use API key authentication.\n *\n * @param apiKey - Your Tritonium API key (starts with trtn_live_ or trtn_test_)\n * @param baseUrl - Optional custom base URL (defaults to production)\n *\n * @example\n * ```typescript\n * import { configureApiKey } from '@tritonium/api-client/auth';\n * import { AppsService } from '@tritonium/api-client';\n *\n * configureApiKey('trtn_live_abc123...');\n *\n * const apps = await AppsService.getApps();\n * ```\n */\nexport function configureApiKey(\n apiKey: string,\n baseUrl: string = 'https://api.tritonium.com'\n): void {\n OpenAPI.BASE = baseUrl;\n const existingHeaders = typeof OpenAPI.HEADERS === 'object' && OpenAPI.HEADERS !== null ? OpenAPI.HEADERS : {};\n OpenAPI.HEADERS = {\n ...existingHeaders,\n 'X-API-Key': apiKey,\n };\n // Remove Bearer token if switching to API key\n if (OpenAPI.TOKEN) {\n OpenAPI.TOKEN = undefined;\n }\n}\n\n/**\n * Configure the SDK to use Bearer token authentication.\n *\n * @param token - Your Cognito JWT access token\n * @param baseUrl - Optional custom base URL (defaults to production)\n *\n * @example\n * ```typescript\n * import { configureBearerToken } from '@tritonium/api-client/auth';\n * import { AppsService } from '@tritonium/api-client';\n *\n * configureBearerToken('eyJhbGciOiJSUzI1NiIs...');\n *\n * const apps = await AppsService.getApps();\n * ```\n */\nexport function configureBearerToken(\n token: string,\n baseUrl: string = 'https://api.tritonium.com'\n): void {\n OpenAPI.BASE = baseUrl;\n OpenAPI.TOKEN = token;\n // Remove API key header if switching to Bearer\n if (OpenAPI.HEADERS && 'X-API-Key' in OpenAPI.HEADERS) {\n const { 'X-API-Key': _, ...rest } = OpenAPI.HEADERS;\n OpenAPI.HEADERS = rest;\n }\n}\n\n/**\n * Configure the SDK with custom settings.\n *\n * @param config - Configuration options\n *\n * @example\n * ```typescript\n * import { configure } from '@tritonium/api-client/auth';\n *\n * configure({\n * apiKey: 'trtn_live_abc123...',\n * baseUrl: 'https://staging-api.tritonium.com',\n * headers: { 'X-Custom-Header': 'value' },\n * });\n * ```\n */\nexport function configure(config: {\n apiKey?: string;\n token?: string;\n baseUrl?: string;\n headers?: Record<string, string>;\n}): void {\n if (config.baseUrl) {\n OpenAPI.BASE = config.baseUrl;\n }\n\n if (config.apiKey) {\n OpenAPI.HEADERS = {\n ...OpenAPI.HEADERS,\n ...config.headers,\n 'X-API-Key': config.apiKey,\n };\n OpenAPI.TOKEN = undefined;\n } else if (config.token) {\n OpenAPI.TOKEN = config.token;\n OpenAPI.HEADERS = {\n ...OpenAPI.HEADERS,\n ...config.headers,\n };\n } else if (config.headers) {\n OpenAPI.HEADERS = {\n ...OpenAPI.HEADERS,\n ...config.headers,\n };\n }\n}\n\n/**\n * Get the current configuration.\n */\nexport function getConfiguration(): {\n baseUrl: string;\n hasApiKey: boolean;\n hasToken: boolean;\n} {\n const headers = OpenAPI.HEADERS;\n const hasApiKey = typeof headers === 'object' && headers !== null && 'X-API-Key' in headers;\n return {\n baseUrl: OpenAPI.BASE,\n hasApiKey,\n hasToken: Boolean(OpenAPI.TOKEN),\n };\n}\n\n/**\n * Clear all authentication configuration.\n */\nexport function clearAuth(): void {\n OpenAPI.TOKEN = undefined;\n const headers = OpenAPI.HEADERS;\n if (typeof headers === 'object' && headers !== null && 'X-API-Key' in headers) {\n const { 'X-API-Key': _, ...rest } = headers;\n OpenAPI.HEADERS = rest;\n }\n}\n"]}
|
package/dist/auth.mjs
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
// core/OpenAPI.ts
|
|
2
|
+
var OpenAPI = {
|
|
3
|
+
BASE: "https://api.tritonium.com",
|
|
4
|
+
TOKEN: void 0,
|
|
5
|
+
HEADERS: void 0};
|
|
6
|
+
|
|
7
|
+
// auth.ts
|
|
8
|
+
function configureApiKey(apiKey, baseUrl = "https://api.tritonium.com") {
|
|
9
|
+
OpenAPI.BASE = baseUrl;
|
|
10
|
+
const existingHeaders = typeof OpenAPI.HEADERS === "object" && OpenAPI.HEADERS !== null ? OpenAPI.HEADERS : {};
|
|
11
|
+
OpenAPI.HEADERS = {
|
|
12
|
+
...existingHeaders,
|
|
13
|
+
"X-API-Key": apiKey
|
|
14
|
+
};
|
|
15
|
+
if (OpenAPI.TOKEN) {
|
|
16
|
+
OpenAPI.TOKEN = void 0;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
function configureBearerToken(token, baseUrl = "https://api.tritonium.com") {
|
|
20
|
+
OpenAPI.BASE = baseUrl;
|
|
21
|
+
OpenAPI.TOKEN = token;
|
|
22
|
+
if (OpenAPI.HEADERS && "X-API-Key" in OpenAPI.HEADERS) {
|
|
23
|
+
const { "X-API-Key": _, ...rest } = OpenAPI.HEADERS;
|
|
24
|
+
OpenAPI.HEADERS = rest;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function configure(config) {
|
|
28
|
+
if (config.baseUrl) {
|
|
29
|
+
OpenAPI.BASE = config.baseUrl;
|
|
30
|
+
}
|
|
31
|
+
if (config.apiKey) {
|
|
32
|
+
OpenAPI.HEADERS = {
|
|
33
|
+
...OpenAPI.HEADERS,
|
|
34
|
+
...config.headers,
|
|
35
|
+
"X-API-Key": config.apiKey
|
|
36
|
+
};
|
|
37
|
+
OpenAPI.TOKEN = void 0;
|
|
38
|
+
} else if (config.token) {
|
|
39
|
+
OpenAPI.TOKEN = config.token;
|
|
40
|
+
OpenAPI.HEADERS = {
|
|
41
|
+
...OpenAPI.HEADERS,
|
|
42
|
+
...config.headers
|
|
43
|
+
};
|
|
44
|
+
} else if (config.headers) {
|
|
45
|
+
OpenAPI.HEADERS = {
|
|
46
|
+
...OpenAPI.HEADERS,
|
|
47
|
+
...config.headers
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function getConfiguration() {
|
|
52
|
+
const headers = OpenAPI.HEADERS;
|
|
53
|
+
const hasApiKey = typeof headers === "object" && headers !== null && "X-API-Key" in headers;
|
|
54
|
+
return {
|
|
55
|
+
baseUrl: OpenAPI.BASE,
|
|
56
|
+
hasApiKey,
|
|
57
|
+
hasToken: Boolean(OpenAPI.TOKEN)
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function clearAuth() {
|
|
61
|
+
OpenAPI.TOKEN = void 0;
|
|
62
|
+
const headers = OpenAPI.HEADERS;
|
|
63
|
+
if (typeof headers === "object" && headers !== null && "X-API-Key" in headers) {
|
|
64
|
+
const { "X-API-Key": _, ...rest } = headers;
|
|
65
|
+
OpenAPI.HEADERS = rest;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export { clearAuth, configure, configureApiKey, configureBearerToken, getConfiguration };
|
|
70
|
+
//# sourceMappingURL=auth.mjs.map
|
|
71
|
+
//# sourceMappingURL=auth.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../core/OpenAPI.ts","../auth.ts"],"names":[],"mappings":";AAqBO,IAAM,OAAA,GAAyB;AAAA,EAClC,IAAA,EAAM,2BAAA;AAAA,EAIN,KAAA,EAAO,MAAA;AAAA,EAGP,OAAA,EAAS,MAEb,CAAA;;;ACIO,SAAS,eAAA,CACd,MAAA,EACA,OAAA,GAAkB,2BAAA,EACZ;AACN,EAAA,OAAA,CAAQ,IAAA,GAAO,OAAA;AACf,EAAA,MAAM,eAAA,GAAkB,OAAO,OAAA,CAAQ,OAAA,KAAY,QAAA,IAAY,QAAQ,OAAA,KAAY,IAAA,GAAO,OAAA,CAAQ,OAAA,GAAU,EAAC;AAC7G,EAAA,OAAA,CAAQ,OAAA,GAAU;AAAA,IAChB,GAAG,eAAA;AAAA,IACH,WAAA,EAAa;AAAA,GACf;AAEA,EAAA,IAAI,QAAQ,KAAA,EAAO;AACjB,IAAA,OAAA,CAAQ,KAAA,GAAQ,MAAA;AAAA,EAClB;AACF;AAkBO,SAAS,oBAAA,CACd,KAAA,EACA,OAAA,GAAkB,2BAAA,EACZ;AACN,EAAA,OAAA,CAAQ,IAAA,GAAO,OAAA;AACf,EAAA,OAAA,CAAQ,KAAA,GAAQ,KAAA;AAEhB,EAAA,IAAI,OAAA,CAAQ,OAAA,IAAW,WAAA,IAAe,OAAA,CAAQ,OAAA,EAAS;AACrD,IAAA,MAAM,EAAE,WAAA,EAAa,CAAA,EAAG,GAAG,IAAA,KAAS,OAAA,CAAQ,OAAA;AAC5C,IAAA,OAAA,CAAQ,OAAA,GAAU,IAAA;AAAA,EACpB;AACF;AAkBO,SAAS,UAAU,MAAA,EAKjB;AACP,EAAA,IAAI,OAAO,OAAA,EAAS;AAClB,IAAA,OAAA,CAAQ,OAAO,MAAA,CAAO,OAAA;AAAA,EACxB;AAEA,EAAA,IAAI,OAAO,MAAA,EAAQ;AACjB,IAAA,OAAA,CAAQ,OAAA,GAAU;AAAA,MAChB,GAAG,OAAA,CAAQ,OAAA;AAAA,MACX,GAAG,MAAA,CAAO,OAAA;AAAA,MACV,aAAa,MAAA,CAAO;AAAA,KACtB;AACA,IAAA,OAAA,CAAQ,KAAA,GAAQ,MAAA;AAAA,EAClB,CAAA,MAAA,IAAW,OAAO,KAAA,EAAO;AACvB,IAAA,OAAA,CAAQ,QAAQ,MAAA,CAAO,KAAA;AACvB,IAAA,OAAA,CAAQ,OAAA,GAAU;AAAA,MAChB,GAAG,OAAA,CAAQ,OAAA;AAAA,MACX,GAAG,MAAA,CAAO;AAAA,KACZ;AAAA,EACF,CAAA,MAAA,IAAW,OAAO,OAAA,EAAS;AACzB,IAAA,OAAA,CAAQ,OAAA,GAAU;AAAA,MAChB,GAAG,OAAA,CAAQ,OAAA;AAAA,MACX,GAAG,MAAA,CAAO;AAAA,KACZ;AAAA,EACF;AACF;AAKO,SAAS,gBAAA,GAId;AACA,EAAA,MAAM,UAAU,OAAA,CAAQ,OAAA;AACxB,EAAA,MAAM,YAAY,OAAO,OAAA,KAAY,QAAA,IAAY,OAAA,KAAY,QAAQ,WAAA,IAAe,OAAA;AACpF,EAAA,OAAO;AAAA,IACL,SAAS,OAAA,CAAQ,IAAA;AAAA,IACjB,SAAA;AAAA,IACA,QAAA,EAAU,OAAA,CAAQ,OAAA,CAAQ,KAAK;AAAA,GACjC;AACF;AAKO,SAAS,SAAA,GAAkB;AAChC,EAAA,OAAA,CAAQ,KAAA,GAAQ,MAAA;AAChB,EAAA,MAAM,UAAU,OAAA,CAAQ,OAAA;AACxB,EAAA,IAAI,OAAO,OAAA,KAAY,QAAA,IAAY,OAAA,KAAY,IAAA,IAAQ,eAAe,OAAA,EAAS;AAC7E,IAAA,MAAM,EAAE,WAAA,EAAa,CAAA,EAAG,GAAG,MAAK,GAAI,OAAA;AACpC,IAAA,OAAA,CAAQ,OAAA,GAAU,IAAA;AAAA,EACpB;AACF","file":"auth.mjs","sourcesContent":["/* generated using openapi-typescript-codegen -- do not edit */\n/* istanbul ignore file */\n/* tslint:disable */\n/* eslint-disable */\nimport type { ApiRequestOptions } from './ApiRequestOptions';\n\ntype Resolver<T> = (options: ApiRequestOptions) => Promise<T>;\ntype Headers = Record<string, string>;\n\nexport type OpenAPIConfig = {\n BASE: string;\n VERSION: string;\n WITH_CREDENTIALS: boolean;\n CREDENTIALS: 'include' | 'omit' | 'same-origin';\n TOKEN?: string | Resolver<string> | undefined;\n USERNAME?: string | Resolver<string> | undefined;\n PASSWORD?: string | Resolver<string> | undefined;\n HEADERS?: Headers | Resolver<Headers> | undefined;\n ENCODE_PATH?: ((path: string) => string) | undefined;\n};\n\nexport const OpenAPI: OpenAPIConfig = {\n BASE: 'https://api.tritonium.com',\n VERSION: '1.0.0',\n WITH_CREDENTIALS: false,\n CREDENTIALS: 'include',\n TOKEN: undefined,\n USERNAME: undefined,\n PASSWORD: undefined,\n HEADERS: undefined,\n ENCODE_PATH: undefined,\n};\n","/**\n * Authentication helpers for the Tritonium API.\n *\n * This module provides utilities for API key authentication and token management.\n *\n * @example\n * ```typescript\n * import { configureApiKey, configureBearerToken } from './auth';\n *\n * // Using API key\n * configureApiKey('trtn_live_your_key_here');\n *\n * // Using Bearer token\n * configureBearerToken('your_jwt_token');\n * ```\n */\n\nimport { OpenAPI } from './core/OpenAPI';\n\n/**\n * Configure the SDK to use API key authentication.\n *\n * @param apiKey - Your Tritonium API key (starts with trtn_live_ or trtn_test_)\n * @param baseUrl - Optional custom base URL (defaults to production)\n *\n * @example\n * ```typescript\n * import { configureApiKey } from '@tritonium/api-client/auth';\n * import { AppsService } from '@tritonium/api-client';\n *\n * configureApiKey('trtn_live_abc123...');\n *\n * const apps = await AppsService.getApps();\n * ```\n */\nexport function configureApiKey(\n apiKey: string,\n baseUrl: string = 'https://api.tritonium.com'\n): void {\n OpenAPI.BASE = baseUrl;\n const existingHeaders = typeof OpenAPI.HEADERS === 'object' && OpenAPI.HEADERS !== null ? OpenAPI.HEADERS : {};\n OpenAPI.HEADERS = {\n ...existingHeaders,\n 'X-API-Key': apiKey,\n };\n // Remove Bearer token if switching to API key\n if (OpenAPI.TOKEN) {\n OpenAPI.TOKEN = undefined;\n }\n}\n\n/**\n * Configure the SDK to use Bearer token authentication.\n *\n * @param token - Your Cognito JWT access token\n * @param baseUrl - Optional custom base URL (defaults to production)\n *\n * @example\n * ```typescript\n * import { configureBearerToken } from '@tritonium/api-client/auth';\n * import { AppsService } from '@tritonium/api-client';\n *\n * configureBearerToken('eyJhbGciOiJSUzI1NiIs...');\n *\n * const apps = await AppsService.getApps();\n * ```\n */\nexport function configureBearerToken(\n token: string,\n baseUrl: string = 'https://api.tritonium.com'\n): void {\n OpenAPI.BASE = baseUrl;\n OpenAPI.TOKEN = token;\n // Remove API key header if switching to Bearer\n if (OpenAPI.HEADERS && 'X-API-Key' in OpenAPI.HEADERS) {\n const { 'X-API-Key': _, ...rest } = OpenAPI.HEADERS;\n OpenAPI.HEADERS = rest;\n }\n}\n\n/**\n * Configure the SDK with custom settings.\n *\n * @param config - Configuration options\n *\n * @example\n * ```typescript\n * import { configure } from '@tritonium/api-client/auth';\n *\n * configure({\n * apiKey: 'trtn_live_abc123...',\n * baseUrl: 'https://staging-api.tritonium.com',\n * headers: { 'X-Custom-Header': 'value' },\n * });\n * ```\n */\nexport function configure(config: {\n apiKey?: string;\n token?: string;\n baseUrl?: string;\n headers?: Record<string, string>;\n}): void {\n if (config.baseUrl) {\n OpenAPI.BASE = config.baseUrl;\n }\n\n if (config.apiKey) {\n OpenAPI.HEADERS = {\n ...OpenAPI.HEADERS,\n ...config.headers,\n 'X-API-Key': config.apiKey,\n };\n OpenAPI.TOKEN = undefined;\n } else if (config.token) {\n OpenAPI.TOKEN = config.token;\n OpenAPI.HEADERS = {\n ...OpenAPI.HEADERS,\n ...config.headers,\n };\n } else if (config.headers) {\n OpenAPI.HEADERS = {\n ...OpenAPI.HEADERS,\n ...config.headers,\n };\n }\n}\n\n/**\n * Get the current configuration.\n */\nexport function getConfiguration(): {\n baseUrl: string;\n hasApiKey: boolean;\n hasToken: boolean;\n} {\n const headers = OpenAPI.HEADERS;\n const hasApiKey = typeof headers === 'object' && headers !== null && 'X-API-Key' in headers;\n return {\n baseUrl: OpenAPI.BASE,\n hasApiKey,\n hasToken: Boolean(OpenAPI.TOKEN),\n };\n}\n\n/**\n * Clear all authentication configuration.\n */\nexport function clearAuth(): void {\n OpenAPI.TOKEN = undefined;\n const headers = OpenAPI.HEADERS;\n if (typeof headers === 'object' && headers !== null && 'X-API-Key' in headers) {\n const { 'X-API-Key': _, ...rest } = headers;\n OpenAPI.HEADERS = rest;\n }\n}\n"]}
|