@playmos/sdk 0.1.6 → 0.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.
@@ -1,224 +0,0 @@
1
- /**
2
- * Public types — pruned to WIRED capability only (fixes #344/I and #335/E).
3
- *
4
- * The old vendored surface advertised four wallet connectors that silently
5
- * returned {connected:false} and config fields the code never read. Here the
6
- * types expose exactly what V1 does: two connectors, the fields `pay()` /
7
- * `enterRound()` actually use, and no more.
8
- */
9
- type Network = "base" | "base-sepolia";
10
- /** Only the connectors that are actually implemented. */
11
- type WalletConnector = "base-account" | "injected";
12
- type GasMode = "sponsored" | "player";
13
- type PaymentStatus = "created" | "pending" | "confirmed" | "failed";
14
- /** Minimal EIP-1193 provider shape (what the wallet must expose). */
15
- interface Eip1193Provider {
16
- request(args: {
17
- method: string;
18
- params?: unknown[] | object;
19
- }): Promise<unknown>;
20
- }
21
- interface GasConfig {
22
- mode?: GasMode;
23
- /** CDP paymaster URL — required only for `mode: "sponsored"`. */
24
- paymasterUrl?: string;
25
- }
26
- interface WalletConfig {
27
- connector?: WalletConnector;
28
- /**
29
- * Pre-built EIP-1193 provider. If omitted, `injected` uses globalThis.ethereum
30
- * and `base-account` expects a provider supplied by the Base Account SDK host.
31
- */
32
- provider?: Eip1193Provider;
33
- }
34
- /** Per-game contract addresses. On testnet these come from the service intent,
35
- * but a studio may pin them explicitly (matches the dogfood adapter). */
36
- interface ContractConfig {
37
- usdc?: `0x${string}`;
38
- playmosPay?: `0x${string}`;
39
- prizePool?: `0x${string}`;
40
- }
41
- interface AgentEconomyConfig {
42
- enabled?: boolean;
43
- /** Tax skimmed to Playmos on each agent↔agent transfer. 100 = 1% (default). */
44
- taxBps?: number;
45
- }
46
- interface PlaymosConfig {
47
- /** pk_test_* (sandbox / Base Sepolia) or pk_live_* (production / Base mainnet).
48
- * The key prefix selects the environment. */
49
- apiKey: string;
50
- /** Override the network derived from the key. Explicit value wins. */
51
- network?: Network;
52
- wallet?: WalletConfig;
53
- gas?: GasConfig;
54
- agentEconomy?: AgentEconomyConfig;
55
- contracts?: ContractConfig;
56
- /** Escape hatch; defaults to the right env's base URL. */
57
- apiBaseUrl?: string;
58
- /**
59
- * Explicit, clearly-labeled offline unit-test helper — instant, deterministic,
60
- * NO network, NO chain. Never the default, never conflated with sandbox. Note:
61
- * even mock results use the REAL status union (never a synthetic "mocked").
62
- */
63
- mock?: boolean;
64
- }
65
- interface PayInput {
66
- /** USD decimal string ("4.99"). Rejected: ≤ 0, non-numeric, > 2 dp. */
67
- amount: string;
68
- /** Your product id, echoed on the receipt + webhook. */
69
- sku: string;
70
- /** Your opaque user id. */
71
- playerId: string;
72
- /**
73
- * The game this IAP belongs to. Optional: when your API key maps to exactly
74
- * one game the service resolves it for you (the quickstart). Supply it
75
- * explicitly when your key spans multiple games.
76
- */
77
- gameId?: string;
78
- /** The studio wallet that receives the 99%. Falls back to the service default. */
79
- studio?: `0x${string}`;
80
- /** Supply your own to make retries safe; omit and the SDK generates a ULID. */
81
- idempotencyKey?: string;
82
- metadata?: Record<string, string>;
83
- }
84
- interface EnterRoundInput {
85
- /** The game — selects its prize-pool contract. */
86
- gameId: string;
87
- /** The round being entered. */
88
- roundId: string;
89
- /** USD entry — grows this round's pool. */
90
- amount: string;
91
- playerId: string;
92
- idempotencyKey?: string;
93
- metadata?: Record<string, string>;
94
- /**
95
- * Advanced (games that manage their own on-chain rounds, e.g. the Playmos
96
- * game-hub kit): the EXACT on-chain round key to enter — overrides the default
97
- * `${gameId}:${roundId}` derivation. Set it to the value your game's server
98
- * verifies `hasEntered` against (e.g. "bjtest:T1").
99
- */
100
- roundKey?: string;
101
- /**
102
- * Advanced: the EXACT on-chain identity for this paid attempt (e.g.
103
- * "0xWallet#nonce"). Overrides the server-generated identity so the on-chain
104
- * entry and your server's `hasEntered` check line up. One entry per identity.
105
- */
106
- identity?: string;
107
- }
108
- interface Payment {
109
- /** `pay_…` (IAP) or `entry_…` (prize-pool) — ULID, server-issued, unique. */
110
- id: string;
111
- status: PaymentStatus;
112
- /** "iap" (1% external) or "entry" (60/30/10 prize-pool). */
113
- kind: "iap" | "entry";
114
- amount: string;
115
- fee: string;
116
- net: string;
117
- /** Present for prize-pool entries: the 60/30/10 breakdown in USD. */
118
- split?: {
119
- pool: string;
120
- seed: string;
121
- rake: string;
122
- };
123
- sku?: string;
124
- roundId?: string;
125
- gameId?: string;
126
- playerId: string;
127
- txHash?: `0x${string}`;
128
- chain: Network;
129
- createdAt: string;
130
- metadata?: Record<string, string>;
131
- /**
132
- * The on-chain identity used for a prize-pool entry (echo of
133
- * `EnterRoundInput.identity` or the SDK-derived value) — reconcile against your
134
- * server's `hasEntered`.
135
- */
136
- identity?: string;
137
- /** True only when produced by the labeled `mock: true` helper. */
138
- mock?: boolean;
139
- }
140
- /** What `verify()` resolves to (server reads the chain). */
141
- interface VerifyResult {
142
- id: string;
143
- status: PaymentStatus;
144
- amount: string;
145
- fee: string;
146
- net: string;
147
- txHash?: `0x${string}`;
148
- playerId: string;
149
- sku?: string;
150
- roundId?: string;
151
- chain: Network;
152
- /** How the service derived this status: an on-chain read, the honest cache, or
153
- * degraded (chain reads not configured). Lets the SDK stop polling when the
154
- * service can never confirm on-chain. */
155
- verifiedVia?: "chain" | "cache" | "degraded";
156
- chainReads?: "enabled" | "degraded";
157
- }
158
- type WebhookEventType = "payment.confirmed" | "payment.failed" | "payout.settled" | "refund.processed";
159
- interface WebhookEvent {
160
- id: string;
161
- type: WebhookEventType;
162
- createdAt: string;
163
- data: {
164
- id: string;
165
- status: PaymentStatus;
166
- amount: string;
167
- fee: string;
168
- net: string;
169
- playerId: string;
170
- sku?: string;
171
- txHash?: `0x${string}`;
172
- chain: Network;
173
- metadata?: Record<string, string>;
174
- };
175
- }
176
-
177
- /**
178
- * Typed, actionable errors — the Stripe bar (spec §11).
179
- *
180
- * Every error carries a stable machine-readable `code` and is thrown at the
181
- * EARLIEST possible layer: input errors fire client-side before any network or
182
- * chain call, so a studio never pays gas to discover a typo.
183
- */
184
- type PlaymosErrorCode = "invalid_amount" | "missing_field" | "insufficient_gas" | "wallet_connection" | "payment_failed" | "auth" | "api_error" | "config";
185
- declare class PlaymosError extends Error {
186
- readonly code: PlaymosErrorCode;
187
- /** Optional machine context (e.g. the offending field, the http status). */
188
- readonly detail?: Record<string, unknown>;
189
- constructor(code: PlaymosErrorCode, message: string, detail?: Record<string, unknown>);
190
- }
191
- /** amount ≤ 0, non-numeric, empty, or more than 2 decimal places. */
192
- declare class InvalidAmountError extends PlaymosError {
193
- constructor(amount: unknown);
194
- }
195
- /** A required field (sku, playerId, gameId, roundId, agentId…) was empty. */
196
- declare class MissingFieldError extends PlaymosError {
197
- constructor(field: string);
198
- }
199
- /** gas mode "player" and the player's ETH is too low to cover gas (pre-check, §7). */
200
- declare class InsufficientGasError extends PlaymosError {
201
- constructor(detail?: Record<string, unknown>);
202
- }
203
- /** The player closed or failed the wallet sheet, or no provider is available. */
204
- declare class WalletConnectionError extends PlaymosError {
205
- constructor(message?: string, detail?: Record<string, unknown>);
206
- }
207
- /** The on-chain settlement reverted, was cancelled, or timed out. */
208
- declare class PaymentFailedError extends PlaymosError {
209
- constructor(message?: string, detail?: Record<string, unknown>);
210
- }
211
- /** Bad, missing, or wrong-environment API key (e.g. a pk_test_ key on a live route). */
212
- declare class AuthError extends PlaymosError {
213
- constructor(message?: string, detail?: Record<string, unknown>);
214
- }
215
- /** The Playmos service returned a non-2xx we don't have a more specific error for. */
216
- declare class ApiError extends PlaymosError {
217
- constructor(message: string, detail?: Record<string, unknown>);
218
- }
219
- /** SDK misconfiguration (e.g. a missing contract address for on-chain mode). */
220
- declare class ConfigError extends PlaymosError {
221
- constructor(message: string, detail?: Record<string, unknown>);
222
- }
223
-
224
- export { type AgentEconomyConfig as A, ConfigError as C, type EnterRoundInput as E, type GasConfig as G, InsufficientGasError as I, MissingFieldError as M, type Network as N, type PlaymosConfig as P, type VerifyResult as V, type WebhookEvent as W, type PayInput as a, type Payment as b, ApiError as c, AuthError as d, type ContractConfig as e, type Eip1193Provider as f, type GasMode as g, InvalidAmountError as h, PaymentFailedError as i, type PaymentStatus as j, PlaymosError as k, type PlaymosErrorCode as l, type WalletConfig as m, WalletConnectionError as n, type WalletConnector as o, type WebhookEventType as p };
@@ -1,224 +0,0 @@
1
- /**
2
- * Public types — pruned to WIRED capability only (fixes #344/I and #335/E).
3
- *
4
- * The old vendored surface advertised four wallet connectors that silently
5
- * returned {connected:false} and config fields the code never read. Here the
6
- * types expose exactly what V1 does: two connectors, the fields `pay()` /
7
- * `enterRound()` actually use, and no more.
8
- */
9
- type Network = "base" | "base-sepolia";
10
- /** Only the connectors that are actually implemented. */
11
- type WalletConnector = "base-account" | "injected";
12
- type GasMode = "sponsored" | "player";
13
- type PaymentStatus = "created" | "pending" | "confirmed" | "failed";
14
- /** Minimal EIP-1193 provider shape (what the wallet must expose). */
15
- interface Eip1193Provider {
16
- request(args: {
17
- method: string;
18
- params?: unknown[] | object;
19
- }): Promise<unknown>;
20
- }
21
- interface GasConfig {
22
- mode?: GasMode;
23
- /** CDP paymaster URL — required only for `mode: "sponsored"`. */
24
- paymasterUrl?: string;
25
- }
26
- interface WalletConfig {
27
- connector?: WalletConnector;
28
- /**
29
- * Pre-built EIP-1193 provider. If omitted, `injected` uses globalThis.ethereum
30
- * and `base-account` expects a provider supplied by the Base Account SDK host.
31
- */
32
- provider?: Eip1193Provider;
33
- }
34
- /** Per-game contract addresses. On testnet these come from the service intent,
35
- * but a studio may pin them explicitly (matches the dogfood adapter). */
36
- interface ContractConfig {
37
- usdc?: `0x${string}`;
38
- playmosPay?: `0x${string}`;
39
- prizePool?: `0x${string}`;
40
- }
41
- interface AgentEconomyConfig {
42
- enabled?: boolean;
43
- /** Tax skimmed to Playmos on each agent↔agent transfer. 100 = 1% (default). */
44
- taxBps?: number;
45
- }
46
- interface PlaymosConfig {
47
- /** pk_test_* (sandbox / Base Sepolia) or pk_live_* (production / Base mainnet).
48
- * The key prefix selects the environment. */
49
- apiKey: string;
50
- /** Override the network derived from the key. Explicit value wins. */
51
- network?: Network;
52
- wallet?: WalletConfig;
53
- gas?: GasConfig;
54
- agentEconomy?: AgentEconomyConfig;
55
- contracts?: ContractConfig;
56
- /** Escape hatch; defaults to the right env's base URL. */
57
- apiBaseUrl?: string;
58
- /**
59
- * Explicit, clearly-labeled offline unit-test helper — instant, deterministic,
60
- * NO network, NO chain. Never the default, never conflated with sandbox. Note:
61
- * even mock results use the REAL status union (never a synthetic "mocked").
62
- */
63
- mock?: boolean;
64
- }
65
- interface PayInput {
66
- /** USD decimal string ("4.99"). Rejected: ≤ 0, non-numeric, > 2 dp. */
67
- amount: string;
68
- /** Your product id, echoed on the receipt + webhook. */
69
- sku: string;
70
- /** Your opaque user id. */
71
- playerId: string;
72
- /**
73
- * The game this IAP belongs to. Optional: when your API key maps to exactly
74
- * one game the service resolves it for you (the quickstart). Supply it
75
- * explicitly when your key spans multiple games.
76
- */
77
- gameId?: string;
78
- /** The studio wallet that receives the 99%. Falls back to the service default. */
79
- studio?: `0x${string}`;
80
- /** Supply your own to make retries safe; omit and the SDK generates a ULID. */
81
- idempotencyKey?: string;
82
- metadata?: Record<string, string>;
83
- }
84
- interface EnterRoundInput {
85
- /** The game — selects its prize-pool contract. */
86
- gameId: string;
87
- /** The round being entered. */
88
- roundId: string;
89
- /** USD entry — grows this round's pool. */
90
- amount: string;
91
- playerId: string;
92
- idempotencyKey?: string;
93
- metadata?: Record<string, string>;
94
- /**
95
- * Advanced (games that manage their own on-chain rounds, e.g. the Playmos
96
- * game-hub kit): the EXACT on-chain round key to enter — overrides the default
97
- * `${gameId}:${roundId}` derivation. Set it to the value your game's server
98
- * verifies `hasEntered` against (e.g. "bjtest:T1").
99
- */
100
- roundKey?: string;
101
- /**
102
- * Advanced: the EXACT on-chain identity for this paid attempt (e.g.
103
- * "0xWallet#nonce"). Overrides the server-generated identity so the on-chain
104
- * entry and your server's `hasEntered` check line up. One entry per identity.
105
- */
106
- identity?: string;
107
- }
108
- interface Payment {
109
- /** `pay_…` (IAP) or `entry_…` (prize-pool) — ULID, server-issued, unique. */
110
- id: string;
111
- status: PaymentStatus;
112
- /** "iap" (1% external) or "entry" (60/30/10 prize-pool). */
113
- kind: "iap" | "entry";
114
- amount: string;
115
- fee: string;
116
- net: string;
117
- /** Present for prize-pool entries: the 60/30/10 breakdown in USD. */
118
- split?: {
119
- pool: string;
120
- seed: string;
121
- rake: string;
122
- };
123
- sku?: string;
124
- roundId?: string;
125
- gameId?: string;
126
- playerId: string;
127
- txHash?: `0x${string}`;
128
- chain: Network;
129
- createdAt: string;
130
- metadata?: Record<string, string>;
131
- /**
132
- * The on-chain identity used for a prize-pool entry (echo of
133
- * `EnterRoundInput.identity` or the SDK-derived value) — reconcile against your
134
- * server's `hasEntered`.
135
- */
136
- identity?: string;
137
- /** True only when produced by the labeled `mock: true` helper. */
138
- mock?: boolean;
139
- }
140
- /** What `verify()` resolves to (server reads the chain). */
141
- interface VerifyResult {
142
- id: string;
143
- status: PaymentStatus;
144
- amount: string;
145
- fee: string;
146
- net: string;
147
- txHash?: `0x${string}`;
148
- playerId: string;
149
- sku?: string;
150
- roundId?: string;
151
- chain: Network;
152
- /** How the service derived this status: an on-chain read, the honest cache, or
153
- * degraded (chain reads not configured). Lets the SDK stop polling when the
154
- * service can never confirm on-chain. */
155
- verifiedVia?: "chain" | "cache" | "degraded";
156
- chainReads?: "enabled" | "degraded";
157
- }
158
- type WebhookEventType = "payment.confirmed" | "payment.failed" | "payout.settled" | "refund.processed";
159
- interface WebhookEvent {
160
- id: string;
161
- type: WebhookEventType;
162
- createdAt: string;
163
- data: {
164
- id: string;
165
- status: PaymentStatus;
166
- amount: string;
167
- fee: string;
168
- net: string;
169
- playerId: string;
170
- sku?: string;
171
- txHash?: `0x${string}`;
172
- chain: Network;
173
- metadata?: Record<string, string>;
174
- };
175
- }
176
-
177
- /**
178
- * Typed, actionable errors — the Stripe bar (spec §11).
179
- *
180
- * Every error carries a stable machine-readable `code` and is thrown at the
181
- * EARLIEST possible layer: input errors fire client-side before any network or
182
- * chain call, so a studio never pays gas to discover a typo.
183
- */
184
- type PlaymosErrorCode = "invalid_amount" | "missing_field" | "insufficient_gas" | "wallet_connection" | "payment_failed" | "auth" | "api_error" | "config";
185
- declare class PlaymosError extends Error {
186
- readonly code: PlaymosErrorCode;
187
- /** Optional machine context (e.g. the offending field, the http status). */
188
- readonly detail?: Record<string, unknown>;
189
- constructor(code: PlaymosErrorCode, message: string, detail?: Record<string, unknown>);
190
- }
191
- /** amount ≤ 0, non-numeric, empty, or more than 2 decimal places. */
192
- declare class InvalidAmountError extends PlaymosError {
193
- constructor(amount: unknown);
194
- }
195
- /** A required field (sku, playerId, gameId, roundId, agentId…) was empty. */
196
- declare class MissingFieldError extends PlaymosError {
197
- constructor(field: string);
198
- }
199
- /** gas mode "player" and the player's ETH is too low to cover gas (pre-check, §7). */
200
- declare class InsufficientGasError extends PlaymosError {
201
- constructor(detail?: Record<string, unknown>);
202
- }
203
- /** The player closed or failed the wallet sheet, or no provider is available. */
204
- declare class WalletConnectionError extends PlaymosError {
205
- constructor(message?: string, detail?: Record<string, unknown>);
206
- }
207
- /** The on-chain settlement reverted, was cancelled, or timed out. */
208
- declare class PaymentFailedError extends PlaymosError {
209
- constructor(message?: string, detail?: Record<string, unknown>);
210
- }
211
- /** Bad, missing, or wrong-environment API key (e.g. a pk_test_ key on a live route). */
212
- declare class AuthError extends PlaymosError {
213
- constructor(message?: string, detail?: Record<string, unknown>);
214
- }
215
- /** The Playmos service returned a non-2xx we don't have a more specific error for. */
216
- declare class ApiError extends PlaymosError {
217
- constructor(message: string, detail?: Record<string, unknown>);
218
- }
219
- /** SDK misconfiguration (e.g. a missing contract address for on-chain mode). */
220
- declare class ConfigError extends PlaymosError {
221
- constructor(message: string, detail?: Record<string, unknown>);
222
- }
223
-
224
- export { type AgentEconomyConfig as A, ConfigError as C, type EnterRoundInput as E, type GasConfig as G, InsufficientGasError as I, MissingFieldError as M, type Network as N, type PlaymosConfig as P, type VerifyResult as V, type WebhookEvent as W, type PayInput as a, type Payment as b, ApiError as c, AuthError as d, type ContractConfig as e, type Eip1193Provider as f, type GasMode as g, InvalidAmountError as h, PaymentFailedError as i, type PaymentStatus as j, PlaymosError as k, type PlaymosErrorCode as l, type WalletConfig as m, WalletConnectionError as n, type WalletConnector as o, type WebhookEventType as p };