@playcademy/sandbox 0.1.0-beta.9 → 0.1.1

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,10 @@
1
+ import type { SandboxConfig } from './types';
2
+ /**
3
+ * Sandbox Configuration
4
+ *
5
+ * Loads configuration from environment variables.
6
+ */
7
+ export type { AuthConfig, SandboxConfig, TimebackConfig, TimebackMode } from './types';
8
+ export { setEmbeddedMode } from './mutators';
9
+ export { configureTimeback, hasTimebackCredentials, hasTimebackFullConfig, isTimebackEnabled, requireTimebackCredentials, } from './timeback';
10
+ export declare const config: SandboxConfig;
@@ -0,0 +1,150 @@
1
+ import { createRequire } from "node:module";
2
+ var __create = Object.create;
3
+ var __getProtoOf = Object.getPrototypeOf;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __toESM = (mod, isNodeMode, target) => {
8
+ target = mod != null ? __create(__getProtoOf(mod)) : {};
9
+ const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
10
+ for (let key of __getOwnPropNames(mod))
11
+ if (!__hasOwnProp.call(to, key))
12
+ __defProp(to, key, {
13
+ get: () => mod[key],
14
+ enumerable: true
15
+ });
16
+ return to;
17
+ };
18
+ var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
19
+ var __export = (target, all) => {
20
+ for (var name in all)
21
+ __defProp(target, name, {
22
+ get: all[name],
23
+ enumerable: true,
24
+ configurable: true,
25
+ set: (newValue) => all[name] = () => newValue
26
+ });
27
+ };
28
+ var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
29
+ var __require = /* @__PURE__ */ createRequire(import.meta.url);
30
+
31
+ // src/config/timeback.ts
32
+ function getTimebackMode() {
33
+ const explicit = process.env.TIMEBACK_MODE;
34
+ if (explicit === "local" || explicit === "remote" || explicit === "disabled")
35
+ return explicit;
36
+ if (process.env.TIMEBACK_LOCAL === "true")
37
+ return "local";
38
+ if (process.env.TIMEBACK_API_CLIENT_ID)
39
+ return "remote";
40
+ return "disabled";
41
+ }
42
+ function isTimebackEnabled() {
43
+ return config.timeback.mode !== "disabled";
44
+ }
45
+ function hasTimebackCredentials() {
46
+ const { mode, onerosterApiUrl, caliperApiUrl, clientId, clientSecret, authUrl } = config.timeback;
47
+ if (mode === "local") {
48
+ return !!(onerosterApiUrl && caliperApiUrl);
49
+ }
50
+ if (mode === "remote") {
51
+ return !!(onerosterApiUrl && clientId && clientSecret && authUrl);
52
+ }
53
+ return false;
54
+ }
55
+ function hasTimebackFullConfig() {
56
+ return hasTimebackCredentials() && !!(config.timeback.courseId && config.timeback.studentId);
57
+ }
58
+ function requireTimebackCredentials() {
59
+ if (hasTimebackCredentials())
60
+ return config.timeback;
61
+ const { mode, onerosterApiUrl, caliperApiUrl, clientId, clientSecret, authUrl } = config.timeback;
62
+ if (mode === "local") {
63
+ const missing2 = [];
64
+ if (!onerosterApiUrl)
65
+ missing2.push("TIMEBACK_ONEROSTER_API_URL");
66
+ if (!caliperApiUrl)
67
+ missing2.push("TIMEBACK_CALIPER_API_URL");
68
+ throw new Error(`TimeBack local mode missing: ${missing2.join(", ")}`);
69
+ }
70
+ const missing = [];
71
+ if (!onerosterApiUrl)
72
+ missing.push("TIMEBACK_ONEROSTER_API_URL");
73
+ if (!clientId)
74
+ missing.push("TIMEBACK_API_CLIENT_ID");
75
+ if (!clientSecret)
76
+ missing.push("TIMEBACK_API_CLIENT_SECRET");
77
+ if (!authUrl)
78
+ missing.push("TIMEBACK_API_AUTH_URL");
79
+ throw new Error(`TimeBack credentials missing: ${missing.join(", ")}`);
80
+ }
81
+ function configureTimeback(options) {
82
+ if (options.mode) {
83
+ config.timeback.mode = options.mode;
84
+ process.env.TIMEBACK_MODE = options.mode;
85
+ }
86
+ if (options.onerosterApiUrl) {
87
+ config.timeback.onerosterApiUrl = options.onerosterApiUrl;
88
+ process.env.TIMEBACK_ONEROSTER_API_URL = options.onerosterApiUrl;
89
+ }
90
+ if (options.caliperApiUrl) {
91
+ config.timeback.caliperApiUrl = options.caliperApiUrl;
92
+ process.env.TIMEBACK_CALIPER_API_URL = options.caliperApiUrl;
93
+ }
94
+ if (options.clientId) {
95
+ config.timeback.clientId = options.clientId;
96
+ process.env.TIMEBACK_API_CLIENT_ID = options.clientId;
97
+ }
98
+ if (options.clientSecret) {
99
+ config.timeback.clientSecret = options.clientSecret;
100
+ process.env.TIMEBACK_API_CLIENT_SECRET = options.clientSecret;
101
+ }
102
+ if (options.authUrl) {
103
+ config.timeback.authUrl = options.authUrl;
104
+ process.env.TIMEBACK_API_AUTH_URL = options.authUrl;
105
+ }
106
+ if (options.courseId) {
107
+ config.timeback.courseId = options.courseId;
108
+ process.env.SANDBOX_TIMEBACK_COURSE_ID = options.courseId;
109
+ }
110
+ if (options.studentId) {
111
+ config.timeback.studentId = options.studentId;
112
+ process.env.SANDBOX_TIMEBACK_STUDENT_ID = options.studentId;
113
+ }
114
+ }
115
+
116
+ // src/config/mutators.ts
117
+ function setEmbeddedMode(embedded) {
118
+ config.embedded = embedded;
119
+ process.env.PLAYCADEMY_EMBEDDED = embedded ? "1" : undefined;
120
+ }
121
+
122
+ // src/config/index.ts
123
+ var config = {
124
+ embedded: process.env.PLAYCADEMY_EMBEDDED === "1",
125
+ auth: {
126
+ betterAuthSecret: process.env.BETTER_AUTH_SECRET || "sandbox-better-auth-secret-for-testing",
127
+ gameJwtSecret: process.env.GAME_JWT_SECRET || "sandbox-game-jwt-secret-for-testing"
128
+ },
129
+ timeback: {
130
+ mode: getTimebackMode(),
131
+ onerosterApiUrl: process.env.TIMEBACK_ONEROSTER_API_URL,
132
+ caliperApiUrl: process.env.TIMEBACK_CALIPER_API_URL,
133
+ clientId: process.env.TIMEBACK_API_CLIENT_ID,
134
+ clientSecret: process.env.TIMEBACK_API_CLIENT_SECRET,
135
+ authUrl: process.env.TIMEBACK_API_AUTH_URL,
136
+ courseId: process.env.SANDBOX_TIMEBACK_COURSE_ID,
137
+ studentId: process.env.SANDBOX_TIMEBACK_STUDENT_ID
138
+ }
139
+ };
140
+ process.env.BETTER_AUTH_SECRET = config.auth.betterAuthSecret;
141
+ process.env.GAME_JWT_SECRET = config.auth.gameJwtSecret;
142
+ export {
143
+ setEmbeddedMode,
144
+ requireTimebackCredentials,
145
+ isTimebackEnabled,
146
+ hasTimebackFullConfig,
147
+ hasTimebackCredentials,
148
+ configureTimeback,
149
+ config
150
+ };
@@ -0,0 +1,4 @@
1
+ /**
2
+ * Configuration Mutation Functions
3
+ */
4
+ export declare function setEmbeddedMode(embedded: boolean): void;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * TimeBack Configuration Helpers
3
+ */
4
+ import type { TimebackConfig, TimebackMode } from './types';
5
+ export declare function getTimebackMode(): TimebackMode;
6
+ export declare function isTimebackEnabled(): boolean;
7
+ export declare function hasTimebackCredentials(): boolean;
8
+ export declare function hasTimebackFullConfig(): boolean;
9
+ export declare function requireTimebackCredentials(): TimebackConfig;
10
+ export declare function configureTimeback(options: Partial<TimebackConfig>): void;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Configuration Type Definitions
3
+ */
4
+ export type TimebackMode = 'local' | 'remote' | 'disabled';
5
+ export 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
+ export interface AuthConfig {
16
+ betterAuthSecret: string;
17
+ gameJwtSecret: string;
18
+ }
19
+ export interface SandboxConfig {
20
+ embedded: boolean;
21
+ auth: AuthConfig;
22
+ timeback: TimebackConfig;
23
+ }
@@ -1,11 +1,171 @@
1
- import type { Item, User } from '@playcademy/data/types';
2
- export declare const DEMO_USER: User;
3
- export declare const DEMO_TOKEN = "demo-token";
1
+ import type { Item } from '@playcademy/data/types';
2
+ export declare const DEMO_USERS: {
3
+ readonly admin: {
4
+ readonly id: `${string}-${string}-${string}-${string}-${string}`;
5
+ readonly name: "Admin User";
6
+ readonly username: "admin_user";
7
+ readonly email: "admin@playcademy.com";
8
+ readonly emailVerified: true;
9
+ readonly image: null;
10
+ readonly role: "admin";
11
+ readonly developerStatus: "approved";
12
+ readonly createdAt: Date;
13
+ readonly updatedAt: Date;
14
+ };
15
+ readonly player: {
16
+ readonly id: `${string}-${string}-${string}-${string}-${string}`;
17
+ readonly name: "Player User";
18
+ readonly username: "player_user";
19
+ readonly email: "player@playcademy.com";
20
+ readonly emailVerified: true;
21
+ readonly image: null;
22
+ readonly role: "player";
23
+ readonly developerStatus: "none";
24
+ readonly createdAt: Date;
25
+ readonly updatedAt: Date;
26
+ };
27
+ readonly developer: {
28
+ readonly id: `${string}-${string}-${string}-${string}-${string}`;
29
+ readonly name: "Developer User";
30
+ readonly username: "developer_user";
31
+ readonly email: "developer@playcademy.com";
32
+ readonly emailVerified: true;
33
+ readonly image: null;
34
+ readonly role: "developer";
35
+ readonly developerStatus: "approved";
36
+ readonly createdAt: Date;
37
+ readonly updatedAt: Date;
38
+ };
39
+ readonly pendingDeveloper: {
40
+ readonly id: `${string}-${string}-${string}-${string}-${string}`;
41
+ readonly name: "Pending Developer";
42
+ readonly username: "pending_dev";
43
+ readonly email: "pending@playcademy.com";
44
+ readonly emailVerified: true;
45
+ readonly image: null;
46
+ readonly role: "developer";
47
+ readonly developerStatus: "pending";
48
+ readonly createdAt: Date;
49
+ readonly updatedAt: Date;
50
+ };
51
+ readonly unverifiedPlayer: {
52
+ readonly id: `${string}-${string}-${string}-${string}-${string}`;
53
+ readonly name: "Unverified Player";
54
+ readonly username: "unverified_player";
55
+ readonly email: "unverified@playcademy.com";
56
+ readonly emailVerified: false;
57
+ readonly image: null;
58
+ readonly role: "player";
59
+ readonly developerStatus: "none";
60
+ readonly createdAt: Date;
61
+ readonly updatedAt: Date;
62
+ };
63
+ };
64
+ export declare const DEMO_TOKENS: {
65
+ readonly 'sandbox-demo-token': {
66
+ readonly id: `${string}-${string}-${string}-${string}-${string}`;
67
+ readonly name: "Admin User";
68
+ readonly username: "admin_user";
69
+ readonly email: "admin@playcademy.com";
70
+ readonly emailVerified: true;
71
+ readonly image: null;
72
+ readonly role: "admin";
73
+ readonly developerStatus: "approved";
74
+ readonly createdAt: Date;
75
+ readonly updatedAt: Date;
76
+ };
77
+ readonly 'sandbox-admin-token': {
78
+ readonly id: `${string}-${string}-${string}-${string}-${string}`;
79
+ readonly name: "Admin User";
80
+ readonly username: "admin_user";
81
+ readonly email: "admin@playcademy.com";
82
+ readonly emailVerified: true;
83
+ readonly image: null;
84
+ readonly role: "admin";
85
+ readonly developerStatus: "approved";
86
+ readonly createdAt: Date;
87
+ readonly updatedAt: Date;
88
+ };
89
+ readonly 'sandbox-player-token': {
90
+ readonly id: `${string}-${string}-${string}-${string}-${string}`;
91
+ readonly name: "Player User";
92
+ readonly username: "player_user";
93
+ readonly email: "player@playcademy.com";
94
+ readonly emailVerified: true;
95
+ readonly image: null;
96
+ readonly role: "player";
97
+ readonly developerStatus: "none";
98
+ readonly createdAt: Date;
99
+ readonly updatedAt: Date;
100
+ };
101
+ readonly 'sandbox-developer-token': {
102
+ readonly id: `${string}-${string}-${string}-${string}-${string}`;
103
+ readonly name: "Developer User";
104
+ readonly username: "developer_user";
105
+ readonly email: "developer@playcademy.com";
106
+ readonly emailVerified: true;
107
+ readonly image: null;
108
+ readonly role: "developer";
109
+ readonly developerStatus: "approved";
110
+ readonly createdAt: Date;
111
+ readonly updatedAt: Date;
112
+ };
113
+ readonly 'sandbox-pending-dev-token': {
114
+ readonly id: `${string}-${string}-${string}-${string}-${string}`;
115
+ readonly name: "Pending Developer";
116
+ readonly username: "pending_dev";
117
+ readonly email: "pending@playcademy.com";
118
+ readonly emailVerified: true;
119
+ readonly image: null;
120
+ readonly role: "developer";
121
+ readonly developerStatus: "pending";
122
+ readonly createdAt: Date;
123
+ readonly updatedAt: Date;
124
+ };
125
+ readonly 'sandbox-unverified-token': {
126
+ readonly id: `${string}-${string}-${string}-${string}-${string}`;
127
+ readonly name: "Unverified Player";
128
+ readonly username: "unverified_player";
129
+ readonly email: "unverified@playcademy.com";
130
+ readonly emailVerified: false;
131
+ readonly image: null;
132
+ readonly role: "player";
133
+ readonly developerStatus: "none";
134
+ readonly createdAt: Date;
135
+ readonly updatedAt: Date;
136
+ };
137
+ readonly 'mock-game-token-for-local-dev': {
138
+ readonly id: `${string}-${string}-${string}-${string}-${string}`;
139
+ readonly name: "Admin User";
140
+ readonly username: "admin_user";
141
+ readonly email: "admin@playcademy.com";
142
+ readonly emailVerified: true;
143
+ readonly image: null;
144
+ readonly role: "admin";
145
+ readonly developerStatus: "approved";
146
+ readonly createdAt: Date;
147
+ readonly updatedAt: Date;
148
+ };
149
+ };
150
+ export declare const DEMO_USER: {
151
+ readonly id: `${string}-${string}-${string}-${string}-${string}`;
152
+ readonly name: "Admin User";
153
+ readonly username: "admin_user";
154
+ readonly email: "admin@playcademy.com";
155
+ readonly emailVerified: true;
156
+ readonly image: null;
157
+ readonly role: "admin";
158
+ readonly developerStatus: "approved";
159
+ readonly createdAt: Date;
160
+ readonly updatedAt: Date;
161
+ };
162
+ export declare const DEMO_TOKEN = "sandbox-demo-token";
163
+ export declare const MOCK_GAME_ID = "mock-game-id-from-template";
4
164
  export declare const PLAYCADEMY_CREDITS_ID: `${string}-${string}-${string}-${string}-${string}`;
5
165
  export declare const SAMPLE_ITEMS: Omit<Item, 'createdAt'>[];
6
166
  export declare const SAMPLE_INVENTORY: {
7
167
  id: `${string}-${string}-${string}-${string}-${string}`;
8
- userId: string;
168
+ userId: `${string}-${string}-${string}-${string}-${string}`;
9
169
  itemId: `${string}-${string}-${string}-${string}-${string}`;
10
170
  quantity: number;
11
171
  }[];
@@ -1,16 +1,16 @@
1
1
  import { setupDatabase } from '.';
2
2
  import type { ProjectInfo } from '../types';
3
3
  export declare function seedDemoData(db: Awaited<ReturnType<typeof setupDatabase>>): Promise<{
4
- id: string;
5
- name: string;
6
- username: string | null;
7
- email: string;
8
- emailVerified: boolean;
9
- image: string | null;
10
- role: "admin" | "player" | "developer";
11
- developerStatus: "none" | "pending" | "approved";
12
- createdAt: Date;
13
- updatedAt: Date;
4
+ readonly id: `${string}-${string}-${string}-${string}-${string}`;
5
+ readonly name: "Admin User";
6
+ readonly username: "admin_user";
7
+ readonly email: "admin@playcademy.com";
8
+ readonly emailVerified: true;
9
+ readonly image: null;
10
+ readonly role: "admin";
11
+ readonly developerStatus: "approved";
12
+ readonly createdAt: Date;
13
+ readonly updatedAt: Date;
14
14
  }>;
15
15
  export declare function generateLevelConfigs(): {
16
16
  level: number;
@@ -21,12 +21,14 @@ export declare function seedCurrentProjectGame(db: Awaited<ReturnType<typeof set
21
21
  id: string;
22
22
  createdAt: Date | null;
23
23
  updatedAt: Date | null;
24
- displayName: string;
25
24
  developerId: string | null;
26
25
  slug: string;
26
+ displayName: string;
27
27
  version: string;
28
- assetBundleBase: string;
28
+ gameType: "hosted" | "external";
29
+ assetBundleBase: string | null;
30
+ externalUrl: string | null;
29
31
  platform: "web" | "godot" | "unity";
30
32
  mapElementId: string | null;
31
- metadata: unknown;
33
+ metadata: import("@playcademy/data/tables").GameMetadata;
32
34
  } | undefined>;
@@ -1,2 +1,10 @@
1
- import type { Context, Next } from 'hono';
2
- export declare function setupAuth(): (c: Context, next: Next) => Promise<void>;
1
+ import type { MiddlewareHandler } from 'hono';
2
+ export interface SetupAuthOptions {
3
+ /** Paths that don't require authentication */
4
+ exceptions?: string[];
5
+ }
6
+ /**
7
+ * Setup authentication middleware for sandbox
8
+ * Accepts both Bearer tokens (for user auth) and x-api-key (for server-to-server)
9
+ */
10
+ export declare function setupAuth(options?: SetupAuthOptions): MiddlewareHandler;
@@ -1,2 +1,22 @@
1
+ import { ApiError } from '@playcademy/api-core/errors';
1
2
  import type { Context } from 'hono';
3
+ /**
4
+ * Create a standardized error response that matches the API contract
5
+ */
6
+ export declare function createErrorResponse(error: ApiError): {
7
+ error: {
8
+ code: string;
9
+ message: string;
10
+ details: unknown;
11
+ };
12
+ };
13
+ /**
14
+ * Create a standardized error response for unknown errors
15
+ */
16
+ export declare function createUnknownErrorResponse(error: unknown): {
17
+ error: {
18
+ code: string;
19
+ message: string;
20
+ };
21
+ };
2
22
  export declare function handleApiError(c: Context, error: unknown): Response;
@@ -0,0 +1,17 @@
1
+ import { createRealtimeServer } from '@playcademy/realtime/server';
2
+ import type { SandboxRealtimeServer } from '@playcademy/realtime/server/sandbox';
3
+ import type { ServerOptions } from '../types';
4
+ /**
5
+ * Starts the realtime server with sandbox-specific configuration.
6
+ *
7
+ * This function handles:
8
+ * - Conditional startup based on options
9
+ * - Sandbox-specific authentication secrets
10
+ * - Quiet mode for clean embedded logging
11
+ * - Error handling with graceful degradation
12
+ *
13
+ * @param realtimeOptions - Realtime configuration from ServerOptions
14
+ * @param betterAuthSecret - Authentication secret for realtime server
15
+ * @returns Promise resolving to realtime server instance or null
16
+ */
17
+ export declare function startRealtimeServer(realtimeOptions: NonNullable<ServerOptions['realtime']>, betterAuthSecret: string): Promise<SandboxRealtimeServer | Awaited<ReturnType<typeof createRealtimeServer>> | null>;
package/dist/pglite.data CHANGED
Binary file
package/dist/pglite.wasm CHANGED
Binary file
@@ -0,0 +1,3 @@
1
+ import { Hono } from 'hono';
2
+ import type { HonoEnv } from '../types';
3
+ export declare const achievementsRouter: Hono<HonoEnv, import("hono/types").BlankSchema, "/">;
@@ -0,0 +1,3 @@
1
+ import { Hono } from 'hono';
2
+ import type { HonoEnv } from '../types';
3
+ export declare const characterRouter: Hono<HonoEnv, import("hono/types").BlankSchema, "/">;
@@ -10,3 +10,11 @@ export { mapRouter, mapsRouter } from './maps';
10
10
  export { shopListingsRouter } from './shop-listings';
11
11
  export { devRouter } from './dev';
12
12
  export { levelsRouter } from './levels';
13
+ export { leaderboardRouter } from './leaderboard';
14
+ export { realtimeRouter } from './realtime';
15
+ export { characterRouter } from './character';
16
+ export { spriteRouter } from './sprite';
17
+ export { timebackRouter } from './timeback';
18
+ export { achievementsRouter } from './achievements';
19
+ export { ltiRouter } from './lti';
20
+ export { notificationsRouter } from './notifications';
@@ -0,0 +1,3 @@
1
+ import { Hono } from 'hono';
2
+ import type { HonoEnv } from '../types';
3
+ export declare const leaderboardRouter: Hono<HonoEnv, import("hono/types").BlankSchema, "/">;
@@ -0,0 +1,3 @@
1
+ import { Hono } from 'hono';
2
+ import type { HonoEnv } from '../types';
3
+ export declare const ltiRouter: Hono<HonoEnv, import("hono/types").BlankSchema, "/">;
@@ -0,0 +1,3 @@
1
+ import { Hono } from 'hono';
2
+ import type { HonoEnv } from '../types';
3
+ export declare const notificationsRouter: Hono<HonoEnv, import("hono/types").BlankSchema, "/">;
@@ -0,0 +1,3 @@
1
+ import { Hono } from 'hono';
2
+ import type { HonoEnv } from '../types';
3
+ export declare const realtimeRouter: Hono<HonoEnv, import("hono/types").BlankSchema, "/">;
@@ -0,0 +1,3 @@
1
+ import { Hono } from 'hono';
2
+ import type { HonoEnv } from '../types';
3
+ export declare const spriteRouter: Hono<HonoEnv, import("hono/types").BlankSchema, "/">;
@@ -0,0 +1,3 @@
1
+ import { Hono } from 'hono';
2
+ import type { HonoEnv } from '../types';
3
+ export declare const timebackRouter: Hono<HonoEnv, import("hono/types").BlankSchema, "/">;
package/dist/server.d.ts CHANGED
@@ -1,3 +1,7 @@
1
- import type { ServerOptions } from './types';
2
- export declare function startServer(options: ServerOptions): Promise<import("@hono/node-server").ServerType>;
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;
5
+ stop: () => void;
6
+ }>;
3
7
  export declare const version: string;