@playcademy/sdk 0.0.1-beta.2 → 0.0.1-beta.20

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.
@@ -0,0 +1,511 @@
1
+ /**
2
+ * @fileoverview Playcademy Messaging System
3
+ *
4
+ * This file implements a unified messaging system for the Playcademy platform that handles
5
+ * communication between different contexts:
6
+ *
7
+ * 1. **Iframe-to-Parent Communication**: When games run inside iframes (production/development),
8
+ * they need to communicate with the parent window using postMessage API
9
+ *
10
+ * 2. **Local Communication**: When games run in the same context (local development),
11
+ * they use CustomEvents for internal messaging
12
+ *
13
+ * The system automatically detects the runtime environment and chooses the appropriate
14
+ * transport method, abstracting this complexity from the developer.
15
+ *
16
+ * **Architecture Overview**:
17
+ * - Games run in iframes for security and isolation
18
+ * - Parent window (Playcademy shell) manages game lifecycle
19
+ * - Messages flow bidirectionally between parent and iframe
20
+ * - Local development mode simulates this architecture without iframes
21
+ */
22
+ import type { GameContextPayload } from './types';
23
+ /**
24
+ * Enumeration of all message types used in the Playcademy messaging system.
25
+ *
26
+ * **Message Flow Patterns**:
27
+ *
28
+ * **Parent → Game (Overworld → Game)**:
29
+ * - INIT: Provides game with authentication token and configuration
30
+ * - TOKEN_REFRESH: Updates game's authentication token before expiry
31
+ * - PAUSE/RESUME: Controls game execution state
32
+ * - FORCE_EXIT: Immediately terminates the game
33
+ * - OVERLAY: Shows/hides UI overlays over the game
34
+ *
35
+ * **Game → Parent (Game → Overworld)**:
36
+ * - READY: Game has loaded and is ready to receive messages
37
+ * - EXIT: Game requests to be closed (user clicked exit, game ended, etc.)
38
+ * - TELEMETRY: Game reports performance metrics (FPS, memory usage, etc.)
39
+ */
40
+ export declare enum MessageEvents {
41
+ /**
42
+ * Initializes the game with authentication context and configuration.
43
+ * Sent immediately after game iframe loads.
44
+ * Payload: { baseUrl: string, token: string, gameId: string }
45
+ */
46
+ INIT = "PLAYCADEMY_INIT",
47
+ /**
48
+ * Updates the game's authentication token before it expires.
49
+ * Sent periodically to maintain valid authentication.
50
+ * Payload: { token: string, exp: number }
51
+ */
52
+ TOKEN_REFRESH = "PLAYCADEMY_TOKEN_REFRESH",
53
+ /**
54
+ * Pauses game execution (e.g., when user switches tabs).
55
+ * Game should pause timers, animations, and user input.
56
+ * Payload: void
57
+ */
58
+ PAUSE = "PLAYCADEMY_PAUSE",
59
+ /**
60
+ * Resumes game execution after being paused.
61
+ * Game should restore timers, animations, and user input.
62
+ * Payload: void
63
+ */
64
+ RESUME = "PLAYCADEMY_RESUME",
65
+ /**
66
+ * Forces immediate game termination (emergency exit).
67
+ * Game should clean up resources and exit immediately.
68
+ * Payload: void
69
+ */
70
+ FORCE_EXIT = "PLAYCADEMY_FORCE_EXIT",
71
+ /**
72
+ * Shows or hides UI overlays over the game.
73
+ * Game may need to pause or adjust rendering accordingly.
74
+ * Payload: boolean (true = show overlay, false = hide overlay)
75
+ */
76
+ OVERLAY = "PLAYCADEMY_OVERLAY",
77
+ /**
78
+ * Game has finished loading and is ready to receive messages.
79
+ * Sent once after game initialization is complete.
80
+ * Payload: void
81
+ */
82
+ READY = "PLAYCADEMY_READY",
83
+ /**
84
+ * Game requests to be closed/exited.
85
+ * Sent when user clicks exit button or game naturally ends.
86
+ * Payload: void
87
+ */
88
+ EXIT = "PLAYCADEMY_EXIT",
89
+ /**
90
+ * Game reports performance telemetry data.
91
+ * Sent periodically for monitoring and analytics.
92
+ * Payload: { fps: number, mem: number }
93
+ */
94
+ TELEMETRY = "PLAYCADEMY_TELEMETRY"
95
+ }
96
+ /**
97
+ * Type definition for message handler functions.
98
+ * These functions are called when a specific message type is received.
99
+ *
100
+ * @template T - The type of payload data the handler expects
101
+ * @param payload - The data sent with the message
102
+ */
103
+ type MessageHandler<T = unknown> = (payload: T) => void;
104
+ /**
105
+ * Type mapping that defines the payload structure for each message type.
106
+ * This ensures type safety when sending and receiving messages.
107
+ *
108
+ * **Usage Examples**:
109
+ * ```typescript
110
+ * // Type-safe message sending
111
+ * messaging.send(MessageEvents.INIT, { baseUrl: '/api', token: 'abc', gameId: '123' })
112
+ *
113
+ * // Type-safe message handling
114
+ * messaging.listen(MessageEvents.TOKEN_REFRESH, ({ token, exp }) => {
115
+ * console.log(`New token expires at: ${new Date(exp)}`)
116
+ * })
117
+ * ```
118
+ */
119
+ export type MessageEventMap = {
120
+ /** Game initialization context with API endpoint, auth token, and game ID */
121
+ [MessageEvents.INIT]: GameContextPayload;
122
+ /** Token refresh data with new token and expiration timestamp */
123
+ [MessageEvents.TOKEN_REFRESH]: {
124
+ token: string;
125
+ exp: number;
126
+ };
127
+ /** Pause message has no payload data */
128
+ [MessageEvents.PAUSE]: void;
129
+ /** Resume message has no payload data */
130
+ [MessageEvents.RESUME]: void;
131
+ /** Force exit message has no payload data */
132
+ [MessageEvents.FORCE_EXIT]: void;
133
+ /** Overlay visibility state (true = show, false = hide) */
134
+ [MessageEvents.OVERLAY]: boolean;
135
+ /** Ready message has no payload data */
136
+ [MessageEvents.READY]: void;
137
+ /** Exit message has no payload data */
138
+ [MessageEvents.EXIT]: void;
139
+ /** Performance telemetry data */
140
+ [MessageEvents.TELEMETRY]: {
141
+ fps: number;
142
+ mem: number;
143
+ };
144
+ };
145
+ /**
146
+ * **PlaycademyMessaging Class**
147
+ *
148
+ * This is the core messaging system that handles all communication in the Playcademy platform.
149
+ * It automatically detects the runtime environment and chooses the appropriate transport method.
150
+ *
151
+ * **Key Features**:
152
+ * 1. **Automatic Transport Selection**: Detects iframe vs local context and uses appropriate method
153
+ * 2. **Type Safety**: Full TypeScript support with payload type checking
154
+ * 3. **Bidirectional Communication**: Handles both parent→game and game→parent messages
155
+ * 4. **Event Cleanup**: Proper listener management to prevent memory leaks
156
+ *
157
+ * **Transport Methods**:
158
+ * - **postMessage**: Used for iframe-to-parent communication (production/development)
159
+ * - **CustomEvent**: Used for local same-context communication (local development)
160
+ *
161
+ * **Runtime Detection Logic**:
162
+ * - If `window.self !== window.top`: We're in an iframe, use postMessage
163
+ * - If `window.self === window.top`: We're in the same context, use CustomEvent
164
+ *
165
+ * **Example Usage**:
166
+ * ```typescript
167
+ * // Send a message (automatically chooses transport)
168
+ * messaging.send(MessageEvents.READY, undefined)
169
+ *
170
+ * // Listen for messages (handles both transports)
171
+ * messaging.listen(MessageEvents.INIT, (payload) => {
172
+ * console.log('Game initialized with:', payload)
173
+ * })
174
+ *
175
+ * // Clean up listeners
176
+ * messaging.unlisten(MessageEvents.INIT, handler)
177
+ * ```
178
+ */
179
+ declare class PlaycademyMessaging {
180
+ /**
181
+ * Internal storage for message listeners.
182
+ *
183
+ * **Structure Explanation**:
184
+ * - Outer Map: MessageEvents → Map of handlers for that event type
185
+ * - Inner Map: MessageHandler → Object containing both listener types
186
+ * - Object: { postMessage: EventListener, customEvent: EventListener }
187
+ *
188
+ * **Why Two Listeners Per Handler?**:
189
+ * Since we don't know at registration time which transport will be used,
190
+ * we register both a postMessage listener and a CustomEvent listener.
191
+ * The appropriate one will be triggered based on the runtime context.
192
+ */
193
+ private listeners;
194
+ /**
195
+ * **Send Message Method**
196
+ *
197
+ * Sends a message using the appropriate transport method based on the runtime context.
198
+ * This is the main public API for sending messages in the Playcademy system.
199
+ *
200
+ * **How It Works**:
201
+ * 1. Analyzes the message type and current runtime context
202
+ * 2. Determines if we're in an iframe and if this message should use postMessage
203
+ * 3. Routes to the appropriate transport method (postMessage or CustomEvent)
204
+ *
205
+ * **Transport Selection Logic**:
206
+ * - **postMessage**: Used when game is in iframe and sending to parent, OR when target window is specified
207
+ * - **CustomEvent**: Used for local/same-context communication
208
+ *
209
+ * **Type Safety**:
210
+ * The generic type parameter `K` ensures that the payload type matches
211
+ * the expected type for the given message event.
212
+ *
213
+ * @template K - The message event type (ensures type safety)
214
+ * @param type - The message event type to send
215
+ * @param payload - The data to send with the message (type-checked)
216
+ * @param options - Optional configuration for message sending
217
+ *
218
+ * @example
219
+ * ```typescript
220
+ * // Send game ready signal (no payload)
221
+ * messaging.send(MessageEvents.READY, undefined)
222
+ *
223
+ * // Send telemetry data (typed payload)
224
+ * messaging.send(MessageEvents.TELEMETRY, { fps: 60, mem: 128 })
225
+ *
226
+ * // Send to specific iframe window (parent to iframe communication)
227
+ * messaging.send(MessageEvents.INIT, { baseUrl, token, gameId }, {
228
+ * target: iframe.contentWindow,
229
+ * origin: '*'
230
+ * })
231
+ *
232
+ * // TypeScript will error if payload type is wrong
233
+ * messaging.send(MessageEvents.INIT, "wrong type") // ❌ Error
234
+ * ```
235
+ */
236
+ send<K extends MessageEvents>(type: K, payload: MessageEventMap[K], options?: {
237
+ target?: Window;
238
+ origin?: string;
239
+ }): void;
240
+ /**
241
+ * **Listen for Messages Method**
242
+ *
243
+ * Registers a message listener that will be called when the specified message type is received.
244
+ * This method automatically handles both postMessage and CustomEvent sources.
245
+ *
246
+ * **Why Register Two Listeners?**:
247
+ * Since we don't know at registration time which transport method will be used to send
248
+ * messages, we register listeners for both possible sources:
249
+ * 1. **postMessage listener**: Handles messages from iframe-to-parent communication
250
+ * 2. **CustomEvent listener**: Handles messages from local same-context communication
251
+ *
252
+ * **Message Processing**:
253
+ * - **postMessage**: Extracts data from `event.data.payload` or `event.data`
254
+ * - **CustomEvent**: Extracts data from `event.detail`
255
+ *
256
+ * **Type Safety**:
257
+ * The handler function receives the correctly typed payload based on the message type.
258
+ *
259
+ * @template K - The message event type (ensures type safety)
260
+ * @param type - The message event type to listen for
261
+ * @param handler - Function to call when the message is received
262
+ *
263
+ * @example
264
+ * ```typescript
265
+ * // Listen for game initialization
266
+ * messaging.listen(MessageEvents.INIT, (payload) => {
267
+ * // payload is automatically typed as GameContextPayload
268
+ * console.log(`Game ${payload.gameId} initialized`)
269
+ * console.log(`API base URL: ${payload.baseUrl}`)
270
+ * })
271
+ *
272
+ * // Listen for token refresh
273
+ * messaging.listen(MessageEvents.TOKEN_REFRESH, ({ token, exp }) => {
274
+ * // payload is automatically typed as { token: string; exp: number }
275
+ * updateAuthToken(token)
276
+ * scheduleTokenRefresh(exp)
277
+ * })
278
+ * ```
279
+ */
280
+ listen<K extends MessageEvents>(type: K, handler: MessageHandler<MessageEventMap[K]>): void;
281
+ /**
282
+ * **Remove Message Listener Method**
283
+ *
284
+ * Removes a previously registered message listener to prevent memory leaks and unwanted callbacks.
285
+ * This method cleans up both the postMessage and CustomEvent listeners that were registered.
286
+ *
287
+ * **Why Clean Up Both Listeners?**:
288
+ * When we registered the listener with `listen()`, we created two browser event listeners:
289
+ * 1. A 'message' event listener for postMessage communication
290
+ * 2. A custom event listener for local CustomEvent communication
291
+ *
292
+ * Both must be removed to prevent memory leaks and ensure the handler is completely unregistered.
293
+ *
294
+ * **Memory Management**:
295
+ * - Removes both event listeners from the browser
296
+ * - Cleans up internal tracking maps
297
+ * - If no more handlers exist for a message type, removes the entire type entry
298
+ *
299
+ * **Safe to Call Multiple Times**:
300
+ * This method is idempotent - calling it multiple times with the same handler is safe.
301
+ *
302
+ * @template K - The message event type (ensures type safety)
303
+ * @param type - The message event type to stop listening for
304
+ * @param handler - The exact handler function that was passed to listen()
305
+ *
306
+ * @example
307
+ * ```typescript
308
+ * // Register a handler
309
+ * const handleInit = (payload) => console.log('Game initialized')
310
+ * messaging.listen(MessageEvents.INIT, handleInit)
311
+ *
312
+ * // Later, remove the handler
313
+ * messaging.unlisten(MessageEvents.INIT, handleInit)
314
+ *
315
+ * // Safe to call multiple times
316
+ * messaging.unlisten(MessageEvents.INIT, handleInit) // No error
317
+ * ```
318
+ */
319
+ unlisten<K extends MessageEvents>(type: K, handler: MessageHandler<MessageEventMap[K]>): void;
320
+ /**
321
+ * **Get Messaging Context Method**
322
+ *
323
+ * Analyzes the current runtime environment and message type to determine the appropriate
324
+ * transport method and configuration for sending messages.
325
+ *
326
+ * **Runtime Environment Detection**:
327
+ * The method detects whether the code is running in an iframe by comparing:
328
+ * - `window.self`: Reference to the current window
329
+ * - `window.top`: Reference to the topmost window in the hierarchy
330
+ *
331
+ * If they're different, we're in an iframe. If they're the same, we're in the top-level window.
332
+ *
333
+ * **Message Direction Analysis**:
334
+ * Different message types flow in different directions:
335
+ * - **Game → Parent**: READY, EXIT, TELEMETRY (use postMessage when in iframe)
336
+ * - **Parent → Game**: INIT, TOKEN_REFRESH, PAUSE, etc. (use CustomEvent in local dev, or postMessage with target)
337
+ *
338
+ * **Cross-Context Communication**:
339
+ * The messaging system supports cross-context targeting through the optional `target` parameter.
340
+ * When a target window is specified, postMessage is used regardless of the current context.
341
+ * This enables parent-to-iframe communication through the unified messaging API.
342
+ *
343
+ * **Transport Selection Logic**:
344
+ * - **postMessage**: Used when game is in iframe AND sending to parent, OR when target window is specified
345
+ * - **CustomEvent**: Used for all other cases (local development, same-context communication)
346
+ *
347
+ * **Security Considerations**:
348
+ * The origin is currently set to '*' for development convenience, but should be
349
+ * configurable for production security.
350
+ *
351
+ * @param eventType - The message event type being sent
352
+ * @returns Configuration object with transport method and target information
353
+ *
354
+ * @example
355
+ * ```typescript
356
+ * // In iframe sending READY to parent
357
+ * const context = getMessagingContext(MessageEvents.READY)
358
+ * // Returns: { shouldUsePostMessage: true, target: window.parent, origin: '*' }
359
+ *
360
+ * // In same context sending INIT
361
+ * const context = getMessagingContext(MessageEvents.INIT)
362
+ * // Returns: { shouldUsePostMessage: false, target: undefined, origin: '*' }
363
+ * ```
364
+ */
365
+ private getMessagingContext;
366
+ /**
367
+ * **Send Via PostMessage Method**
368
+ *
369
+ * Sends a message using the browser's postMessage API for iframe-to-parent communication.
370
+ * This method is used when the game is running in an iframe and needs to communicate
371
+ * with the parent window (the Playcademy shell).
372
+ *
373
+ * **PostMessage Protocol**:
374
+ * The postMessage API is the standard way for iframes to communicate with their parent.
375
+ * It's secure, cross-origin capable, and designed specifically for this use case.
376
+ *
377
+ * **Message Structure**:
378
+ * The method creates a message object with the following structure:
379
+ * - `type`: The message event type (e.g., 'PLAYCADEMY_READY')
380
+ * - Payload data: Either spread into the object or in a `payload` property
381
+ *
382
+ * **Payload Handling**:
383
+ * - **Object payloads**: Spread directly into the message (e.g., { type, token, exp })
384
+ * - **Primitive payloads**: Wrapped in a `payload` property (e.g., { type, payload: true })
385
+ * - **Undefined payloads**: Only the type is sent (e.g., { type })
386
+ *
387
+ * **Security**:
388
+ * The origin parameter controls which domains can receive the message.
389
+ * Currently set to '*' for development, but should be restricted in production.
390
+ *
391
+ * @template K - The message event type (ensures type safety)
392
+ * @param type - The message event type to send
393
+ * @param payload - The data to send with the message
394
+ * @param target - The target window (defaults to parent window)
395
+ * @param origin - The allowed origin for the message (defaults to '*')
396
+ *
397
+ * @example
398
+ * ```typescript
399
+ * // Send ready signal (no payload)
400
+ * sendViaPostMessage(MessageEvents.READY, undefined)
401
+ * // Sends: { type: 'PLAYCADEMY_READY' }
402
+ *
403
+ * // Send telemetry data (object payload)
404
+ * sendViaPostMessage(MessageEvents.TELEMETRY, { fps: 60, mem: 128 })
405
+ * // Sends: { type: 'PLAYCADEMY_TELEMETRY', fps: 60, mem: 128 }
406
+ *
407
+ * // Send overlay state (primitive payload)
408
+ * sendViaPostMessage(MessageEvents.OVERLAY, true)
409
+ * // Sends: { type: 'PLAYCADEMY_OVERLAY', payload: true }
410
+ * ```
411
+ */
412
+ private sendViaPostMessage;
413
+ /**
414
+ * **Send Via CustomEvent Method**
415
+ *
416
+ * Sends a message using the browser's CustomEvent API for local same-context communication.
417
+ * This method is used when both the sender and receiver are in the same window context,
418
+ * typically during local development or when the parent needs to send messages to the game.
419
+ *
420
+ * **CustomEvent Protocol**:
421
+ * CustomEvent is a browser API for creating and dispatching custom events within the same
422
+ * window context. It's simpler than postMessage but only works within the same origin/context.
423
+ *
424
+ * **Event Structure**:
425
+ * - **type**: The event name (e.g., 'PLAYCADEMY_INIT')
426
+ * - **detail**: The payload data attached to the event
427
+ *
428
+ * **When This Is Used**:
429
+ * - Local development when game and shell run in the same context
430
+ * - Parent-to-game communication (INIT, TOKEN_REFRESH, PAUSE, etc.)
431
+ * - Any scenario where postMessage isn't needed
432
+ *
433
+ * **Event Bubbling**:
434
+ * CustomEvents are dispatched on the window object and can be listened to by any
435
+ * code in the same context using `addEventListener(type, handler)`.
436
+ *
437
+ * @template K - The message event type (ensures type safety)
438
+ * @param type - The message event type to send (becomes the event name)
439
+ * @param payload - The data to send with the message (stored in event.detail)
440
+ *
441
+ * @example
442
+ * ```typescript
443
+ * // Send initialization data
444
+ * sendViaCustomEvent(MessageEvents.INIT, {
445
+ * baseUrl: '/api',
446
+ * token: 'abc123',
447
+ * gameId: 'game-456'
448
+ * })
449
+ * // Creates: CustomEvent('PLAYCADEMY_INIT', { detail: { baseUrl, token, gameId } })
450
+ *
451
+ * // Send pause signal
452
+ * sendViaCustomEvent(MessageEvents.PAUSE, undefined)
453
+ * // Creates: CustomEvent('PLAYCADEMY_PAUSE', { detail: undefined })
454
+ *
455
+ * // Listeners can access the data via event.detail:
456
+ * window.addEventListener('PLAYCADEMY_INIT', (event) => {
457
+ * console.log(event.detail.gameId) // 'game-456'
458
+ * })
459
+ * ```
460
+ */
461
+ private sendViaCustomEvent;
462
+ }
463
+ /**
464
+ * **Playcademy Messaging Singleton**
465
+ *
466
+ * This is the main messaging instance used throughout the Playcademy platform.
467
+ * It's exported as a singleton to ensure consistent communication across all parts
468
+ * of the application.
469
+ *
470
+ * **Why a Singleton?**:
471
+ * - Ensures all parts of the app use the same messaging instance
472
+ * - Prevents conflicts between multiple messaging systems
473
+ * - Simplifies the API - no need to pass instances around
474
+ * - Maintains consistent event listener management
475
+ *
476
+ * **Usage in Different Contexts**:
477
+ *
478
+ * **In Games**:
479
+ * ```typescript
480
+ * import { messaging, MessageEvents } from '@playcademy/sdk'
481
+ *
482
+ * // Tell parent we're ready
483
+ * messaging.send(MessageEvents.READY, undefined)
484
+ *
485
+ * // Listen for pause/resume
486
+ * messaging.listen(MessageEvents.PAUSE, () => game.pause())
487
+ * messaging.listen(MessageEvents.RESUME, () => game.resume())
488
+ * ```
489
+ *
490
+ * **In Parent Shell**:
491
+ * ```typescript
492
+ * import { messaging, MessageEvents } from '@playcademy/sdk'
493
+ *
494
+ * // Send initialization data to game
495
+ * messaging.send(MessageEvents.INIT, { baseUrl, token, gameId })
496
+ *
497
+ * // Listen for game events
498
+ * messaging.listen(MessageEvents.EXIT, () => closeGame())
499
+ * messaging.listen(MessageEvents.READY, () => showGame())
500
+ * ```
501
+ *
502
+ * **Automatic Transport Selection**:
503
+ * The messaging system automatically chooses the right transport method:
504
+ * - Uses postMessage when game is in iframe sending to parent
505
+ * - Uses CustomEvent for local development and parent-to-game communication
506
+ *
507
+ * **Type Safety**:
508
+ * All message sending and receiving is fully type-safe with TypeScript.
509
+ */
510
+ export declare const messaging: PlaycademyMessaging;
511
+ export {};
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { User, InventoryItemWithReward, Game, DeveloperKey, DeveloperStatusResponse, MapElement, Reward, InsertReward, ManifestV1, UpdateReward } from '@playcademy/data/schemas';
1
+ import type { User, InventoryItemWithItem, Game, DeveloperKey, DeveloperStatusResponse, MapElement, Item, InsertItem, ManifestV1, UpdateItem, Currency, InsertCurrency, UpdateCurrency, ShopListing, InsertShopListing, UpdateShopListing } from '@playcademy/types';
2
2
  export interface ClientConfig {
3
3
  baseUrl: string;
4
4
  token?: string;
@@ -9,7 +9,7 @@ export interface ClientEvents {
9
9
  token: string | null;
10
10
  };
11
11
  inventoryChange: {
12
- rewardId: string;
12
+ itemId: string;
13
13
  delta: number;
14
14
  newTotal: number;
15
15
  };
@@ -40,4 +40,32 @@ export type StartSessionResponse = {
40
40
  export type InventoryMutationResponse = {
41
41
  newTotal: number;
42
42
  };
43
- export type { User, InventoryItemWithReward, Game, ManifestV1, DeveloperKey, DeveloperStatusResponse, MapElement, Reward, InsertReward, UpdateReward, };
43
+ export interface ShopDisplayItem extends Item {
44
+ listingId: string;
45
+ shopPrice: number;
46
+ currencyId: string;
47
+ currencySymbol?: string | null;
48
+ currencyDisplayName?: string | null;
49
+ currencyImageUrl?: string | null;
50
+ stock?: number | null;
51
+ sellBackPercentage?: number | null;
52
+ }
53
+ export interface UserCurrencyInfo {
54
+ id: string;
55
+ balance: number;
56
+ symbol?: string | null;
57
+ imageUrl?: string | null;
58
+ isPrimary: boolean;
59
+ }
60
+ export interface CurrencyInfo {
61
+ id: string;
62
+ symbol?: string | null;
63
+ imageUrl?: string | null;
64
+ displayName?: string | null;
65
+ isPrimary: boolean;
66
+ }
67
+ export interface ShopViewResponse {
68
+ shopItems: ShopDisplayItem[];
69
+ currencies: CurrencyInfo[];
70
+ }
71
+ export type { User, InventoryItemWithItem, Game, ManifestV1, DeveloperKey, DeveloperStatusResponse, MapElement, Item, InsertItem, UpdateItem, Currency, InsertCurrency, UpdateCurrency, ShopListing, InsertShopListing, UpdateShopListing, };
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@playcademy/sdk",
3
3
  "type": "module",
4
- "version": "0.0.1-beta.2",
4
+ "version": "0.0.1-beta.20",
5
5
  "exports": {
6
6
  ".": {
7
- "import": "./dist/runtime.js",
8
- "require": "./dist/runtime.js",
9
- "types": "./dist/runtime.d.ts"
7
+ "import": "./dist/index.js",
8
+ "require": "./dist/index.js",
9
+ "types": "./dist/index.d.ts"
10
10
  },
11
11
  "./types": {
12
12
  "import": "./dist/types.js",
@@ -14,24 +14,25 @@
14
14
  "types": "./dist/types.d.ts"
15
15
  }
16
16
  },
17
- "main": "dist/runtime.js",
18
- "module": "dist/runtime.js",
19
17
  "files": [
20
18
  "dist"
21
19
  ],
20
+ "main": "dist/index.js",
21
+ "module": "dist/index.js",
22
22
  "scripts": {
23
23
  "build": "bun build.js",
24
- "pub": "bun run build && bunx bumpp --no-tag --no-push && bun publish --access public"
25
- },
26
- "dependencies": {
27
- "@playcademy/data": "0.0.1"
24
+ "pub": "bun run build && bun run bump && bun publish --access public",
25
+ "bump": "bunx bumpp --no-tag --no-push -c \"chore(@playcademy/sdk): release v%s\""
28
26
  },
29
27
  "devDependencies": {
28
+ "@playcademy/types": "^0.0.1-beta.6",
30
29
  "@types/bun": "latest",
31
30
  "typescript": "^5.0.0",
32
31
  "yocto-spinner": "^0.2.1"
33
32
  },
34
33
  "peerDependencies": {
34
+ "drizzle-orm": "^0.42.0",
35
+ "@playcademy/types": "latest",
35
36
  "typescript": "^5"
36
37
  }
37
38
  }
package/dist/bus.d.ts DELETED
@@ -1,37 +0,0 @@
1
- import type { GameContextPayload } from './types';
2
- export declare enum BusEvents {
3
- INIT = "PLAYCADEMY_INIT",
4
- TOKEN_REFRESH = "PLAYCADEMY_TOKEN_REFRESH",
5
- PAUSE = "PLAYCADEMY_PAUSE",
6
- RESUME = "PLAYCADEMY_RESUME",
7
- FORCE_EXIT = "PLAYCADEMY_FORCE_EXIT",
8
- OVERLAY = "PLAYCADEMY_OVERLAY",
9
- READY = "PLAYCADEMY_READY",
10
- EXIT = "PLAYCADEMY_EXIT",
11
- TELEMETRY = "PLAYCADEMY_TELEMETRY"
12
- }
13
- type BusHandler<T = unknown> = (payload: T) => void;
14
- export type BusEventMap = {
15
- [BusEvents.INIT]: GameContextPayload;
16
- [BusEvents.TOKEN_REFRESH]: {
17
- token: string;
18
- exp: number;
19
- };
20
- [BusEvents.PAUSE]: void;
21
- [BusEvents.RESUME]: void;
22
- [BusEvents.FORCE_EXIT]: void;
23
- [BusEvents.OVERLAY]: boolean;
24
- [BusEvents.READY]: void;
25
- [BusEvents.EXIT]: void;
26
- [BusEvents.TELEMETRY]: {
27
- fps: number;
28
- mem: number;
29
- };
30
- };
31
- interface Bus {
32
- emit<K extends BusEvents>(type: K, payload: BusEventMap[K]): void;
33
- on<K extends BusEvents>(type: K, handler: BusHandler<BusEventMap[K]>): void;
34
- off<K extends BusEvents>(type: K, handler: BusHandler<BusEventMap[K]>): void;
35
- }
36
- export declare const bus: Bus;
37
- export {};
package/dist/runtime.d.ts DELETED
@@ -1,7 +0,0 @@
1
- import { PlaycademyClient } from './core/client';
2
- /** For Node, SSR, dashboards, etc. */
3
- export { PlaycademyClient } from './core/client';
4
- /** Factory for code running *inside* the CADEMY loader (games) */
5
- export declare function initFromWindow(): Promise<PlaycademyClient>;
6
- export { bus, BusEvents } from './bus';
7
- export { PlaycademyError } from './core/errors';