ugcinc 1.1.8 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/base.d.ts +2 -0
- package/dist/base.js +14 -3
- package/package.json +1 -1
package/dist/base.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { ApiResponse } from './types';
|
|
2
2
|
export interface ClientConfig {
|
|
3
3
|
apiKey: string;
|
|
4
|
+
orgId?: string;
|
|
4
5
|
}
|
|
5
6
|
export declare class BaseClient {
|
|
6
7
|
protected apiKey: string;
|
|
8
|
+
protected orgId?: string;
|
|
7
9
|
private readonly baseUrl;
|
|
8
10
|
constructor(config: ClientConfig);
|
|
9
11
|
protected request<T>(endpoint: string, options?: RequestInit): Promise<ApiResponse<T>>;
|
package/dist/base.js
CHANGED
|
@@ -5,14 +5,25 @@ class BaseClient {
|
|
|
5
5
|
constructor(config) {
|
|
6
6
|
this.baseUrl = 'https://api.ugc.inc';
|
|
7
7
|
this.apiKey = config.apiKey;
|
|
8
|
+
this.orgId = config.orgId;
|
|
8
9
|
}
|
|
9
10
|
async request(endpoint, options = {}) {
|
|
10
|
-
|
|
11
|
+
let url = `${this.baseUrl}${endpoint}`;
|
|
12
|
+
// If orgId is provided, treat apiKey as admin key and add orgId as query param
|
|
13
|
+
if (this.orgId) {
|
|
14
|
+
const separator = endpoint.includes('?') ? '&' : '?';
|
|
15
|
+
url = `${url}${separator}orgId=${encodeURIComponent(this.orgId)}`;
|
|
16
|
+
}
|
|
11
17
|
const headers = {
|
|
12
18
|
'Content-Type': 'application/json',
|
|
13
|
-
'Authorization': `Bearer ${this.apiKey}`,
|
|
14
|
-
...options.headers,
|
|
15
19
|
};
|
|
20
|
+
// Use admin key header if orgId is provided, otherwise use Bearer token
|
|
21
|
+
if (this.orgId) {
|
|
22
|
+
headers['x-api-key'] = this.apiKey;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
headers['Authorization'] = `Bearer ${this.apiKey}`;
|
|
26
|
+
}
|
|
16
27
|
try {
|
|
17
28
|
const response = await fetch(url, {
|
|
18
29
|
...options,
|