@playcademy/sandbox 0.3.6 → 0.3.8

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,54 @@
1
+ /**
2
+ * Sandbox API Infrastructure
3
+ *
4
+ * Exports the handle and handleStream functions for use in Hono routes.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * // In route setup
9
+ * import { currencies } from '@playcademy/api-core/controllers'
10
+ * import { handle } from '../infrastructure/api'
11
+ *
12
+ * router.get('/currencies', handle(currencies.list))
13
+ * router.post('/currencies', handle(currencies.create, { status: 201 }))
14
+ * ```
15
+ */
16
+ import { createHandlers } from '@playcademy/api-hono';
17
+ /**
18
+ * Wrap a controller function into a Hono request handler.
19
+ *
20
+ * IMPORTANT: This returns a function that looks up handlers at REQUEST time,
21
+ * not at route registration time. This is critical because route modules are
22
+ * cached by the module system, but we need each sandbox to use its own handlers.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * import { currencies } from '@playcademy/api-core/controllers'
27
+ * import { handle } from '../infrastructure/api'
28
+ *
29
+ * router.get('/currencies', handle(currencies.list))
30
+ * router.post('/currencies', handle(currencies.create, { status: 201 }))
31
+ * ```
32
+ */
33
+ export declare function handle(...args: Parameters<ReturnType<typeof createHandlers>[0]>): ReturnType<ReturnType<typeof createHandlers>[0]>;
34
+ /**
35
+ * Wrap a streaming controller function into a Hono request handler.
36
+ *
37
+ * IMPORTANT: This returns a function that looks up handlers at REQUEST time,
38
+ * not at route registration time. This is critical because route modules are
39
+ * cached by the module system, but we need each sandbox to use its own handlers.
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * import { deploy } from '@playcademy/api-core/controllers'
44
+ * import { handleStream } from '../infrastructure/api'
45
+ *
46
+ * router.post('/games/:slug/deploy', handleStream(deploy.deploy))
47
+ * ```
48
+ */
49
+ export declare function handleStream(...args: Parameters<ReturnType<typeof createHandlers>[1]>): ReturnType<ReturnType<typeof createHandlers>[1]>;
50
+ /**
51
+ * Reset the handlers (for testing or hot reload).
52
+ */
53
+ export declare function resetHandlers(): void;
54
+ export { createSandboxContext, getSandboxContext, resetSandboxContext } from './context';
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Sandbox Auth Provider
3
+ *
4
+ * Simplified auth for local development. No real JWT signing/verification -
5
+ * uses demo tokens and simple base64 encoding.
6
+ *
7
+ * @module infrastructure/api/providers/auth
8
+ */
9
+ import type { AuthProvider } from '@playcademy/api-core/providers';
10
+ /**
11
+ * Create a sandbox auth provider.
12
+ *
13
+ * Uses demo tokens and simple encoding instead of real JWT signing.
14
+ */
15
+ export declare function createSandboxAuthProvider(): AuthProvider;
16
+ /**
17
+ * Get a demo user for sandbox auth.
18
+ */
19
+ export declare function getDemoUser(role?: 'admin' | 'developer' | 'player'): {
20
+ readonly id: "00000000-0000-0000-0000-000000000003";
21
+ readonly name: "Admin User";
22
+ readonly username: "admin_user";
23
+ readonly email: "admin@playcademy.com";
24
+ readonly emailVerified: true;
25
+ readonly image: null;
26
+ readonly role: "admin";
27
+ readonly developerStatus: "approved";
28
+ readonly createdAt: Date;
29
+ readonly updatedAt: Date;
30
+ } | {
31
+ readonly id: "00000000-0000-0000-0000-000000000001";
32
+ readonly name: "Player User";
33
+ readonly username: "player_user";
34
+ readonly email: "player@playcademy.com";
35
+ readonly emailVerified: true;
36
+ readonly image: null;
37
+ readonly role: "player";
38
+ readonly developerStatus: "none";
39
+ readonly createdAt: Date;
40
+ readonly updatedAt: Date;
41
+ } | {
42
+ readonly id: "00000000-0000-0000-0000-000000000002";
43
+ readonly name: "Developer User";
44
+ readonly username: "developer_user";
45
+ readonly email: "developer@playcademy.com";
46
+ readonly emailVerified: true;
47
+ readonly image: null;
48
+ readonly role: "developer";
49
+ readonly developerStatus: "approved";
50
+ readonly createdAt: Date;
51
+ readonly updatedAt: Date;
52
+ };
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Sandbox Cache Provider
3
+ *
4
+ * In-memory cache for local development. Simple TTL-based expiration.
5
+ *
6
+ * @module infrastructure/api/providers/cache
7
+ */
8
+ import type { CacheProvider } from '@playcademy/api-core/providers';
9
+ /**
10
+ * Create a sandbox cache provider.
11
+ *
12
+ * Uses in-memory storage with TTL support.
13
+ */
14
+ export declare function createSandboxCacheProvider(): CacheProvider;
15
+ /**
16
+ * Clear all sandbox cache (useful for testing).
17
+ */
18
+ export declare function clearSandboxCache(): void;
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Sandbox Provider Implementations
3
+ *
4
+ * In-memory implementations of api-core provider interfaces for local development.
5
+ *
6
+ * @module infrastructure/api/providers
7
+ */
8
+ export { createSandboxAuthProvider, getDemoUser } from './auth.provider';
9
+ export { createSandboxCacheProvider, clearSandboxCache } from './cache.provider';
10
+ export { createSandboxSecretsProvider, clearSandboxSecrets } from './secrets.provider';
11
+ export { createSandboxStorageProvider, clearSandboxStorage } from './storage.provider';
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Sandbox Secrets Provider
3
+ *
4
+ * In-memory secrets storage for local development. Secrets are not persisted
5
+ * across restarts - this is intentional for sandbox simplicity.
6
+ *
7
+ * @module infrastructure/api/providers/secrets
8
+ */
9
+ import type { SecretsProvider } from '@playcademy/api-core/providers';
10
+ /**
11
+ * Create a sandbox secrets provider.
12
+ *
13
+ * Uses in-memory storage. Secrets are lost on restart.
14
+ */
15
+ export declare function createSandboxSecretsProvider(): SecretsProvider;
16
+ /**
17
+ * Clear all sandbox secrets (useful for testing).
18
+ */
19
+ export declare function clearSandboxSecrets(): void;
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Sandbox Storage Provider
3
+ *
4
+ * In-memory storage for local development. File uploads are not persisted
5
+ * across restarts - this is intentional for sandbox simplicity.
6
+ *
7
+ * @module infrastructure/api/providers/storage
8
+ */
9
+ import type { StorageProvider } from '@playcademy/api-core/providers';
10
+ /**
11
+ * Create a sandbox storage provider.
12
+ *
13
+ * Uses in-memory storage. Data is lost on restart.
14
+ */
15
+ export declare function createSandboxStorageProvider(): StorageProvider;
16
+ /**
17
+ * Clear all sandbox storage (useful for testing).
18
+ */
19
+ export declare function clearSandboxStorage(): void;
@@ -4,7 +4,8 @@
4
4
  * Pure mock data generators for local development.
5
5
  * Used by route handlers when mock mode is enabled.
6
6
  */
7
- import type { AuthenticatedUser, GameUser, TimebackStudentProfile, User, UserEnrollment, UserTimebackData } from '@playcademy/data/types';
7
+ import type { User } from '@playcademy/sdk/types';
8
+ import type { AuthenticatedUser, GameUser, TimebackStudentProfile, UserEnrollment, UserTimebackData } from '@playcademy/types/user';
8
9
  import type { DatabaseInstance } from '../types';
9
10
  /**
10
11
  * Check if TimeBack should return mock data instead of calling real APIs.
@@ -24,6 +25,11 @@ export declare function getMockEnrollments(db: DatabaseInstance): Promise<UserEn
24
25
  * Generate complete mock TimeBack data for a user.
25
26
  */
26
27
  export declare function getMockTimebackData(db: DatabaseInstance, timebackId: string, gameId?: string): Promise<UserTimebackData>;
28
+ /**
29
+ * Get mock timeback user data for the current sandbox user.
30
+ * Uses the configured timebackId from sandbox config.
31
+ */
32
+ export declare function getMockTimebackUser(db: DatabaseInstance, gameId?: string): Promise<UserTimebackData>;
27
33
  /**
28
34
  * Build a complete user response with mock timeback data.
29
35
  * Used to bypass api-core when in mock mode (avoids real API calls).
package/dist/server.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as _hono_node_server from '@hono/node-server';
2
- import { TimebackOrgType, TimebackUserRole } from '@playcademy/data/types';
2
+ import { TimebackOrgType, TimebackUserRole } from '@playcademy/types/user';
3
3
 
4
4
  /**
5
5
  * Configuration Type Definitions
@@ -288,7 +288,7 @@ declare const version: string;
288
288
  */
289
289
  declare function startServer(port: number, project?: ProjectInfo, options?: Omit<ServerOptions, 'port' | 'project'>): Promise<{
290
290
  main: _hono_node_server.ServerType;
291
- timebackMode: "local" | "remote" | "mock" | null;
291
+ timebackMode: "local" | "mock" | "remote" | null;
292
292
  setRole: (role: TimebackUserRole) => void;
293
293
  stop: () => Promise<void>;
294
294
  }>;