@playcademy/sandbox 0.1.9 → 0.1.10

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.
Files changed (41) hide show
  1. package/README.md +15 -15
  2. package/dist/cli.d.ts +0 -1
  3. package/dist/cli.js +103711 -98870
  4. package/dist/config.d.ts +43 -0
  5. package/dist/server.d.ts +288 -5
  6. package/dist/server.js +102023 -97211
  7. package/package.json +9 -11
  8. package/dist/config/index.d.ts +0 -10
  9. package/dist/config/mutators.d.ts +0 -4
  10. package/dist/config/timeback.d.ts +0 -10
  11. package/dist/config/types.d.ts +0 -23
  12. package/dist/constants.d.ts +0 -171
  13. package/dist/database/index.d.ts +0 -6
  14. package/dist/database/path-manager.d.ts +0 -26
  15. package/dist/database/seed.d.ts +0 -34
  16. package/dist/lib/auth.d.ts +0 -10
  17. package/dist/lib/error-handler.d.ts +0 -22
  18. package/dist/lib/realtime.d.ts +0 -17
  19. package/dist/routes/achievements.d.ts +0 -3
  20. package/dist/routes/character.d.ts +0 -3
  21. package/dist/routes/currencies.d.ts +0 -3
  22. package/dist/routes/dev.d.ts +0 -3
  23. package/dist/routes/games.d.ts +0 -3
  24. package/dist/routes/health.d.ts +0 -2
  25. package/dist/routes/index.d.ts +0 -20
  26. package/dist/routes/inventory.d.ts +0 -3
  27. package/dist/routes/items.d.ts +0 -3
  28. package/dist/routes/leaderboard.d.ts +0 -3
  29. package/dist/routes/levels.d.ts +0 -3
  30. package/dist/routes/lti.d.ts +0 -3
  31. package/dist/routes/manifest.d.ts +0 -3
  32. package/dist/routes/maps.d.ts +0 -4
  33. package/dist/routes/notifications.d.ts +0 -3
  34. package/dist/routes/realtime.d.ts +0 -3
  35. package/dist/routes/shop-listings.d.ts +0 -3
  36. package/dist/routes/shop.d.ts +0 -3
  37. package/dist/routes/sprite.d.ts +0 -3
  38. package/dist/routes/timeback.d.ts +0 -3
  39. package/dist/routes/users.d.ts +0 -3
  40. package/dist/types.d.ts +0 -29
  41. /package/dist/{config/index.js → config.js} +0 -0
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Configuration Type Definitions
3
+ */
4
+ type TimebackMode = 'local' | 'remote' | 'disabled';
5
+ interface TimebackConfig {
6
+ mode: TimebackMode;
7
+ onerosterApiUrl?: string;
8
+ caliperApiUrl?: string;
9
+ clientId?: string;
10
+ clientSecret?: string;
11
+ authUrl?: string;
12
+ courseId?: string;
13
+ studentId?: string;
14
+ }
15
+ interface AuthConfig {
16
+ betterAuthSecret: string;
17
+ gameJwtSecret: string;
18
+ }
19
+ interface SandboxConfig {
20
+ embedded: boolean;
21
+ auth: AuthConfig;
22
+ timeback: TimebackConfig;
23
+ }
24
+
25
+ /**
26
+ * Configuration Mutation Functions
27
+ */
28
+ declare function setEmbeddedMode(embedded: boolean): void;
29
+
30
+ /**
31
+ * TimeBack Configuration Helpers
32
+ */
33
+
34
+ declare function isTimebackEnabled(): boolean;
35
+ declare function hasTimebackCredentials(): boolean;
36
+ declare function hasTimebackFullConfig(): boolean;
37
+ declare function requireTimebackCredentials(): TimebackConfig;
38
+ declare function configureTimeback(options: Partial<TimebackConfig>): void;
39
+
40
+ declare const config: SandboxConfig;
41
+
42
+ export { config, configureTimeback, hasTimebackCredentials, hasTimebackFullConfig, isTimebackEnabled, requireTimebackCredentials, setEmbeddedMode };
43
+ export type { AuthConfig, SandboxConfig, TimebackConfig, TimebackMode };
package/dist/server.d.ts CHANGED
@@ -1,7 +1,290 @@
1
- import type { ProjectInfo, ServerOptions } from './types';
2
- export declare function startServer(port: number, project?: ProjectInfo, options?: Omit<ServerOptions, 'port' | 'project'>): Promise<{
3
- main: import("@hono/node-server").ServerType;
4
- realtime: Bun.Server<import("@playcademy/realtime/server").WebSocketData> | import("@playcademy/realtime/server/sandbox").SandboxRealtimeServer | null;
1
+ import * as _playcademy_realtime_server_sandbox from '@playcademy/realtime/server/sandbox';
2
+ import * as _playcademy_realtime_server from '@playcademy/realtime/server';
3
+ import * as _hono_node_server from '@hono/node-server';
4
+
5
+ /**
6
+ * Configuration Type Definitions
7
+ */
8
+ type TimebackMode = 'local' | 'remote' | 'disabled';
9
+ interface TimebackConfig {
10
+ mode: TimebackMode;
11
+ onerosterApiUrl?: string;
12
+ caliperApiUrl?: string;
13
+ clientId?: string;
14
+ clientSecret?: string;
15
+ authUrl?: string;
16
+ courseId?: string;
17
+ studentId?: string;
18
+ }
19
+
20
+ /**
21
+ * Project information types
22
+ */
23
+ /**
24
+ * Information about the current game project
25
+ * Used for seeding and display
26
+ */
27
+ interface ProjectInfo {
28
+ slug: string;
29
+ displayName: string;
30
+ version: string;
31
+ description?: string;
32
+ }
33
+
34
+ /**
35
+ * Server configuration types
36
+ */
37
+
38
+ /**
39
+ * Logger interface for embedding the sandbox in other tools (e.g., Vite plugin)
40
+ *
41
+ * Allows external tools to capture and display sandbox logs in their own format.
42
+ */
43
+ interface PluginLogger {
44
+ /** Log informational messages */
45
+ info: (msg: string) => void;
46
+ /** Log warning messages */
47
+ warn: (msg: string) => void;
48
+ /** Log error messages */
49
+ error: (msg: string) => void;
50
+ }
51
+ /**
52
+ * Configuration options for starting the Playcademy sandbox server
53
+ *
54
+ * The sandbox provides a local development environment that simulates the
55
+ * Playcademy platform, including API endpoints, authentication, and database.
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * import { startServer } from '@playcademy/sandbox'
60
+ *
61
+ * await startServer({
62
+ * port: 8788,
63
+ * seed: true,
64
+ * logLevel: 'debug'
65
+ * })
66
+ * ```
67
+ */
68
+ interface ServerOptions {
69
+ /**
70
+ * Port number for the sandbox server.
71
+ *
72
+ * The sandbox will listen on this port for HTTP requests.
73
+ *
74
+ * @example
75
+ * ```ts
76
+ * {
77
+ * port: 8788
78
+ * }
79
+ * ```
80
+ */
81
+ port: number;
82
+ /**
83
+ * Project information for context.
84
+ *
85
+ * Provides metadata about the game being developed. Usually provided
86
+ * automatically by the Vite plugin.
87
+ */
88
+ project?: ProjectInfo;
89
+ /**
90
+ * Enable verbose logging.
91
+ *
92
+ * Shows detailed information about all operations. Equivalent to
93
+ * setting `logLevel: 'debug'`.
94
+ *
95
+ * @default false
96
+ * @example
97
+ * ```ts
98
+ * {
99
+ * verbose: true // Show all debug output
100
+ * }
101
+ * ```
102
+ */
103
+ verbose?: boolean;
104
+ /**
105
+ * Run in quiet mode (minimal logging).
106
+ *
107
+ * Suppresses most log output except errors. Useful when embedding
108
+ * the sandbox in other tools.
109
+ *
110
+ * @default false
111
+ * @example
112
+ * ```ts
113
+ * {
114
+ * quiet: true // Suppress most logs
115
+ * }
116
+ * ```
117
+ */
118
+ quiet?: boolean;
119
+ /**
120
+ * Seed the database with demo data on startup.
121
+ *
122
+ * Creates demo users, games, achievements, and other platform data
123
+ * for testing. Recommended for development.
124
+ *
125
+ * @default true
126
+ * @example
127
+ * ```ts
128
+ * {
129
+ * seed: false // Don't seed demo data
130
+ * }
131
+ * ```
132
+ */
133
+ seed?: boolean;
134
+ /**
135
+ * Use an in-memory database instead of a file.
136
+ *
137
+ * The database only exists in RAM and is lost when the server stops.
138
+ * Faster but non-persistent. Useful for testing.
139
+ *
140
+ * @default false
141
+ * @example
142
+ * ```ts
143
+ * {
144
+ * memoryOnly: true // Database in RAM only
145
+ * }
146
+ * ```
147
+ */
148
+ memoryOnly?: boolean;
149
+ /**
150
+ * Recreate the database on each server start.
151
+ *
152
+ * Drops and recreates the database with fresh seed data every time
153
+ * the server starts. Ensures a clean state for development.
154
+ *
155
+ * **Warning**: All existing data will be lost on each restart.
156
+ *
157
+ * @default false
158
+ * @example
159
+ * ```ts
160
+ * {
161
+ * recreateDb: true // Fresh database every restart
162
+ * }
163
+ * ```
164
+ */
165
+ recreateDb?: boolean;
166
+ /**
167
+ * Custom path for the database file.
168
+ *
169
+ * Specifies where the SQLite database file should be stored.
170
+ * If not provided, defaults to a path based on node_modules location.
171
+ *
172
+ * Special value `':memory:'` creates an in-memory database
173
+ * (equivalent to `memoryOnly: true`).
174
+ *
175
+ * @example
176
+ * ```ts
177
+ * {
178
+ * databasePath: './my-sandbox.db'
179
+ * }
180
+ * ```
181
+ *
182
+ * @example
183
+ * ```ts
184
+ * {
185
+ * databasePath: ':memory:' // In-memory database
186
+ * }
187
+ * ```
188
+ */
189
+ databasePath?: string;
190
+ /**
191
+ * Log level for the sandbox server.
192
+ *
193
+ * Controls the verbosity of server logs:
194
+ * - `'debug'`: Very detailed logs (all operations)
195
+ * - `'info'`: Standard operational logs (default)
196
+ * - `'warn'`: Warnings only
197
+ * - `'error'`: Errors only
198
+ *
199
+ * @default 'info'
200
+ * @example
201
+ * ```ts
202
+ * {
203
+ * logLevel: 'debug' // Show all debug information
204
+ * }
205
+ * ```
206
+ */
207
+ logLevel?: 'debug' | 'info' | 'warn' | 'error';
208
+ /**
209
+ * Realtime/WebSocket server configuration.
210
+ *
211
+ * The realtime server provides WebSocket support for live updates,
212
+ * multiplayer features, and other real-time functionality.
213
+ *
214
+ * @example
215
+ * ```ts
216
+ * {
217
+ * realtime: {
218
+ * enabled: true,
219
+ * port: 8789 // Run WebSocket server on port 8789
220
+ * }
221
+ * }
222
+ * ```
223
+ */
224
+ realtime?: {
225
+ /**
226
+ * Enable the realtime/WebSocket server.
227
+ * @default true
228
+ */
229
+ enabled?: boolean;
230
+ /**
231
+ * Port for the WebSocket server.
232
+ *
233
+ * By default, uses the HTTP port + 1 (e.g., if HTTP is 8788,
234
+ * WebSocket will be 8789).
235
+ */
236
+ port?: number;
237
+ };
238
+ /**
239
+ * Timeback (time travel) integration configuration.
240
+ *
241
+ * Timeback allows you to simulate time-based game mechanics during
242
+ * development (e.g., daily rewards, energy refills).
243
+ *
244
+ * @example
245
+ * ```ts
246
+ * {
247
+ * timeback: {
248
+ * enabled: true,
249
+ * port: 3210
250
+ * }
251
+ * }
252
+ * ```
253
+ */
254
+ timeback?: Partial<TimebackConfig>;
255
+ /**
256
+ * Custom logger for capturing sandbox output.
257
+ *
258
+ * Allows external tools (like the Vite plugin) to capture and display
259
+ * sandbox logs in their own format. If not provided, logs go to console.
260
+ *
261
+ * @example
262
+ * ```ts
263
+ * {
264
+ * logger: {
265
+ * info: (msg) => console.log('[SANDBOX]', msg),
266
+ * warn: (msg) => console.warn('[SANDBOX]', msg),
267
+ * error: (msg) => console.error('[SANDBOX]', msg)
268
+ * }
269
+ * }
270
+ * ```
271
+ */
272
+ logger?: PluginLogger;
273
+ }
274
+
275
+ declare const version: string;
276
+ /**
277
+ * Start the sandbox server
278
+ *
279
+ * @param port - Port to listen on
280
+ * @param project - Optional project information for seeding
281
+ * @param options - Server configuration options
282
+ * @returns Server instance with stop method
283
+ */
284
+ declare function startServer(port: number, project?: ProjectInfo, options?: Omit<ServerOptions, 'port' | 'project'>): Promise<{
285
+ main: _hono_node_server.ServerType;
286
+ realtime: Bun.Server<_playcademy_realtime_server.WebSocketData> | _playcademy_realtime_server_sandbox.SandboxRealtimeServer | null;
5
287
  stop: () => void;
6
288
  }>;
7
- export declare const version: string;
289
+
290
+ export { startServer, version };