@omen.foundation/game-sdk 1.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 +91 -0
- package/dist/index.d.mts +162 -0
- package/dist/index.d.ts +162 -0
- package/dist/index.js +465 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +463 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +41 -0
package/README.md
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# @omen.foundation/game-sdk
|
|
2
|
+
|
|
3
|
+
OmenX Game SDK for web applications - OAuth authentication and API integration.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @omen.foundation/game-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Quick Start
|
|
12
|
+
|
|
13
|
+
### Basic Usage
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { OmenXGameSDK } from '@omen.foundation/game-sdk';
|
|
17
|
+
|
|
18
|
+
const sdk = new OmenXGameSDK({
|
|
19
|
+
gameId: 'your-game-id',
|
|
20
|
+
onAuth: (authData) => {
|
|
21
|
+
console.log('Authenticated!', authData);
|
|
22
|
+
// User is now authenticated
|
|
23
|
+
},
|
|
24
|
+
onAuthError: (error) => {
|
|
25
|
+
console.error('Auth error:', error);
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Initialize SDK
|
|
30
|
+
await sdk.init();
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### OAuth Authentication
|
|
34
|
+
|
|
35
|
+
For standalone games (not embedded in iframes):
|
|
36
|
+
|
|
37
|
+
```typescript
|
|
38
|
+
// Authenticate user via OAuth popup
|
|
39
|
+
await sdk.authenticate({
|
|
40
|
+
redirectUri: 'https://yourgame.com/auth/callback',
|
|
41
|
+
enablePKCE: true, // Recommended for security
|
|
42
|
+
});
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Iframe Authentication
|
|
46
|
+
|
|
47
|
+
For games embedded in the OmenX frontend, authentication is automatic:
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
const sdk = new OmenXGameSDK({
|
|
51
|
+
gameId: 'your-game-id',
|
|
52
|
+
enableIframeAuth: true, // Default: true
|
|
53
|
+
parentOrigin: 'https://omen.foundation', // Optional: for security
|
|
54
|
+
onAuth: (authData) => {
|
|
55
|
+
// Auth data received automatically from parent window
|
|
56
|
+
},
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
await sdk.init();
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### Making API Calls
|
|
63
|
+
|
|
64
|
+
```typescript
|
|
65
|
+
// Make authenticated API calls
|
|
66
|
+
const response = await sdk.apiCall('/v1/nfts/templates?gameId=your-game-id');
|
|
67
|
+
const data = await response.json();
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Check Authentication Status
|
|
71
|
+
|
|
72
|
+
```typescript
|
|
73
|
+
if (sdk.isAuthenticated()) {
|
|
74
|
+
const authData = sdk.getAuthData();
|
|
75
|
+
console.log('User:', authData.walletAddress);
|
|
76
|
+
}
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Logout
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
await sdk.logout();
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
## API Reference
|
|
86
|
+
|
|
87
|
+
See the [full documentation](./docs/README.md) for detailed API reference.
|
|
88
|
+
|
|
89
|
+
## License
|
|
90
|
+
|
|
91
|
+
MIT
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication data received from OmenX
|
|
3
|
+
*/
|
|
4
|
+
interface AuthData {
|
|
5
|
+
accessToken: string;
|
|
6
|
+
walletAddress: string;
|
|
7
|
+
userId: string;
|
|
8
|
+
profileName?: string;
|
|
9
|
+
profilePicture?: string;
|
|
10
|
+
email?: string;
|
|
11
|
+
gameId: string;
|
|
12
|
+
timestamp: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* User information structure
|
|
16
|
+
*/
|
|
17
|
+
interface UserInfo {
|
|
18
|
+
walletAddress: string;
|
|
19
|
+
userId: string;
|
|
20
|
+
profileName?: string;
|
|
21
|
+
profilePicture?: string;
|
|
22
|
+
email?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Configuration for OmenXGameSDK
|
|
26
|
+
*/
|
|
27
|
+
interface OmenXGameSDKConfig {
|
|
28
|
+
/**
|
|
29
|
+
* Your game ID (from developer portal)
|
|
30
|
+
*/
|
|
31
|
+
gameId: string;
|
|
32
|
+
/**
|
|
33
|
+
* OmenX API base URL (default: https://api.omen.foundation)
|
|
34
|
+
*/
|
|
35
|
+
apiBaseUrl?: string;
|
|
36
|
+
/**
|
|
37
|
+
* OAuth authorization URL (default: https://api.omen.foundation/v1/oauth/authorize)
|
|
38
|
+
*/
|
|
39
|
+
oauthAuthorizeUrl?: string;
|
|
40
|
+
/**
|
|
41
|
+
* OAuth token URL (default: https://api.omen.foundation/v1/oauth/token)
|
|
42
|
+
*/
|
|
43
|
+
oauthTokenUrl?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Callback when authentication succeeds
|
|
46
|
+
*/
|
|
47
|
+
onAuth?: (authData: AuthData) => void;
|
|
48
|
+
/**
|
|
49
|
+
* Callback when authentication fails
|
|
50
|
+
*/
|
|
51
|
+
onAuthError?: (error: Error) => void;
|
|
52
|
+
/**
|
|
53
|
+
* Callback when user logs out
|
|
54
|
+
*/
|
|
55
|
+
onLogout?: () => void;
|
|
56
|
+
/**
|
|
57
|
+
* Enable iframe authentication (default: true)
|
|
58
|
+
* If true, SDK will listen for auth data from parent window
|
|
59
|
+
*/
|
|
60
|
+
enableIframeAuth?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Expected parent origin for iframe auth (security)
|
|
63
|
+
* If set, only messages from this origin will be accepted
|
|
64
|
+
*/
|
|
65
|
+
parentOrigin?: string;
|
|
66
|
+
/**
|
|
67
|
+
* Storage key prefix for tokens (default: 'omenx_game_')
|
|
68
|
+
*/
|
|
69
|
+
storageKeyPrefix?: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* OAuth authentication options
|
|
73
|
+
*/
|
|
74
|
+
interface OAuthOptions {
|
|
75
|
+
/**
|
|
76
|
+
* Redirect URI (must be registered in developer portal)
|
|
77
|
+
*/
|
|
78
|
+
redirectUri: string;
|
|
79
|
+
/**
|
|
80
|
+
* State parameter for CSRF protection (auto-generated if not provided)
|
|
81
|
+
*/
|
|
82
|
+
state?: string;
|
|
83
|
+
/**
|
|
84
|
+
* Enable PKCE (default: true)
|
|
85
|
+
*/
|
|
86
|
+
enablePKCE?: boolean;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* API call options
|
|
90
|
+
*/
|
|
91
|
+
interface ApiCallOptions {
|
|
92
|
+
/**
|
|
93
|
+
* HTTP method (default: 'GET')
|
|
94
|
+
*/
|
|
95
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
96
|
+
/**
|
|
97
|
+
* Request body
|
|
98
|
+
*/
|
|
99
|
+
body?: any;
|
|
100
|
+
/**
|
|
101
|
+
* Request headers
|
|
102
|
+
*/
|
|
103
|
+
headers?: Record<string, string>;
|
|
104
|
+
/**
|
|
105
|
+
* Whether to include authentication token (default: true)
|
|
106
|
+
*/
|
|
107
|
+
includeAuth?: boolean;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* OmenX Game SDK
|
|
112
|
+
*
|
|
113
|
+
* Provides authentication and API integration for games on the OmenX platform.
|
|
114
|
+
* Supports both OAuth-style authentication and iframe authentication passing.
|
|
115
|
+
*/
|
|
116
|
+
declare class OmenXGameSDK {
|
|
117
|
+
private config;
|
|
118
|
+
private oauthFlow;
|
|
119
|
+
private iframeAuth;
|
|
120
|
+
private tokenManager;
|
|
121
|
+
private currentAuthData;
|
|
122
|
+
constructor(config: OmenXGameSDKConfig);
|
|
123
|
+
/**
|
|
124
|
+
* Initialize the SDK
|
|
125
|
+
* Call this after creating an instance
|
|
126
|
+
*/
|
|
127
|
+
init(): Promise<void>;
|
|
128
|
+
/**
|
|
129
|
+
* Authenticate user via OAuth popup
|
|
130
|
+
*/
|
|
131
|
+
authenticate(options: OAuthOptions): Promise<AuthData>;
|
|
132
|
+
/**
|
|
133
|
+
* Get current authentication data
|
|
134
|
+
*/
|
|
135
|
+
getAuthData(): AuthData | null;
|
|
136
|
+
/**
|
|
137
|
+
* Check if user is authenticated
|
|
138
|
+
*/
|
|
139
|
+
isAuthenticated(): boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Logout user
|
|
142
|
+
*/
|
|
143
|
+
logout(): Promise<void>;
|
|
144
|
+
/**
|
|
145
|
+
* Make an authenticated API call
|
|
146
|
+
*/
|
|
147
|
+
apiCall(endpoint: string, options?: ApiCallOptions): Promise<Response>;
|
|
148
|
+
/**
|
|
149
|
+
* Handle token received from OAuth flow
|
|
150
|
+
*/
|
|
151
|
+
private handleTokenReceived;
|
|
152
|
+
/**
|
|
153
|
+
* Handle auth data from iframe
|
|
154
|
+
*/
|
|
155
|
+
private handleAuthData;
|
|
156
|
+
/**
|
|
157
|
+
* Refresh access token using refresh token
|
|
158
|
+
*/
|
|
159
|
+
private refreshAccessToken;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export { type ApiCallOptions, type AuthData, type OAuthOptions, OmenXGameSDK, type OmenXGameSDKConfig, type UserInfo };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication data received from OmenX
|
|
3
|
+
*/
|
|
4
|
+
interface AuthData {
|
|
5
|
+
accessToken: string;
|
|
6
|
+
walletAddress: string;
|
|
7
|
+
userId: string;
|
|
8
|
+
profileName?: string;
|
|
9
|
+
profilePicture?: string;
|
|
10
|
+
email?: string;
|
|
11
|
+
gameId: string;
|
|
12
|
+
timestamp: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* User information structure
|
|
16
|
+
*/
|
|
17
|
+
interface UserInfo {
|
|
18
|
+
walletAddress: string;
|
|
19
|
+
userId: string;
|
|
20
|
+
profileName?: string;
|
|
21
|
+
profilePicture?: string;
|
|
22
|
+
email?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Configuration for OmenXGameSDK
|
|
26
|
+
*/
|
|
27
|
+
interface OmenXGameSDKConfig {
|
|
28
|
+
/**
|
|
29
|
+
* Your game ID (from developer portal)
|
|
30
|
+
*/
|
|
31
|
+
gameId: string;
|
|
32
|
+
/**
|
|
33
|
+
* OmenX API base URL (default: https://api.omen.foundation)
|
|
34
|
+
*/
|
|
35
|
+
apiBaseUrl?: string;
|
|
36
|
+
/**
|
|
37
|
+
* OAuth authorization URL (default: https://api.omen.foundation/v1/oauth/authorize)
|
|
38
|
+
*/
|
|
39
|
+
oauthAuthorizeUrl?: string;
|
|
40
|
+
/**
|
|
41
|
+
* OAuth token URL (default: https://api.omen.foundation/v1/oauth/token)
|
|
42
|
+
*/
|
|
43
|
+
oauthTokenUrl?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Callback when authentication succeeds
|
|
46
|
+
*/
|
|
47
|
+
onAuth?: (authData: AuthData) => void;
|
|
48
|
+
/**
|
|
49
|
+
* Callback when authentication fails
|
|
50
|
+
*/
|
|
51
|
+
onAuthError?: (error: Error) => void;
|
|
52
|
+
/**
|
|
53
|
+
* Callback when user logs out
|
|
54
|
+
*/
|
|
55
|
+
onLogout?: () => void;
|
|
56
|
+
/**
|
|
57
|
+
* Enable iframe authentication (default: true)
|
|
58
|
+
* If true, SDK will listen for auth data from parent window
|
|
59
|
+
*/
|
|
60
|
+
enableIframeAuth?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Expected parent origin for iframe auth (security)
|
|
63
|
+
* If set, only messages from this origin will be accepted
|
|
64
|
+
*/
|
|
65
|
+
parentOrigin?: string;
|
|
66
|
+
/**
|
|
67
|
+
* Storage key prefix for tokens (default: 'omenx_game_')
|
|
68
|
+
*/
|
|
69
|
+
storageKeyPrefix?: string;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* OAuth authentication options
|
|
73
|
+
*/
|
|
74
|
+
interface OAuthOptions {
|
|
75
|
+
/**
|
|
76
|
+
* Redirect URI (must be registered in developer portal)
|
|
77
|
+
*/
|
|
78
|
+
redirectUri: string;
|
|
79
|
+
/**
|
|
80
|
+
* State parameter for CSRF protection (auto-generated if not provided)
|
|
81
|
+
*/
|
|
82
|
+
state?: string;
|
|
83
|
+
/**
|
|
84
|
+
* Enable PKCE (default: true)
|
|
85
|
+
*/
|
|
86
|
+
enablePKCE?: boolean;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* API call options
|
|
90
|
+
*/
|
|
91
|
+
interface ApiCallOptions {
|
|
92
|
+
/**
|
|
93
|
+
* HTTP method (default: 'GET')
|
|
94
|
+
*/
|
|
95
|
+
method?: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
96
|
+
/**
|
|
97
|
+
* Request body
|
|
98
|
+
*/
|
|
99
|
+
body?: any;
|
|
100
|
+
/**
|
|
101
|
+
* Request headers
|
|
102
|
+
*/
|
|
103
|
+
headers?: Record<string, string>;
|
|
104
|
+
/**
|
|
105
|
+
* Whether to include authentication token (default: true)
|
|
106
|
+
*/
|
|
107
|
+
includeAuth?: boolean;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* OmenX Game SDK
|
|
112
|
+
*
|
|
113
|
+
* Provides authentication and API integration for games on the OmenX platform.
|
|
114
|
+
* Supports both OAuth-style authentication and iframe authentication passing.
|
|
115
|
+
*/
|
|
116
|
+
declare class OmenXGameSDK {
|
|
117
|
+
private config;
|
|
118
|
+
private oauthFlow;
|
|
119
|
+
private iframeAuth;
|
|
120
|
+
private tokenManager;
|
|
121
|
+
private currentAuthData;
|
|
122
|
+
constructor(config: OmenXGameSDKConfig);
|
|
123
|
+
/**
|
|
124
|
+
* Initialize the SDK
|
|
125
|
+
* Call this after creating an instance
|
|
126
|
+
*/
|
|
127
|
+
init(): Promise<void>;
|
|
128
|
+
/**
|
|
129
|
+
* Authenticate user via OAuth popup
|
|
130
|
+
*/
|
|
131
|
+
authenticate(options: OAuthOptions): Promise<AuthData>;
|
|
132
|
+
/**
|
|
133
|
+
* Get current authentication data
|
|
134
|
+
*/
|
|
135
|
+
getAuthData(): AuthData | null;
|
|
136
|
+
/**
|
|
137
|
+
* Check if user is authenticated
|
|
138
|
+
*/
|
|
139
|
+
isAuthenticated(): boolean;
|
|
140
|
+
/**
|
|
141
|
+
* Logout user
|
|
142
|
+
*/
|
|
143
|
+
logout(): Promise<void>;
|
|
144
|
+
/**
|
|
145
|
+
* Make an authenticated API call
|
|
146
|
+
*/
|
|
147
|
+
apiCall(endpoint: string, options?: ApiCallOptions): Promise<Response>;
|
|
148
|
+
/**
|
|
149
|
+
* Handle token received from OAuth flow
|
|
150
|
+
*/
|
|
151
|
+
private handleTokenReceived;
|
|
152
|
+
/**
|
|
153
|
+
* Handle auth data from iframe
|
|
154
|
+
*/
|
|
155
|
+
private handleAuthData;
|
|
156
|
+
/**
|
|
157
|
+
* Refresh access token using refresh token
|
|
158
|
+
*/
|
|
159
|
+
private refreshAccessToken;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
export { type ApiCallOptions, type AuthData, type OAuthOptions, OmenXGameSDK, type OmenXGameSDKConfig, type UserInfo };
|