@playcademy/sandbox 0.1.0 → 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
+ }
@@ -134,6 +134,18 @@ export declare const DEMO_TOKENS: {
134
134
  readonly createdAt: Date;
135
135
  readonly updatedAt: Date;
136
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
+ };
137
149
  };
138
150
  export declare const DEMO_USER: {
139
151
  readonly id: `${string}-${string}-${string}-${string}-${string}`;
@@ -148,6 +160,7 @@ export declare const DEMO_USER: {
148
160
  readonly updatedAt: Date;
149
161
  };
150
162
  export declare const DEMO_TOKEN = "sandbox-demo-token";
163
+ export declare const MOCK_GAME_ID = "mock-game-id-from-template";
151
164
  export declare const PLAYCADEMY_CREDITS_ID: `${string}-${string}-${string}-${string}-${string}`;
152
165
  export declare const SAMPLE_ITEMS: Omit<Item, 'createdAt'>[];
153
166
  export declare const SAMPLE_INVENTORY: {
@@ -1,5 +1,10 @@
1
- import type { Context, Next } from 'hono';
1
+ import type { MiddlewareHandler } from 'hono';
2
+ export interface SetupAuthOptions {
3
+ /** Paths that don't require authentication */
4
+ exceptions?: string[];
5
+ }
2
6
  /**
3
7
  * Setup authentication middleware for sandbox
8
+ * Accepts both Bearer tokens (for user auth) and x-api-key (for server-to-server)
4
9
  */
5
- export declare function setupAuth(): (c: Context, next: Next) => Promise<void>;
10
+ export declare function setupAuth(options?: SetupAuthOptions): MiddlewareHandler;
package/dist/server.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { ProjectInfo, ServerOptions } from './types';
2
2
  export declare function startServer(port: number, project?: ProjectInfo, options?: Omit<ServerOptions, 'port' | 'project'>): Promise<{
3
3
  main: import("@hono/node-server").ServerType;
4
- realtime: Bun.Server | import("@playcademy/realtime/server/sandbox").SandboxRealtimeServer | null;
4
+ realtime: Bun.Server<import("@playcademy/realtime/server").WebSocketData> | import("@playcademy/realtime/server/sandbox").SandboxRealtimeServer | null;
5
5
  stop: () => void;
6
6
  }>;
7
7
  export declare const version: string;