opencloud-platform-sdk 2.0.0 → 3.0.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 +156 -82
- package/dist/cli.d.mts +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +161 -0
- package/dist/cli.mjs +138 -0
- package/dist/index.d.mts +58 -65
- package/dist/index.d.ts +58 -65
- package/dist/index.js +230 -243
- package/dist/index.mjs +230 -243
- package/package.json +6 -3
package/dist/index.d.mts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* opencloud-platform-sdk
|
|
2
|
+
* opencloud-platform-sdk v3.0.0
|
|
3
3
|
* Official SDK for OpenCloud - AI App Marketplace
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* -
|
|
7
|
-
* -
|
|
8
|
-
* -
|
|
5
|
+
* Standalone Mode:
|
|
6
|
+
* - Works directly on any domain (no iframe required)
|
|
7
|
+
* - Uses popup for authentication
|
|
8
|
+
* - Charges from user's OpenCloud wallet
|
|
9
9
|
*/
|
|
10
10
|
interface OpenCloudConfig {
|
|
11
11
|
appId: string;
|
|
@@ -21,8 +21,21 @@ interface TrackUsageResponse {
|
|
|
21
21
|
userBalance: number;
|
|
22
22
|
transactionId: string;
|
|
23
23
|
}
|
|
24
|
+
interface ChargeResult {
|
|
25
|
+
success: boolean;
|
|
26
|
+
charged?: number;
|
|
27
|
+
balance?: number;
|
|
28
|
+
transactionId?: string;
|
|
29
|
+
error?: 'CANCELLED' | 'INSUFFICIENT_BALANCE' | 'NOT_AUTHENTICATED' | 'UNKNOWN';
|
|
30
|
+
}
|
|
24
31
|
interface UserSession {
|
|
25
32
|
token: string;
|
|
33
|
+
user?: {
|
|
34
|
+
id: string;
|
|
35
|
+
email: string;
|
|
36
|
+
username?: string;
|
|
37
|
+
balance?: number;
|
|
38
|
+
};
|
|
26
39
|
}
|
|
27
40
|
interface UserInfo {
|
|
28
41
|
id: string;
|
|
@@ -32,11 +45,15 @@ interface UserInfo {
|
|
|
32
45
|
}
|
|
33
46
|
declare class OpenCloudSDK {
|
|
34
47
|
private config;
|
|
35
|
-
private heartbeatInterval?;
|
|
36
48
|
private _isPreviewMode;
|
|
37
|
-
private
|
|
49
|
+
private _session;
|
|
50
|
+
private _authPopup;
|
|
38
51
|
constructor();
|
|
39
52
|
private detectPreviewMode;
|
|
53
|
+
private loadStoredSession;
|
|
54
|
+
private saveSession;
|
|
55
|
+
private clearStoredSession;
|
|
56
|
+
private setupMessageListener;
|
|
40
57
|
/**
|
|
41
58
|
* Check if running in preview/development mode
|
|
42
59
|
*/
|
|
@@ -46,85 +63,61 @@ declare class OpenCloudSDK {
|
|
|
46
63
|
*/
|
|
47
64
|
init(options: OpenCloudConfig): void;
|
|
48
65
|
/**
|
|
49
|
-
*
|
|
50
|
-
* Call this BEFORE or AFTER your AI/API call
|
|
51
|
-
*
|
|
52
|
-
* Example:
|
|
53
|
-
* ```
|
|
54
|
-
* // Check if user can afford it first
|
|
55
|
-
* const canUse = await opencloud.canAfford();
|
|
56
|
-
* if (!canUse) {
|
|
57
|
-
* opencloud.requestTopUp();
|
|
58
|
-
* return;
|
|
59
|
-
* }
|
|
60
|
-
*
|
|
61
|
-
* // Do your AI call
|
|
62
|
-
* const result = await myAICall();
|
|
63
|
-
*
|
|
64
|
-
* // Track the usage (charges user)
|
|
65
|
-
* await opencloud.trackUsage({ action: 'chat_message' });
|
|
66
|
-
* ```
|
|
66
|
+
* Check if user is authenticated with OpenCloud
|
|
67
67
|
*/
|
|
68
|
-
|
|
68
|
+
isAuthenticated(): boolean;
|
|
69
69
|
/**
|
|
70
|
-
*
|
|
71
|
-
* Returns
|
|
70
|
+
* Open login popup for user authentication
|
|
71
|
+
* Returns a promise that resolves when login is complete
|
|
72
72
|
*/
|
|
73
|
-
|
|
73
|
+
login(): Promise<UserSession | null>;
|
|
74
74
|
/**
|
|
75
|
-
*
|
|
75
|
+
* Log out the current user
|
|
76
76
|
*/
|
|
77
|
-
|
|
77
|
+
logout(): void;
|
|
78
78
|
/**
|
|
79
79
|
* Get current user info
|
|
80
80
|
*/
|
|
81
|
-
|
|
81
|
+
getUser(): UserInfo | null;
|
|
82
82
|
/**
|
|
83
|
-
*
|
|
83
|
+
* Charge the user for using a feature
|
|
84
|
+
* Will automatically prompt for login if not authenticated
|
|
85
|
+
*
|
|
86
|
+
* @param action - Optional action name for analytics
|
|
87
|
+
* @returns ChargeResult with success status
|
|
84
88
|
*/
|
|
85
|
-
|
|
89
|
+
charge(action?: string, metadata?: Record<string, any>): Promise<ChargeResult>;
|
|
86
90
|
/**
|
|
87
|
-
*
|
|
88
|
-
* Opens the top-up modal or redirects to payment page
|
|
91
|
+
* Check if user can afford to use the app
|
|
89
92
|
*/
|
|
90
|
-
|
|
93
|
+
canAfford(): Promise<boolean>;
|
|
91
94
|
/**
|
|
92
|
-
*
|
|
95
|
+
* Get user's current balance
|
|
93
96
|
*/
|
|
94
|
-
|
|
97
|
+
getBalance(): Promise<number>;
|
|
95
98
|
/**
|
|
96
|
-
*
|
|
99
|
+
* Open top-up popup for user to add credits
|
|
97
100
|
*/
|
|
98
|
-
|
|
99
|
-
private startHeartbeat;
|
|
100
|
-
private sendHeartbeat;
|
|
101
|
-
private getUserSession;
|
|
101
|
+
openTopUp(): void;
|
|
102
102
|
/**
|
|
103
|
-
*
|
|
103
|
+
* Get price per use for this app
|
|
104
104
|
*/
|
|
105
|
-
|
|
105
|
+
getAppPrice(): Promise<number>;
|
|
106
106
|
/**
|
|
107
|
-
*
|
|
107
|
+
* Execute a function and charge the user
|
|
108
|
+
* Handles authentication, balance check, and charging automatically
|
|
108
109
|
*/
|
|
110
|
+
withCharge<T>(fn: () => Promise<T>, options?: {
|
|
111
|
+
action?: string;
|
|
112
|
+
metadata?: Record<string, any>;
|
|
113
|
+
}): Promise<T>;
|
|
114
|
+
trackUsage(params?: TrackUsageParams): Promise<TrackUsageResponse>;
|
|
115
|
+
requestTopUp(): void;
|
|
116
|
+
requestLogin(): void;
|
|
117
|
+
getUserInfo(): Promise<UserInfo>;
|
|
118
|
+
clearSession(): void;
|
|
109
119
|
destroy(): void;
|
|
110
|
-
/**
|
|
111
|
-
* Execute a function and automatically charge the user
|
|
112
|
-
* This is a convenience method that combines canAfford + your code + trackUsage
|
|
113
|
-
*
|
|
114
|
-
* @param fn - The async function to execute (your AI call, etc.)
|
|
115
|
-
* @param options - Optional tracking options
|
|
116
|
-
* @returns The result of your function
|
|
117
|
-
*
|
|
118
|
-
* Example:
|
|
119
|
-
* ```typescript
|
|
120
|
-
* const result = await opencloud.withUsage(async () => {
|
|
121
|
-
* const response = await fetch('https://api.openai.com/...', { ... });
|
|
122
|
-
* return await response.json();
|
|
123
|
-
* }, { action: 'chat_message' });
|
|
124
|
-
* ```
|
|
125
|
-
*/
|
|
126
|
-
withUsage<T>(fn: () => Promise<T>, options?: TrackUsageParams): Promise<T>;
|
|
127
120
|
}
|
|
128
121
|
declare const opencloud: OpenCloudSDK;
|
|
129
122
|
|
|
130
|
-
export { type OpenCloudConfig, OpenCloudSDK, type TrackUsageParams, type TrackUsageResponse, type UserInfo, type UserSession, opencloud };
|
|
123
|
+
export { type ChargeResult, type OpenCloudConfig, OpenCloudSDK, type TrackUsageParams, type TrackUsageResponse, type UserInfo, type UserSession, opencloud };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* opencloud-platform-sdk
|
|
2
|
+
* opencloud-platform-sdk v3.0.0
|
|
3
3
|
* Official SDK for OpenCloud - AI App Marketplace
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
* -
|
|
7
|
-
* -
|
|
8
|
-
* -
|
|
5
|
+
* Standalone Mode:
|
|
6
|
+
* - Works directly on any domain (no iframe required)
|
|
7
|
+
* - Uses popup for authentication
|
|
8
|
+
* - Charges from user's OpenCloud wallet
|
|
9
9
|
*/
|
|
10
10
|
interface OpenCloudConfig {
|
|
11
11
|
appId: string;
|
|
@@ -21,8 +21,21 @@ interface TrackUsageResponse {
|
|
|
21
21
|
userBalance: number;
|
|
22
22
|
transactionId: string;
|
|
23
23
|
}
|
|
24
|
+
interface ChargeResult {
|
|
25
|
+
success: boolean;
|
|
26
|
+
charged?: number;
|
|
27
|
+
balance?: number;
|
|
28
|
+
transactionId?: string;
|
|
29
|
+
error?: 'CANCELLED' | 'INSUFFICIENT_BALANCE' | 'NOT_AUTHENTICATED' | 'UNKNOWN';
|
|
30
|
+
}
|
|
24
31
|
interface UserSession {
|
|
25
32
|
token: string;
|
|
33
|
+
user?: {
|
|
34
|
+
id: string;
|
|
35
|
+
email: string;
|
|
36
|
+
username?: string;
|
|
37
|
+
balance?: number;
|
|
38
|
+
};
|
|
26
39
|
}
|
|
27
40
|
interface UserInfo {
|
|
28
41
|
id: string;
|
|
@@ -32,11 +45,15 @@ interface UserInfo {
|
|
|
32
45
|
}
|
|
33
46
|
declare class OpenCloudSDK {
|
|
34
47
|
private config;
|
|
35
|
-
private heartbeatInterval?;
|
|
36
48
|
private _isPreviewMode;
|
|
37
|
-
private
|
|
49
|
+
private _session;
|
|
50
|
+
private _authPopup;
|
|
38
51
|
constructor();
|
|
39
52
|
private detectPreviewMode;
|
|
53
|
+
private loadStoredSession;
|
|
54
|
+
private saveSession;
|
|
55
|
+
private clearStoredSession;
|
|
56
|
+
private setupMessageListener;
|
|
40
57
|
/**
|
|
41
58
|
* Check if running in preview/development mode
|
|
42
59
|
*/
|
|
@@ -46,85 +63,61 @@ declare class OpenCloudSDK {
|
|
|
46
63
|
*/
|
|
47
64
|
init(options: OpenCloudConfig): void;
|
|
48
65
|
/**
|
|
49
|
-
*
|
|
50
|
-
* Call this BEFORE or AFTER your AI/API call
|
|
51
|
-
*
|
|
52
|
-
* Example:
|
|
53
|
-
* ```
|
|
54
|
-
* // Check if user can afford it first
|
|
55
|
-
* const canUse = await opencloud.canAfford();
|
|
56
|
-
* if (!canUse) {
|
|
57
|
-
* opencloud.requestTopUp();
|
|
58
|
-
* return;
|
|
59
|
-
* }
|
|
60
|
-
*
|
|
61
|
-
* // Do your AI call
|
|
62
|
-
* const result = await myAICall();
|
|
63
|
-
*
|
|
64
|
-
* // Track the usage (charges user)
|
|
65
|
-
* await opencloud.trackUsage({ action: 'chat_message' });
|
|
66
|
-
* ```
|
|
66
|
+
* Check if user is authenticated with OpenCloud
|
|
67
67
|
*/
|
|
68
|
-
|
|
68
|
+
isAuthenticated(): boolean;
|
|
69
69
|
/**
|
|
70
|
-
*
|
|
71
|
-
* Returns
|
|
70
|
+
* Open login popup for user authentication
|
|
71
|
+
* Returns a promise that resolves when login is complete
|
|
72
72
|
*/
|
|
73
|
-
|
|
73
|
+
login(): Promise<UserSession | null>;
|
|
74
74
|
/**
|
|
75
|
-
*
|
|
75
|
+
* Log out the current user
|
|
76
76
|
*/
|
|
77
|
-
|
|
77
|
+
logout(): void;
|
|
78
78
|
/**
|
|
79
79
|
* Get current user info
|
|
80
80
|
*/
|
|
81
|
-
|
|
81
|
+
getUser(): UserInfo | null;
|
|
82
82
|
/**
|
|
83
|
-
*
|
|
83
|
+
* Charge the user for using a feature
|
|
84
|
+
* Will automatically prompt for login if not authenticated
|
|
85
|
+
*
|
|
86
|
+
* @param action - Optional action name for analytics
|
|
87
|
+
* @returns ChargeResult with success status
|
|
84
88
|
*/
|
|
85
|
-
|
|
89
|
+
charge(action?: string, metadata?: Record<string, any>): Promise<ChargeResult>;
|
|
86
90
|
/**
|
|
87
|
-
*
|
|
88
|
-
* Opens the top-up modal or redirects to payment page
|
|
91
|
+
* Check if user can afford to use the app
|
|
89
92
|
*/
|
|
90
|
-
|
|
93
|
+
canAfford(): Promise<boolean>;
|
|
91
94
|
/**
|
|
92
|
-
*
|
|
95
|
+
* Get user's current balance
|
|
93
96
|
*/
|
|
94
|
-
|
|
97
|
+
getBalance(): Promise<number>;
|
|
95
98
|
/**
|
|
96
|
-
*
|
|
99
|
+
* Open top-up popup for user to add credits
|
|
97
100
|
*/
|
|
98
|
-
|
|
99
|
-
private startHeartbeat;
|
|
100
|
-
private sendHeartbeat;
|
|
101
|
-
private getUserSession;
|
|
101
|
+
openTopUp(): void;
|
|
102
102
|
/**
|
|
103
|
-
*
|
|
103
|
+
* Get price per use for this app
|
|
104
104
|
*/
|
|
105
|
-
|
|
105
|
+
getAppPrice(): Promise<number>;
|
|
106
106
|
/**
|
|
107
|
-
*
|
|
107
|
+
* Execute a function and charge the user
|
|
108
|
+
* Handles authentication, balance check, and charging automatically
|
|
108
109
|
*/
|
|
110
|
+
withCharge<T>(fn: () => Promise<T>, options?: {
|
|
111
|
+
action?: string;
|
|
112
|
+
metadata?: Record<string, any>;
|
|
113
|
+
}): Promise<T>;
|
|
114
|
+
trackUsage(params?: TrackUsageParams): Promise<TrackUsageResponse>;
|
|
115
|
+
requestTopUp(): void;
|
|
116
|
+
requestLogin(): void;
|
|
117
|
+
getUserInfo(): Promise<UserInfo>;
|
|
118
|
+
clearSession(): void;
|
|
109
119
|
destroy(): void;
|
|
110
|
-
/**
|
|
111
|
-
* Execute a function and automatically charge the user
|
|
112
|
-
* This is a convenience method that combines canAfford + your code + trackUsage
|
|
113
|
-
*
|
|
114
|
-
* @param fn - The async function to execute (your AI call, etc.)
|
|
115
|
-
* @param options - Optional tracking options
|
|
116
|
-
* @returns The result of your function
|
|
117
|
-
*
|
|
118
|
-
* Example:
|
|
119
|
-
* ```typescript
|
|
120
|
-
* const result = await opencloud.withUsage(async () => {
|
|
121
|
-
* const response = await fetch('https://api.openai.com/...', { ... });
|
|
122
|
-
* return await response.json();
|
|
123
|
-
* }, { action: 'chat_message' });
|
|
124
|
-
* ```
|
|
125
|
-
*/
|
|
126
|
-
withUsage<T>(fn: () => Promise<T>, options?: TrackUsageParams): Promise<T>;
|
|
127
120
|
}
|
|
128
121
|
declare const opencloud: OpenCloudSDK;
|
|
129
122
|
|
|
130
|
-
export { type OpenCloudConfig, OpenCloudSDK, type TrackUsageParams, type TrackUsageResponse, type UserInfo, type UserSession, opencloud };
|
|
123
|
+
export { type ChargeResult, type OpenCloudConfig, OpenCloudSDK, type TrackUsageParams, type TrackUsageResponse, type UserInfo, type UserSession, opencloud };
|