oblien 1.2.7 → 1.3.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/index.d.ts +57 -38
- package/index.js +6 -6
- package/package.json +2 -2
- package/sandbox.js +6 -6
- package/src/agents/index.js +20 -5
- package/src/browser/index.js +66 -41
- package/src/cdn/index.js +75 -50
- package/src/chat/index.js +27 -7
- package/src/credits/index.js +17 -5
- package/src/namespaces/index.js +16 -5
- package/src/sandbox/core/api/base.js +89 -0
- package/src/sandbox/core/api/database.js +340 -0
- package/src/sandbox/core/api/files.js +141 -0
- package/src/sandbox/core/api/git.js +174 -0
- package/src/sandbox/core/api/search.js +29 -0
- package/src/sandbox/core/api/snapshots.js +132 -0
- package/src/sandbox/core/api/terminal.js +20 -0
- package/src/sandbox/core/auth.js +256 -0
- package/src/sandbox/core/client.js +197 -0
- package/src/sandbox/core/index.js +22 -0
- package/src/sandbox/core/managers/terminal.js +453 -0
- package/src/sandbox/core/managers/watcher.js +197 -0
- package/src/sandbox/core/types.js +92 -0
- package/src/sandbox/core/utils/http.js +89 -0
- package/src/sandbox/core/websocket/connection.js +479 -0
- package/src/sandbox/index.d.ts +542 -0
- package/src/sandbox/index.js +59 -10
- package/src/sandbox/sandbox.js +204 -15
- package/src/search/index.js +23 -8
package/index.d.ts
CHANGED
|
@@ -12,7 +12,7 @@ export interface OblienConfig {
|
|
|
12
12
|
|
|
13
13
|
export class OblienClient {
|
|
14
14
|
constructor(config: OblienConfig);
|
|
15
|
-
|
|
15
|
+
|
|
16
16
|
authenticate(): Promise<string>;
|
|
17
17
|
getAuthHeaders(): Promise<Record<string, string>>;
|
|
18
18
|
get(path: string, params?: Record<string, any>): Promise<any>;
|
|
@@ -33,7 +33,7 @@ export interface StorageAdapter {
|
|
|
33
33
|
|
|
34
34
|
export class NodeCacheStorage implements StorageAdapter {
|
|
35
35
|
constructor(ttl?: number);
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
get(key: string): Promise<any>;
|
|
38
38
|
set(key: string, value: any, ttl?: number): Promise<boolean>;
|
|
39
39
|
delete(key: string): Promise<boolean>;
|
|
@@ -51,7 +51,7 @@ export class InMemoryStorage implements StorageAdapter {
|
|
|
51
51
|
|
|
52
52
|
export class RedisStorage implements StorageAdapter {
|
|
53
53
|
constructor(redisClient: any);
|
|
54
|
-
|
|
54
|
+
|
|
55
55
|
get(key: string): Promise<any>;
|
|
56
56
|
set(key: string, value: any, ttl?: number): Promise<boolean>;
|
|
57
57
|
delete(key: string): Promise<boolean>;
|
|
@@ -100,7 +100,7 @@ export interface Guest {
|
|
|
100
100
|
|
|
101
101
|
export class GuestManager {
|
|
102
102
|
constructor(options?: GuestManagerOptions);
|
|
103
|
-
|
|
103
|
+
|
|
104
104
|
generateGuestId(ip: string): string;
|
|
105
105
|
getOrCreateGuest(ip: string, metadata?: Record<string, any>): Promise<Guest>;
|
|
106
106
|
getGuest(guestId: string | GuestOptions): Promise<Guest | null>;
|
|
@@ -141,10 +141,10 @@ export interface SessionData {
|
|
|
141
141
|
|
|
142
142
|
export class ChatSession {
|
|
143
143
|
constructor(options: SessionOptions);
|
|
144
|
-
|
|
144
|
+
|
|
145
145
|
sessionId: string | null;
|
|
146
146
|
token: string | null;
|
|
147
|
-
|
|
147
|
+
|
|
148
148
|
create(): Promise<SessionData>;
|
|
149
149
|
get(sessionId?: string): Promise<any>;
|
|
150
150
|
delete(sessionId?: string): Promise<any>;
|
|
@@ -176,7 +176,7 @@ export interface CreateGuestSessionOptions {
|
|
|
176
176
|
fingerprint?: string;
|
|
177
177
|
agentId: string;
|
|
178
178
|
workflowId?: string;
|
|
179
|
-
namespace?: string;
|
|
179
|
+
namespace?: string;
|
|
180
180
|
endUserId?: string;
|
|
181
181
|
metadata?: Record<string, any>;
|
|
182
182
|
workspace?: Record<string, any>;
|
|
@@ -304,39 +304,39 @@ export interface GetGuestOptions {
|
|
|
304
304
|
|
|
305
305
|
export class OblienChat {
|
|
306
306
|
constructor(client: OblienClient, options?: ChatOptions);
|
|
307
|
-
|
|
307
|
+
|
|
308
308
|
// Session Creation
|
|
309
309
|
createSession(options: CreateSessionOptions): Promise<SessionData>;
|
|
310
310
|
createGuestSession(options: CreateGuestSessionOptions): Promise<GuestSessionData>;
|
|
311
311
|
getGuest(options: GetGuestOptions | string, getSessions?: boolean): Promise<Guest | null>; // From Oblien API (string = namespace)
|
|
312
312
|
getGuestFromCache(ip: string, fingerprint?: string): Promise<Guest | null>; // From local cache
|
|
313
|
-
|
|
313
|
+
|
|
314
314
|
// Session Token Management (Server-side)
|
|
315
315
|
createSessionToken(sessionId: string): Promise<SessionTokenData>;
|
|
316
316
|
revokeSessionToken(sessionId: string): Promise<any>;
|
|
317
|
-
|
|
317
|
+
|
|
318
318
|
// Session Token Management (Client-side)
|
|
319
319
|
refreshToken(options: RefreshTokenOptions): Promise<SessionTokenData>;
|
|
320
320
|
prepareSession(options: PrepareSessionOptions): Promise<any>;
|
|
321
|
-
|
|
321
|
+
|
|
322
322
|
// Session Management (Server-side)
|
|
323
323
|
getSession(sessionId: string): Promise<any>;
|
|
324
324
|
getSessionHistory(sessionId: string, options?: SessionHistoryOptions): Promise<any>;
|
|
325
325
|
listSessions(options?: ListSessionsOptions): Promise<any[]>;
|
|
326
326
|
deleteSession(sessionId: string): Promise<any>;
|
|
327
|
-
|
|
327
|
+
|
|
328
328
|
// Security & Moderation (Server-side)
|
|
329
329
|
banUser(sessionId: string, options?: BanUserOptions): Promise<any>;
|
|
330
330
|
unbanUser(sessionId: string): Promise<any>;
|
|
331
331
|
lockSession(sessionId: string, options?: LockSessionOptions): Promise<any>;
|
|
332
|
-
|
|
332
|
+
|
|
333
333
|
// Chat Operations
|
|
334
334
|
send(options: SendMessageOptions): Promise<any>;
|
|
335
335
|
upload(options: UploadOptions): Promise<any>;
|
|
336
|
-
|
|
336
|
+
|
|
337
337
|
// History (Client-side)
|
|
338
338
|
getHistory(options: GetHistoryOptions): Promise<any>;
|
|
339
|
-
|
|
339
|
+
|
|
340
340
|
// Guest Management
|
|
341
341
|
getAllGuests(): Promise<Guest[]>;
|
|
342
342
|
cleanupGuests(): Promise<number>;
|
|
@@ -441,10 +441,10 @@ export interface NamespaceUsage {
|
|
|
441
441
|
|
|
442
442
|
export class Namespace {
|
|
443
443
|
constructor(options: { client: OblienClient; namespaceId?: string; data?: NamespaceData });
|
|
444
|
-
|
|
444
|
+
|
|
445
445
|
namespaceId: string | null;
|
|
446
446
|
data: NamespaceData | null;
|
|
447
|
-
|
|
447
|
+
|
|
448
448
|
create(options: CreateNamespaceOptions): Promise<NamespaceData>;
|
|
449
449
|
get(identifier?: string): Promise<NamespaceData>;
|
|
450
450
|
update(updates: UpdateNamespaceOptions, namespaceId?: string): Promise<NamespaceData>;
|
|
@@ -461,7 +461,7 @@ export class Namespace {
|
|
|
461
461
|
|
|
462
462
|
export class OblienNamespaces {
|
|
463
463
|
constructor(client: OblienClient);
|
|
464
|
-
|
|
464
|
+
|
|
465
465
|
create(options: CreateNamespaceOptions): Promise<NamespaceData>;
|
|
466
466
|
get(identifier: string): Promise<NamespaceData>;
|
|
467
467
|
list(options?: ListNamespacesOptions): Promise<{ success: boolean; data: NamespaceData[]; pagination: any }>;
|
|
@@ -606,41 +606,41 @@ export interface PurchaseHistoryOptions {
|
|
|
606
606
|
|
|
607
607
|
export class OblienCredits {
|
|
608
608
|
constructor(client: OblienClient);
|
|
609
|
-
|
|
609
|
+
|
|
610
610
|
// Balance Management
|
|
611
611
|
getBalance(): Promise<number>;
|
|
612
612
|
addCredits(amount: number, reason?: string, metadata?: Record<string, any>): Promise<any>;
|
|
613
|
-
|
|
613
|
+
|
|
614
614
|
// Quota Management
|
|
615
615
|
getNamespaceQuotas(options?: { limit?: number; offset?: number; after?: string; search?: string; status?: string }): Promise<any>;
|
|
616
616
|
getNamespaceDetails(namespace: string, options?: { days?: number }): Promise<any>;
|
|
617
617
|
setQuota(options: SetQuotaOptions): Promise<QuotaData>;
|
|
618
618
|
resetQuota(namespace: string, service: string): Promise<any>;
|
|
619
|
-
|
|
619
|
+
|
|
620
620
|
// End User Quota Management (Optional Third Level)
|
|
621
621
|
setEndUserQuota(options: SetEndUserQuotaOptions): Promise<any>;
|
|
622
622
|
getEndUserQuota(namespace: string, endUserId: string, service: string): Promise<{ success: boolean; quota: EndUserQuota | null }>;
|
|
623
623
|
resetEndUserQuota(namespace: string, endUserId: string, service: string): Promise<any>;
|
|
624
|
-
|
|
624
|
+
|
|
625
625
|
// Default Quota Configuration (Dynamic, per client)
|
|
626
626
|
setDefaultQuota(options: SetDefaultQuotaOptions): Promise<any>;
|
|
627
627
|
getDefaultQuota(level: 'namespace' | 'end_user', service: string): Promise<{ success: boolean; config: DefaultQuotaConfig | null }>;
|
|
628
628
|
getAllDefaultQuotas(level?: 'namespace' | 'end_user'): Promise<{ success: boolean; configs: DefaultQuotaConfig[] }>;
|
|
629
629
|
deleteDefaultQuota(level: 'namespace' | 'end_user', service: string): Promise<any>;
|
|
630
630
|
toggleDefaultQuotaAutoApply(level: 'namespace' | 'end_user', service: string, autoApply: boolean): Promise<any>;
|
|
631
|
-
|
|
631
|
+
|
|
632
632
|
// Usage History & Transactions
|
|
633
633
|
getHistory(options?: HistoryOptions): Promise<{ success: boolean; data: CreditTransaction[]; pagination: any }>;
|
|
634
634
|
getHistoryFilters(): Promise<{ namespaces: string[]; services: string[] }>;
|
|
635
635
|
getSummary(options?: SummaryOptions): Promise<any>;
|
|
636
636
|
getUsageStats(options?: { days?: number }): Promise<any>;
|
|
637
|
-
|
|
637
|
+
|
|
638
638
|
// Pricing & Packages
|
|
639
639
|
getPackages(): Promise<CreditPackage[]>;
|
|
640
640
|
getPricingInfo(): Promise<any>;
|
|
641
641
|
calculateCost(options: CalculateCostOptions): Promise<any>;
|
|
642
642
|
calculateCredits(amount: number): Promise<any>;
|
|
643
|
-
|
|
643
|
+
|
|
644
644
|
// Purchase Management
|
|
645
645
|
createCheckout(options: PurchaseOptions): Promise<any>;
|
|
646
646
|
getPurchaseHistory(options?: PurchaseHistoryOptions): Promise<any>;
|
|
@@ -675,7 +675,10 @@ export interface PageContentOptions {
|
|
|
675
675
|
selector?: string;
|
|
676
676
|
extract?: 'html' | 'text' | 'both';
|
|
677
677
|
waitForFullLoad?: boolean;
|
|
678
|
-
|
|
678
|
+
proxy?: string;
|
|
679
|
+
proxyPort?: number;
|
|
680
|
+
proxyUsername?: string;
|
|
681
|
+
proxyPassword?: string;
|
|
679
682
|
}
|
|
680
683
|
|
|
681
684
|
export interface PageContentResult {
|
|
@@ -694,7 +697,10 @@ export interface ScreenshotOptions {
|
|
|
694
697
|
quality?: number;
|
|
695
698
|
viewport?: { width: number; height: number };
|
|
696
699
|
device?: string;
|
|
697
|
-
|
|
700
|
+
proxy?: string;
|
|
701
|
+
proxyPort?: number;
|
|
702
|
+
proxyUsername?: string;
|
|
703
|
+
proxyPassword?: string;
|
|
698
704
|
}
|
|
699
705
|
|
|
700
706
|
export interface ScreenshotResult {
|
|
@@ -712,7 +718,10 @@ export interface PdfOptions {
|
|
|
712
718
|
landscape?: boolean;
|
|
713
719
|
printBackground?: boolean;
|
|
714
720
|
margin?: { top?: string; right?: string; bottom?: string; left?: string };
|
|
715
|
-
|
|
721
|
+
proxy?: string;
|
|
722
|
+
proxyPort?: number;
|
|
723
|
+
proxyUsername?: string;
|
|
724
|
+
proxyPassword?: string;
|
|
716
725
|
}
|
|
717
726
|
|
|
718
727
|
export interface PdfResult {
|
|
@@ -727,7 +736,10 @@ export interface MonitorRequestsOptions {
|
|
|
727
736
|
token?: string;
|
|
728
737
|
duration?: number;
|
|
729
738
|
filterTypes?: string[];
|
|
730
|
-
|
|
739
|
+
proxy?: string;
|
|
740
|
+
proxyPort?: number;
|
|
741
|
+
proxyUsername?: string;
|
|
742
|
+
proxyPassword?: string;
|
|
731
743
|
}
|
|
732
744
|
|
|
733
745
|
export interface MonitorRequestsResult {
|
|
@@ -745,7 +757,10 @@ export interface ConsoleLogsOptions {
|
|
|
745
757
|
url: string;
|
|
746
758
|
token?: string;
|
|
747
759
|
duration?: number;
|
|
748
|
-
|
|
760
|
+
proxy?: string;
|
|
761
|
+
proxyPort?: number;
|
|
762
|
+
proxyUsername?: string;
|
|
763
|
+
proxyPassword?: string;
|
|
749
764
|
}
|
|
750
765
|
|
|
751
766
|
export interface ConsoleLogsResult {
|
|
@@ -759,11 +774,11 @@ export interface ConsoleLogsResult {
|
|
|
759
774
|
|
|
760
775
|
export class OblienBrowser {
|
|
761
776
|
constructor(client: OblienClient, config?: BrowserConfig);
|
|
762
|
-
|
|
777
|
+
|
|
763
778
|
// Token Management
|
|
764
779
|
generateToken(): Promise<BrowserTokenResponse>;
|
|
765
780
|
clearTokenCache(): void;
|
|
766
|
-
|
|
781
|
+
|
|
767
782
|
// Browser Operations
|
|
768
783
|
getPageContent(options: PageContentOptions): Promise<PageContentResult>;
|
|
769
784
|
screenshot(options: ScreenshotOptions): Promise<ScreenshotResult>;
|
|
@@ -919,26 +934,26 @@ export interface RestoreFileResult {
|
|
|
919
934
|
|
|
920
935
|
export class OblienCDN {
|
|
921
936
|
constructor(client: OblienClient, config?: CDNConfig);
|
|
922
|
-
|
|
937
|
+
|
|
923
938
|
// Token Management
|
|
924
939
|
generateUserToken(): Promise<TokenResponse>;
|
|
925
940
|
generateAdminToken(): Promise<TokenResponse>;
|
|
926
941
|
clearTokenCache(scope?: 'user' | 'admin' | 'all'): void;
|
|
927
|
-
|
|
942
|
+
|
|
928
943
|
// File Upload
|
|
929
944
|
upload(file: Buffer | string | MulterFile, options?: UploadOptions): Promise<UploadResult>;
|
|
930
945
|
uploadMultiple(files: Array<Buffer | string | MulterFile>, options?: MultiUploadOptions): Promise<MultiUploadResult>;
|
|
931
|
-
|
|
946
|
+
|
|
932
947
|
// URL Upload
|
|
933
948
|
uploadFromUrls(urls: string[], options?: UploadFromUrlsOptions): Promise<MultiUploadResult>;
|
|
934
|
-
|
|
949
|
+
|
|
935
950
|
// File Info (Admin Only)
|
|
936
951
|
getFileInfo(filePath: string, options?: FileInfoOptions): Promise<FileInfo>;
|
|
937
|
-
|
|
952
|
+
|
|
938
953
|
// Metadata
|
|
939
954
|
getVariants(options?: { token?: string }): Promise<any>;
|
|
940
955
|
getLimits(options?: { token?: string }): Promise<any>;
|
|
941
|
-
|
|
956
|
+
|
|
942
957
|
// File Management (Session-based)
|
|
943
958
|
listFiles(options?: ListFilesOptions): Promise<ListFilesResult>;
|
|
944
959
|
getStats(): Promise<StorageStats>;
|
|
@@ -947,6 +962,10 @@ export class OblienCDN {
|
|
|
947
962
|
restoreFile(fileId: number | string): Promise<RestoreFileResult>;
|
|
948
963
|
}
|
|
949
964
|
|
|
965
|
+
// ============ Sandbox Types ============
|
|
966
|
+
|
|
967
|
+
export * from './src/sandbox/index.d.ts';
|
|
968
|
+
|
|
950
969
|
// ============ Exports ============
|
|
951
970
|
|
|
952
971
|
declare const _default: {
|
package/index.js
CHANGED
|
@@ -13,11 +13,11 @@ import { OblienCDN } from './src/cdn/index.js';
|
|
|
13
13
|
import { OblienBrowser } from './src/browser/index.js';
|
|
14
14
|
import { OblienNamespaces, Namespace } from './src/namespaces/index.js';
|
|
15
15
|
import { OblienCredits } from './src/credits/index.js';
|
|
16
|
-
import {
|
|
17
|
-
GuestManager,
|
|
16
|
+
import {
|
|
17
|
+
GuestManager,
|
|
18
18
|
NodeCacheStorage,
|
|
19
19
|
InMemoryStorage,
|
|
20
|
-
RedisStorage
|
|
20
|
+
RedisStorage
|
|
21
21
|
} from './src/utils/guest-manager.js';
|
|
22
22
|
|
|
23
23
|
// Re-export as named exports
|
|
@@ -31,11 +31,11 @@ export { OblienCDN };
|
|
|
31
31
|
export { OblienBrowser };
|
|
32
32
|
export { OblienNamespaces, Namespace };
|
|
33
33
|
export { OblienCredits };
|
|
34
|
-
export {
|
|
35
|
-
GuestManager,
|
|
34
|
+
export {
|
|
35
|
+
GuestManager,
|
|
36
36
|
NodeCacheStorage,
|
|
37
37
|
InMemoryStorage,
|
|
38
|
-
RedisStorage
|
|
38
|
+
RedisStorage
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
// Default export
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "oblien",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Server-side SDK for Oblien AI Platform - Build AI-powered applications with chat, agents, and workflows",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"type": "module",
|
|
@@ -82,4 +82,4 @@
|
|
|
82
82
|
"README.md",
|
|
83
83
|
"LICENSE"
|
|
84
84
|
]
|
|
85
|
-
}
|
|
85
|
+
}
|
package/sandbox.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Sandbox Module Entry Point
|
|
3
|
-
* Import this for sandbox management
|
|
3
|
+
* Import this for sandbox management and interaction
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
export { OblienSandboxes, Sandbox } from './src/sandbox/index.js';
|
|
6
|
+
export { OblienSandboxes, Sandbox, SandboxClient } from './src/sandbox/index.js';
|
|
7
7
|
|
|
8
|
-
export default {
|
|
9
|
-
OblienSandboxes,
|
|
10
|
-
Sandbox
|
|
8
|
+
export default {
|
|
9
|
+
OblienSandboxes,
|
|
10
|
+
Sandbox,
|
|
11
|
+
SandboxClient
|
|
11
12
|
};
|
|
12
|
-
|
package/src/agents/index.js
CHANGED
|
@@ -3,19 +3,34 @@
|
|
|
3
3
|
* Manages AI agents, their settings, and operations
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { OblienClient } from '../client.js';
|
|
6
7
|
import { Agent } from './agent.js';
|
|
7
8
|
import { Tools } from './tools.js';
|
|
8
9
|
|
|
9
10
|
export class OblienAgents {
|
|
10
11
|
/**
|
|
11
|
-
* @param {import('../client.js').OblienClient}
|
|
12
|
+
* @param {import('../client.js').OblienClient|Object} clientOrConfig - Oblien client instance or config
|
|
13
|
+
* @param {string} [clientOrConfig.clientId] - Client ID (if not using client instance)
|
|
14
|
+
* @param {string} [clientOrConfig.clientSecret] - Client Secret (if not using client instance)
|
|
15
|
+
* @param {string} [clientOrConfig.baseURL] - Base URL (optional)
|
|
12
16
|
*/
|
|
13
|
-
constructor(
|
|
14
|
-
if (!
|
|
15
|
-
throw new Error('Oblien client
|
|
17
|
+
constructor(clientOrConfig) {
|
|
18
|
+
if (!clientOrConfig) {
|
|
19
|
+
throw new Error('Oblien client or credentials are required');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// If it's already a client instance
|
|
23
|
+
if (clientOrConfig.clientId && clientOrConfig.clientSecret && typeof clientOrConfig.get === 'function') {
|
|
24
|
+
this.client = clientOrConfig;
|
|
25
|
+
}
|
|
26
|
+
// If credentials provided, create client
|
|
27
|
+
else if (clientOrConfig.clientId && clientOrConfig.clientSecret) {
|
|
28
|
+
this.client = new OblienClient(clientOrConfig);
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
throw new Error('Either provide OblienClient instance or { clientId, clientSecret }');
|
|
16
32
|
}
|
|
17
33
|
|
|
18
|
-
this.client = client;
|
|
19
34
|
this._tools = null;
|
|
20
35
|
}
|
|
21
36
|
|
package/src/browser/index.js
CHANGED
|
@@ -3,12 +3,37 @@
|
|
|
3
3
|
* Browser automation with automatic token management
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
import { OblienClient } from '../client.js';
|
|
7
|
+
|
|
6
8
|
export class OblienBrowser {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
9
|
+
/**
|
|
10
|
+
* @param {import('../client.js').OblienClient|Object} clientOrConfig - Oblien client instance or { clientId, clientSecret }
|
|
11
|
+
* @param {Object} [config] - Configuration options
|
|
12
|
+
* @param {string} [config.browserURL] - Browser service URL
|
|
13
|
+
*/
|
|
14
|
+
constructor(clientOrConfig, config = {}) {
|
|
15
|
+
if (!clientOrConfig) {
|
|
16
|
+
throw new Error('Either provide OblienClient instance or { clientId, clientSecret }');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// If it's already a client instance
|
|
20
|
+
if (clientOrConfig.clientId && clientOrConfig.clientSecret && typeof clientOrConfig.get === 'function') {
|
|
21
|
+
this.client = clientOrConfig;
|
|
22
|
+
}
|
|
23
|
+
// If credentials provided, create client
|
|
24
|
+
else if (clientOrConfig.clientId && clientOrConfig.clientSecret) {
|
|
25
|
+
// Extract browserURL if passed in clientOrConfig
|
|
26
|
+
if (clientOrConfig.browserURL) {
|
|
27
|
+
config.browserURL = clientOrConfig.browserURL;
|
|
28
|
+
}
|
|
29
|
+
this.client = new OblienClient(clientOrConfig);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
throw new Error('Either provide OblienClient instance or { clientId, clientSecret }');
|
|
33
|
+
}
|
|
34
|
+
|
|
10
35
|
this.browserURL = config.browserURL || 'https://browser.oblien.com';
|
|
11
|
-
|
|
36
|
+
|
|
12
37
|
// Token cache for reuse within expiration window
|
|
13
38
|
this._tokenCache = {
|
|
14
39
|
token: null,
|
|
@@ -33,7 +58,7 @@ export class OblienBrowser {
|
|
|
33
58
|
*/
|
|
34
59
|
async generateToken() {
|
|
35
60
|
const response = await this.client.post('browser/token');
|
|
36
|
-
|
|
61
|
+
|
|
37
62
|
// Cache token for reuse
|
|
38
63
|
if (response.success && response.token) {
|
|
39
64
|
this._tokenCache = {
|
|
@@ -41,7 +66,7 @@ export class OblienBrowser {
|
|
|
41
66
|
expiresAt: Date.now() + 50000 // 50 seconds (buffer before 1m expiry)
|
|
42
67
|
};
|
|
43
68
|
}
|
|
44
|
-
|
|
69
|
+
|
|
45
70
|
return response;
|
|
46
71
|
}
|
|
47
72
|
|
|
@@ -52,12 +77,12 @@ export class OblienBrowser {
|
|
|
52
77
|
*/
|
|
53
78
|
async _getToken() {
|
|
54
79
|
const cached = this._tokenCache;
|
|
55
|
-
|
|
80
|
+
|
|
56
81
|
// Use cached token if still valid
|
|
57
82
|
if (cached.token && cached.expiresAt > Date.now()) {
|
|
58
83
|
return cached.token;
|
|
59
84
|
}
|
|
60
|
-
|
|
85
|
+
|
|
61
86
|
// Generate new token
|
|
62
87
|
const tokenData = await this.generateToken();
|
|
63
88
|
return tokenData.token;
|
|
@@ -107,14 +132,14 @@ export class OblienBrowser {
|
|
|
107
132
|
*/
|
|
108
133
|
async getPageContent(options) {
|
|
109
134
|
const { url, token, ...restOptions } = options;
|
|
110
|
-
|
|
135
|
+
|
|
111
136
|
if (!url) {
|
|
112
137
|
throw new Error('URL is required');
|
|
113
138
|
}
|
|
114
|
-
|
|
139
|
+
|
|
115
140
|
// Get token (use provided or generate new one)
|
|
116
141
|
const browserToken = token || await this._getToken();
|
|
117
|
-
|
|
142
|
+
|
|
118
143
|
const response = await fetch(`${this.browserURL}/page-content`, {
|
|
119
144
|
method: 'POST',
|
|
120
145
|
headers: {
|
|
@@ -123,12 +148,12 @@ export class OblienBrowser {
|
|
|
123
148
|
},
|
|
124
149
|
body: JSON.stringify({ url, ...restOptions })
|
|
125
150
|
});
|
|
126
|
-
|
|
151
|
+
|
|
127
152
|
if (!response.ok) {
|
|
128
153
|
const error = await response.json().catch(() => ({}));
|
|
129
154
|
throw new Error(error.error || `Request failed: ${response.status}`);
|
|
130
155
|
}
|
|
131
|
-
|
|
156
|
+
|
|
132
157
|
return response.json();
|
|
133
158
|
}
|
|
134
159
|
|
|
@@ -167,13 +192,13 @@ export class OblienBrowser {
|
|
|
167
192
|
*/
|
|
168
193
|
async screenshot(options) {
|
|
169
194
|
const { url, token, ...restOptions } = options;
|
|
170
|
-
|
|
195
|
+
|
|
171
196
|
if (!url) {
|
|
172
197
|
throw new Error('URL is required');
|
|
173
198
|
}
|
|
174
|
-
|
|
199
|
+
|
|
175
200
|
const browserToken = token || await this._getToken();
|
|
176
|
-
|
|
201
|
+
|
|
177
202
|
const response = await fetch(`${this.browserURL}/screenshot`, {
|
|
178
203
|
method: 'POST',
|
|
179
204
|
headers: {
|
|
@@ -182,12 +207,12 @@ export class OblienBrowser {
|
|
|
182
207
|
},
|
|
183
208
|
body: JSON.stringify({ url, ...restOptions })
|
|
184
209
|
});
|
|
185
|
-
|
|
210
|
+
|
|
186
211
|
if (!response.ok) {
|
|
187
212
|
const error = await response.json().catch(() => ({}));
|
|
188
213
|
throw new Error(error.error || `Screenshot failed: ${response.status}`);
|
|
189
214
|
}
|
|
190
|
-
|
|
215
|
+
|
|
191
216
|
return response.json();
|
|
192
217
|
}
|
|
193
218
|
|
|
@@ -224,13 +249,13 @@ export class OblienBrowser {
|
|
|
224
249
|
*/
|
|
225
250
|
async pdf(options) {
|
|
226
251
|
const { url, token, ...restOptions } = options;
|
|
227
|
-
|
|
252
|
+
|
|
228
253
|
if (!url) {
|
|
229
254
|
throw new Error('URL is required');
|
|
230
255
|
}
|
|
231
|
-
|
|
256
|
+
|
|
232
257
|
const browserToken = token || await this._getToken();
|
|
233
|
-
|
|
258
|
+
|
|
234
259
|
const response = await fetch(`${this.browserURL}/pdf`, {
|
|
235
260
|
method: 'POST',
|
|
236
261
|
headers: {
|
|
@@ -239,12 +264,12 @@ export class OblienBrowser {
|
|
|
239
264
|
},
|
|
240
265
|
body: JSON.stringify({ url, ...restOptions })
|
|
241
266
|
});
|
|
242
|
-
|
|
267
|
+
|
|
243
268
|
if (!response.ok) {
|
|
244
269
|
const error = await response.json().catch(() => ({}));
|
|
245
270
|
throw new Error(error.error || `PDF generation failed: ${response.status}`);
|
|
246
271
|
}
|
|
247
|
-
|
|
272
|
+
|
|
248
273
|
return response.json();
|
|
249
274
|
}
|
|
250
275
|
|
|
@@ -280,13 +305,13 @@ export class OblienBrowser {
|
|
|
280
305
|
*/
|
|
281
306
|
async monitorRequests(options) {
|
|
282
307
|
const { url, token, ...restOptions } = options;
|
|
283
|
-
|
|
308
|
+
|
|
284
309
|
if (!url) {
|
|
285
310
|
throw new Error('URL is required');
|
|
286
311
|
}
|
|
287
|
-
|
|
312
|
+
|
|
288
313
|
const browserToken = token || await this._getToken();
|
|
289
|
-
|
|
314
|
+
|
|
290
315
|
const response = await fetch(`${this.browserURL}/monitor-requests`, {
|
|
291
316
|
method: 'POST',
|
|
292
317
|
headers: {
|
|
@@ -295,12 +320,12 @@ export class OblienBrowser {
|
|
|
295
320
|
},
|
|
296
321
|
body: JSON.stringify({ url, ...restOptions })
|
|
297
322
|
});
|
|
298
|
-
|
|
323
|
+
|
|
299
324
|
if (!response.ok) {
|
|
300
325
|
const error = await response.json().catch(() => ({}));
|
|
301
326
|
throw new Error(error.error || `Request monitoring failed: ${response.status}`);
|
|
302
327
|
}
|
|
303
|
-
|
|
328
|
+
|
|
304
329
|
return response.json();
|
|
305
330
|
}
|
|
306
331
|
|
|
@@ -333,13 +358,13 @@ export class OblienBrowser {
|
|
|
333
358
|
*/
|
|
334
359
|
async getConsoleLogs(options) {
|
|
335
360
|
const { url, token, ...restOptions } = options;
|
|
336
|
-
|
|
361
|
+
|
|
337
362
|
if (!url) {
|
|
338
363
|
throw new Error('URL is required');
|
|
339
364
|
}
|
|
340
|
-
|
|
365
|
+
|
|
341
366
|
const browserToken = token || await this._getToken();
|
|
342
|
-
|
|
367
|
+
|
|
343
368
|
const response = await fetch(`${this.browserURL}/console-logs`, {
|
|
344
369
|
method: 'POST',
|
|
345
370
|
headers: {
|
|
@@ -348,12 +373,12 @@ export class OblienBrowser {
|
|
|
348
373
|
},
|
|
349
374
|
body: JSON.stringify({ url, ...restOptions })
|
|
350
375
|
});
|
|
351
|
-
|
|
376
|
+
|
|
352
377
|
if (!response.ok) {
|
|
353
378
|
const error = await response.json().catch(() => ({}));
|
|
354
379
|
throw new Error(error.error || `Console logs retrieval failed: ${response.status}`);
|
|
355
380
|
}
|
|
356
|
-
|
|
381
|
+
|
|
357
382
|
return response.json();
|
|
358
383
|
}
|
|
359
384
|
|
|
@@ -377,21 +402,21 @@ export class OblienBrowser {
|
|
|
377
402
|
*/
|
|
378
403
|
async getDevicePresets(options = {}) {
|
|
379
404
|
const { token } = options;
|
|
380
|
-
|
|
405
|
+
|
|
381
406
|
const browserToken = token || await this._getToken();
|
|
382
|
-
|
|
407
|
+
|
|
383
408
|
const response = await fetch(`${this.browserURL}/device-presets`, {
|
|
384
409
|
method: 'GET',
|
|
385
410
|
headers: {
|
|
386
411
|
'Authorization': `Bearer ${browserToken}`
|
|
387
412
|
}
|
|
388
413
|
});
|
|
389
|
-
|
|
414
|
+
|
|
390
415
|
if (!response.ok) {
|
|
391
416
|
const error = await response.json().catch(() => ({}));
|
|
392
417
|
throw new Error(error.error || `Failed to get device presets: ${response.status}`);
|
|
393
418
|
}
|
|
394
|
-
|
|
419
|
+
|
|
395
420
|
return response.json();
|
|
396
421
|
}
|
|
397
422
|
|
|
@@ -414,21 +439,21 @@ export class OblienBrowser {
|
|
|
414
439
|
*/
|
|
415
440
|
async getStatus(options = {}) {
|
|
416
441
|
const { token } = options;
|
|
417
|
-
|
|
442
|
+
|
|
418
443
|
const browserToken = token || await this._getToken();
|
|
419
|
-
|
|
444
|
+
|
|
420
445
|
const response = await fetch(`${this.browserURL}/status`, {
|
|
421
446
|
method: 'GET',
|
|
422
447
|
headers: {
|
|
423
448
|
'Authorization': `Bearer ${browserToken}`
|
|
424
449
|
}
|
|
425
450
|
});
|
|
426
|
-
|
|
451
|
+
|
|
427
452
|
if (!response.ok) {
|
|
428
453
|
const error = await response.json().catch(() => ({}));
|
|
429
454
|
throw new Error(error.error || `Failed to get status: ${response.status}`);
|
|
430
455
|
}
|
|
431
|
-
|
|
456
|
+
|
|
432
457
|
return response.json();
|
|
433
458
|
}
|
|
434
459
|
|