@arcadiasol/sdk 1.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 +139 -0
- package/dist/esm/api-client.d.ts +54 -0
- package/dist/esm/api-client.d.ts.map +1 -0
- package/dist/esm/errors.d.ts +51 -0
- package/dist/esm/errors.d.ts.map +1 -0
- package/dist/esm/index.d.ts +13 -0
- package/dist/esm/index.d.ts.map +1 -0
- package/dist/esm/index.js +929 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/messaging.d.ts +33 -0
- package/dist/esm/messaging.d.ts.map +1 -0
- package/dist/esm/payment.d.ts +35 -0
- package/dist/esm/payment.d.ts.map +1 -0
- package/dist/esm/sdk.d.ts +73 -0
- package/dist/esm/sdk.d.ts.map +1 -0
- package/dist/esm/types.d.ts +136 -0
- package/dist/esm/types.d.ts.map +1 -0
- package/dist/esm/wallet.d.ts +48 -0
- package/dist/esm/wallet.d.ts.map +1 -0
- package/dist/umd/arcadia-game-sdk.js +949 -0
- package/dist/umd/arcadia-game-sdk.js.map +1 -0
- package/dist/umd/arcadia-game-sdk.min.js +1 -0
- package/examples/basic-integration.html +219 -0
- package/examples/payment-example.html +330 -0
- package/examples/wallet-example.html +298 -0
- package/package.json +53 -0
package/README.md
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
# Arcadia Game SDK
|
|
2
|
+
|
|
3
|
+
SDK for integrating Arcadia wallet and payment features into Web3 games.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- ✅ **Wallet Integration** - Get wallet address, check connection status
|
|
8
|
+
- ✅ **Payment Processing** - Pay-to-play and in-game purchases
|
|
9
|
+
- ✅ **Iframe Support** - Works seamlessly in Arcadia iframes
|
|
10
|
+
- ✅ **Non-Iframe Support** - Works with direct API calls for native apps
|
|
11
|
+
- ✅ **Stats Tracking** - Track playtime and online status (non-iframe mode)
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
### NPM
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
npm install @arcadiasol/sdk
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### CDN
|
|
22
|
+
|
|
23
|
+
```html
|
|
24
|
+
<script src="https://cdn.jsdelivr.net/npm/@arcadiasol/sdk@latest/dist/umd/arcadia-game-sdk.js"></script>
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Quick Start
|
|
28
|
+
|
|
29
|
+
### Iframe Mode (Web Games)
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import ArcadiaSDK from '@arcadiasol/sdk';
|
|
33
|
+
|
|
34
|
+
const arcadia = new ArcadiaSDK({
|
|
35
|
+
gameId: 'your-game-id',
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
await arcadia.init();
|
|
39
|
+
|
|
40
|
+
// Get wallet address
|
|
41
|
+
const walletAddress = await arcadia.getWalletAddress();
|
|
42
|
+
|
|
43
|
+
// Pay to play
|
|
44
|
+
const result = await arcadia.payment.payToPlay(0.1, 'SOL');
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### Non-Iframe Mode (Native Apps / External Games)
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import ArcadiaSDK from '@arcadiasol/sdk';
|
|
51
|
+
|
|
52
|
+
const arcadia = new ArcadiaSDK({
|
|
53
|
+
gameId: 'your-game-id',
|
|
54
|
+
apiBaseURL: 'https://arcadia.com', // Required for non-iframe
|
|
55
|
+
authToken: 'your-auth-token', // Optional: if you have auth token
|
|
56
|
+
walletAddress: 'your-wallet-address', // Optional: if you know wallet address
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
await arcadia.init();
|
|
60
|
+
|
|
61
|
+
// Get wallet address
|
|
62
|
+
const walletAddress = await arcadia.getWalletAddress();
|
|
63
|
+
|
|
64
|
+
// Track playtime
|
|
65
|
+
await arcadia.stats.updatePlaytime(1.5, 'playing');
|
|
66
|
+
|
|
67
|
+
// Update online status
|
|
68
|
+
await arcadia.stats.updateOnlineStatus(true);
|
|
69
|
+
|
|
70
|
+
// Pay to play (requires transaction signature)
|
|
71
|
+
// Note: You must sign the transaction yourself in non-iframe mode
|
|
72
|
+
const txSignature = await signTransaction(...); // Your signing logic
|
|
73
|
+
const result = await arcadia.payment.payToPlay(0.1, 'SOL', txSignature);
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
## API Reference
|
|
77
|
+
|
|
78
|
+
### Constructor
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
new ArcadiaSDK(config: SDKConfig)
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
**Config Options:**
|
|
85
|
+
- `gameId` (string, required) - Your game identifier
|
|
86
|
+
- `parentOrigin` (string, optional) - Parent window origin for iframe security
|
|
87
|
+
- `timeout` (number, optional) - Request timeout in milliseconds (default: 30000)
|
|
88
|
+
- `apiBaseURL` (string, optional) - Base URL for API calls (required for non-iframe)
|
|
89
|
+
- `authToken` (string, optional) - Pre-authenticated token (non-iframe mode)
|
|
90
|
+
- `walletAddress` (string, optional) - Wallet address (non-iframe mode)
|
|
91
|
+
|
|
92
|
+
### Methods
|
|
93
|
+
|
|
94
|
+
#### `init(): Promise<void>`
|
|
95
|
+
|
|
96
|
+
Initialize SDK. Must be called after creating SDK instance.
|
|
97
|
+
|
|
98
|
+
#### `getWalletAddress(): Promise<string | null>`
|
|
99
|
+
|
|
100
|
+
Get connected wallet address. Returns `null` if not connected.
|
|
101
|
+
|
|
102
|
+
#### `isWalletConnected(): Promise<boolean>`
|
|
103
|
+
|
|
104
|
+
Check if wallet is connected.
|
|
105
|
+
|
|
106
|
+
#### `onWalletChange(callback: Function): void`
|
|
107
|
+
|
|
108
|
+
Listen for wallet connection changes.
|
|
109
|
+
|
|
110
|
+
#### `payment.payToPlay(amount, token, txSignature?)`
|
|
111
|
+
|
|
112
|
+
Pay to play. `txSignature` required for non-iframe mode.
|
|
113
|
+
|
|
114
|
+
#### `payment.purchaseItem(itemId, amount, token, txSignature?)`
|
|
115
|
+
|
|
116
|
+
Purchase in-game item. `txSignature` required for non-iframe mode.
|
|
117
|
+
|
|
118
|
+
#### `stats.updatePlaytime(hours, status?)`
|
|
119
|
+
|
|
120
|
+
Update playtime (non-iframe mode only).
|
|
121
|
+
|
|
122
|
+
#### `stats.updateOnlineStatus(isOnline)`
|
|
123
|
+
|
|
124
|
+
Update online status (non-iframe mode only).
|
|
125
|
+
|
|
126
|
+
## Environment Detection
|
|
127
|
+
|
|
128
|
+
The SDK automatically detects if it's running in an iframe:
|
|
129
|
+
|
|
130
|
+
- **Iframe Mode**: Uses `postMessage` for communication
|
|
131
|
+
- **Non-Iframe Mode**: Uses REST API calls (requires `apiBaseURL`)
|
|
132
|
+
|
|
133
|
+
## Examples
|
|
134
|
+
|
|
135
|
+
See `/examples` directory for complete examples.
|
|
136
|
+
|
|
137
|
+
## Documentation
|
|
138
|
+
|
|
139
|
+
Full documentation: https://docs.arcadia.com/sdk
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { PaymentRequest, PaymentResponse, WalletAddressResponse } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* API Client for non-iframe environments
|
|
4
|
+
* Handles direct REST API calls when SDK is not running in iframe
|
|
5
|
+
*/
|
|
6
|
+
export declare class APIClient {
|
|
7
|
+
private baseURL;
|
|
8
|
+
private authToken;
|
|
9
|
+
private walletAddress;
|
|
10
|
+
constructor(baseURL?: string);
|
|
11
|
+
/**
|
|
12
|
+
* Detect Arcadia base URL from environment or use default
|
|
13
|
+
*/
|
|
14
|
+
private detectBaseURL;
|
|
15
|
+
/**
|
|
16
|
+
* Set authentication token (from wallet authentication)
|
|
17
|
+
*/
|
|
18
|
+
setAuthToken(token: string): void;
|
|
19
|
+
/**
|
|
20
|
+
* Set wallet address (for wallet-based auth)
|
|
21
|
+
*/
|
|
22
|
+
setWalletAddress(address: string): void;
|
|
23
|
+
/**
|
|
24
|
+
* Authenticate with wallet
|
|
25
|
+
* Returns auth token for subsequent API calls
|
|
26
|
+
*/
|
|
27
|
+
authenticateWithWallet(walletAddress: string, signature: string, message: string): Promise<{
|
|
28
|
+
token: string;
|
|
29
|
+
user: any;
|
|
30
|
+
profile: any;
|
|
31
|
+
}>;
|
|
32
|
+
/**
|
|
33
|
+
* Get wallet address (for non-iframe)
|
|
34
|
+
* Requires authentication
|
|
35
|
+
*/
|
|
36
|
+
getWalletAddress(): Promise<WalletAddressResponse>;
|
|
37
|
+
/**
|
|
38
|
+
* Send payment request via API
|
|
39
|
+
*/
|
|
40
|
+
sendPaymentRequest(gameId: string, request: PaymentRequest): Promise<PaymentResponse>;
|
|
41
|
+
/**
|
|
42
|
+
* Update playtime/stats
|
|
43
|
+
*/
|
|
44
|
+
updatePlaytime(gameId: string, playtimeHours: number, status?: 'playing' | 'owned' | 'completed'): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Update online status
|
|
47
|
+
*/
|
|
48
|
+
updateOnlineStatus(isOnline: boolean, gameId?: string): Promise<void>;
|
|
49
|
+
/**
|
|
50
|
+
* Generic request method
|
|
51
|
+
*/
|
|
52
|
+
private request;
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=api-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api-client.d.ts","sourceRoot":"","sources":["../../src/api-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAC;AAEjF;;;GAGG;AACH,qBAAa,SAAS;IACpB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,SAAS,CAAuB;IACxC,OAAO,CAAC,aAAa,CAAuB;gBAEhC,OAAO,CAAC,EAAE,MAAM;IAK5B;;OAEG;IACH,OAAO,CAAC,aAAa;IAmBrB;;OAEG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIjC;;OAEG;IACH,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI;IAIvC;;;OAGG;IACG,sBAAsB,CAC1B,aAAa,EAAE,MAAM,EACrB,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,MAAM,GACd,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,GAAG,CAAC;QAAC,OAAO,EAAE,GAAG,CAAA;KAAE,CAAC;IAmBtD;;;OAGG;IACG,gBAAgB,IAAI,OAAO,CAAC,qBAAqB,CAAC;IAuCxD;;OAEG;IACG,kBAAkB,CACtB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,cAAc,GACtB,OAAO,CAAC,eAAe,CAAC;IAgB3B;;OAEG;IACG,cAAc,CAClB,MAAM,EAAE,MAAM,EACd,aAAa,EAAE,MAAM,EACrB,MAAM,CAAC,EAAE,SAAS,GAAG,OAAO,GAAG,WAAW,GACzC,OAAO,CAAC,IAAI,CAAC;IAWhB;;OAEG;IACG,kBAAkB,CAAC,QAAQ,EAAE,OAAO,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAU3E;;OAEG;YACW,OAAO;CAgCtB"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for all SDK errors
|
|
3
|
+
*/
|
|
4
|
+
export declare class ArcadiaSDKError extends Error {
|
|
5
|
+
code?: string | undefined;
|
|
6
|
+
constructor(message: string, code?: string | undefined);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Error thrown when wallet is not connected
|
|
10
|
+
*/
|
|
11
|
+
export declare class WalletNotConnectedError extends ArcadiaSDKError {
|
|
12
|
+
constructor(message?: string);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Error thrown when payment fails
|
|
16
|
+
*/
|
|
17
|
+
export declare class PaymentFailedError extends ArcadiaSDKError {
|
|
18
|
+
txSignature?: string | undefined;
|
|
19
|
+
constructor(message?: string, txSignature?: string | undefined);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Error thrown when request times out
|
|
23
|
+
*/
|
|
24
|
+
export declare class TimeoutError extends ArcadiaSDKError {
|
|
25
|
+
constructor(message?: string);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Error thrown when SDK configuration is invalid
|
|
29
|
+
*/
|
|
30
|
+
export declare class InvalidConfigError extends ArcadiaSDKError {
|
|
31
|
+
constructor(message?: string);
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Error thrown when SDK is not running in iframe
|
|
35
|
+
*/
|
|
36
|
+
export declare class NotInIframeError extends ArcadiaSDKError {
|
|
37
|
+
constructor(message?: string);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Error thrown when invalid amount is provided
|
|
41
|
+
*/
|
|
42
|
+
export declare class InvalidAmountError extends ArcadiaSDKError {
|
|
43
|
+
constructor(message?: string);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Error thrown when invalid token is provided
|
|
47
|
+
*/
|
|
48
|
+
export declare class InvalidTokenError extends ArcadiaSDKError {
|
|
49
|
+
constructor(message?: string);
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,eAAgB,SAAQ,KAAK;IACJ,IAAI,CAAC,EAAE,MAAM;gBAArC,OAAO,EAAE,MAAM,EAAS,IAAI,CAAC,EAAE,MAAM,YAAA;CAKlD;AAED;;GAEG;AACH,qBAAa,uBAAwB,SAAQ,eAAe;gBAC9C,OAAO,GAAE,MAA0E;CAKhG;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,eAAe;IACE,WAAW,CAAC,EAAE,MAAM;gBAA/D,OAAO,GAAE,MAAyB,EAAS,WAAW,CAAC,EAAE,MAAM,YAAA;CAK5E;AAED;;GAEG;AACH,qBAAa,YAAa,SAAQ,eAAe;gBACnC,OAAO,GAAE,MAA+C;CAKrE;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,eAAe;gBACzC,OAAO,GAAE,MAAoC;CAK1D;AAED;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,eAAe;gBACvC,OAAO,GAAE,MAAiF;CAKvG;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,eAAe;gBACzC,OAAO,GAAE,MAAiE;CAKvF;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,eAAe;gBACxC,OAAO,GAAE,MAAkD;CAKxE"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Arcadia Game SDK
|
|
3
|
+
*
|
|
4
|
+
* SDK for integrating Arcadia wallet and payment features into Web3 games.
|
|
5
|
+
* Works in iframe environments by communicating with parent window via postMessage.
|
|
6
|
+
*/
|
|
7
|
+
export { ArcadiaSDK } from './sdk';
|
|
8
|
+
export { APIClient } from './api-client';
|
|
9
|
+
export type { SDKConfig, PaymentResult, WalletInfo, MessageType, PaymentRequest, PaymentResponse, InitData, WalletAddressResponse, } from './types';
|
|
10
|
+
export { ArcadiaSDKError, WalletNotConnectedError, PaymentFailedError, TimeoutError, InvalidConfigError, NotInIframeError, InvalidAmountError, InvalidTokenError, } from './errors';
|
|
11
|
+
import { ArcadiaSDK } from './sdk';
|
|
12
|
+
export default ArcadiaSDK;
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAGnC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAGzC,YAAY,EACV,SAAS,EACT,aAAa,EACb,UAAU,EACV,WAAW,EACX,cAAc,EACd,eAAe,EACf,QAAQ,EACR,qBAAqB,GACtB,MAAM,SAAS,CAAC;AAGjB,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,kBAAkB,EAClB,YAAY,EACZ,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,UAAU,CAAC;AAGlB,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AACnC,eAAe,UAAU,CAAC"}
|