playcademy 0.14.11-alpha.8 → 0.14.12-alpha.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.
package/dist/db.d.ts CHANGED
@@ -75,6 +75,17 @@ declare function resetDatabase(workspace: string, mf: Miniflare, options?: {
75
75
  debug?: boolean;
76
76
  }): Promise<void>;
77
77
 
78
+ /**
79
+ * Environment context passed to seed functions
80
+ */
81
+ interface SeedContext {
82
+ env: {
83
+ DB: unknown;
84
+ BUCKET?: unknown;
85
+ secrets?: Record<string, string>;
86
+ };
87
+ }
88
+
78
89
  /**
79
90
  * Database Seed Utilities
80
91
  *
@@ -87,19 +98,17 @@ declare function resetDatabase(workspace: string, mf: Miniflare, options?: {
87
98
  * Bundles all deps for portability.
88
99
  */
89
100
  declare function importSeedModule(seedPath: string): Promise<{
90
- seed?: (c: {
91
- env: {
92
- DB: unknown;
93
- };
94
- }) => Promise<void>;
101
+ seed?: (c: SeedContext) => Promise<void>;
95
102
  }>;
103
+ declare function getBucket(mf: Miniflare): Promise<unknown | null>;
96
104
  /**
97
- * Execute a seed file against a Miniflare D1 instance
105
+ * Execute a seed file against a Miniflare instance
98
106
  *
99
107
  * @param seedFilePath - Path to seed file
100
- * @param mf - Miniflare instance with D1 database
108
+ * @param mf - Miniflare instance with D1 database (and optionally bucket/secrets)
109
+ * @param envSecrets - Environment secrets from .env file
101
110
  */
102
- declare function executeSeedFile(seedFilePath: string, mf: Miniflare): Promise<void>;
111
+ declare function executeSeedFile(seedFilePath: string, mf: Miniflare, envSecrets?: Record<string, string>): Promise<void>;
103
112
 
104
- export { bundleSeedWorker, executeSeedFile, getDevDbPath as getPath, importSeedModule, resetDatabase };
113
+ export { bundleSeedWorker, executeSeedFile, getBucket, getDevDbPath as getPath, importSeedModule, resetDatabase };
105
114
  export type { SeedWorkerBundle };
package/dist/db.js CHANGED
@@ -2938,7 +2938,14 @@ async function resetDatabase(workspace, mf, options = { debug: false }) {
2938
2938
  async function importSeedModule(seedPath) {
2939
2939
  return await importTypescriptFile(seedPath);
2940
2940
  }
2941
- async function executeSeedFile(seedFilePath, mf) {
2941
+ async function getBucket(mf) {
2942
+ try {
2943
+ return await mf.getR2Bucket(CLOUDFLARE_BINDINGS.BUCKET);
2944
+ } catch {
2945
+ return null;
2946
+ }
2947
+ }
2948
+ async function executeSeedFile(seedFilePath, mf, envSecrets = {}) {
2942
2949
  const d1 = await mf.getD1Database(CLOUDFLARE_BINDINGS.DB);
2943
2950
  const seedModule = await importSeedModule(seedFilePath);
2944
2951
  if (typeof seedModule.seed !== "function") {
@@ -2951,9 +2958,16 @@ async function executeSeedFile(seedFilePath, mf) {
2951
2958
  logger.newLine();
2952
2959
  process.exit(1);
2953
2960
  }
2961
+ const bucket = await getBucket(mf);
2962
+ const hasSecrets = Object.keys(envSecrets).length > 0;
2954
2963
  await runStep(
2955
2964
  "Seeding database...",
2956
- async () => seedModule.seed?.({ env: { DB: d1 } }),
2965
+ async () => {
2966
+ const env = { DB: d1 };
2967
+ if (bucket) env.BUCKET = bucket;
2968
+ if (hasSecrets) env.secrets = envSecrets;
2969
+ return seedModule.seed?.({ env });
2970
+ },
2957
2971
  "Database seeded successfully!"
2958
2972
  );
2959
2973
  logger.newLine();
@@ -2961,6 +2975,7 @@ async function executeSeedFile(seedFilePath, mf) {
2961
2975
  export {
2962
2976
  bundleSeedWorker,
2963
2977
  executeSeedFile,
2978
+ getBucket,
2964
2979
  getDevDbPath as getPath,
2965
2980
  importSeedModule,
2966
2981
  resetDatabase
package/dist/index.js CHANGED
@@ -5770,7 +5770,14 @@ init_core();
5770
5770
  async function importSeedModule(seedPath) {
5771
5771
  return await importTypescriptFile(seedPath);
5772
5772
  }
5773
- async function executeSeedFile(seedFilePath, mf) {
5773
+ async function getBucket(mf) {
5774
+ try {
5775
+ return await mf.getR2Bucket(CLOUDFLARE_BINDINGS.BUCKET);
5776
+ } catch {
5777
+ return null;
5778
+ }
5779
+ }
5780
+ async function executeSeedFile(seedFilePath, mf, envSecrets = {}) {
5774
5781
  const d1 = await mf.getD1Database(CLOUDFLARE_BINDINGS.DB);
5775
5782
  const seedModule = await importSeedModule(seedFilePath);
5776
5783
  if (typeof seedModule.seed !== "function") {
@@ -5783,9 +5790,16 @@ async function executeSeedFile(seedFilePath, mf) {
5783
5790
  logger.newLine();
5784
5791
  process.exit(1);
5785
5792
  }
5793
+ const bucket = await getBucket(mf);
5794
+ const hasSecrets = Object.keys(envSecrets).length > 0;
5786
5795
  await runStep(
5787
5796
  "Seeding database...",
5788
- async () => seedModule.seed?.({ env: { DB: d1 } }),
5797
+ async () => {
5798
+ const env = { DB: d1 };
5799
+ if (bucket) env.BUCKET = bucket;
5800
+ if (hasSecrets) env.secrets = envSecrets;
5801
+ return seedModule.seed?.({ env });
5802
+ },
5789
5803
  "Database seeded successfully!"
5790
5804
  );
5791
5805
  logger.newLine();
@@ -7123,8 +7137,11 @@ function scaffoldProtectedExample(workspace) {
7123
7137
  writeFileSync3(join14(sampleDir, "protected.ts"), protectedRouteTemplate);
7124
7138
  }
7125
7139
  function updateEnvForAuth(workspace, strategies) {
7126
- if (strategies.length === 0) return;
7127
7140
  const envLines = [];
7141
+ envLines.push("# Better Auth (required)");
7142
+ envLines.push("# Generate with: openssl rand -base64 32");
7143
+ envLines.push("BETTER_AUTH_SECRET=your_secret_here");
7144
+ envLines.push("");
7128
7145
  if (strategies.includes("github")) {
7129
7146
  envLines.push("# GitHub OAuth (for standalone auth)");
7130
7147
  envLines.push("GITHUB_CLIENT_ID=your_github_client_id");
@@ -7137,9 +7154,7 @@ function updateEnvForAuth(workspace, strategies) {
7137
7154
  envLines.push("GOOGLE_CLIENT_SECRET=your_google_client_secret");
7138
7155
  envLines.push("");
7139
7156
  }
7140
- if (envLines.length > 0) {
7141
- updateEnvExample(workspace, envLines);
7142
- }
7157
+ updateEnvExample(workspace, envLines);
7143
7158
  }
7144
7159
  async function scaffoldAuthSetup(options = {}) {
7145
7160
  const workspace = getWorkspace();
@@ -7195,7 +7210,7 @@ import { join as join15 } from "path";
7195
7210
  // package.json
7196
7211
  var package_default2 = {
7197
7212
  name: "playcademy",
7198
- version: "0.14.11",
7213
+ version: "0.14.12",
7199
7214
  type: "module",
7200
7215
  exports: {
7201
7216
  ".": {
@@ -11905,10 +11920,37 @@ async function runDbSeedRemote(seedFile, options) {
11905
11920
  async function runDbSeedLocal(seedFile, options) {
11906
11921
  const workspace = getWorkspace();
11907
11922
  const dbDir = join31(workspace, CLI_DIRECTORIES.DATABASE);
11923
+ const config = await loadConfig();
11924
+ const hasBucket = hasBucketSetup(config);
11925
+ const hasKV = hasKVSetup(config);
11926
+ const bucketDir = hasBucket ? join31(workspace, CLI_DIRECTORIES.BUCKET) : void 0;
11927
+ const kvDir = hasKV ? join31(workspace, CLI_DIRECTORIES.KV) : void 0;
11928
+ if (bucketDir) {
11929
+ const { mkdir: mkdir5 } = await import("fs/promises");
11930
+ await mkdir5(bucketDir, { recursive: true });
11931
+ }
11932
+ if (kvDir) {
11933
+ const { mkdir: mkdir5 } = await import("fs/promises");
11934
+ await mkdir5(kvDir, { recursive: true });
11935
+ }
11936
+ const envSecrets = await readEnvFile(workspace);
11937
+ const bindings = {};
11938
+ for (const [key, value] of Object.entries(envSecrets)) {
11939
+ bindings[`secrets_${key}`] = value;
11940
+ }
11908
11941
  const mf = new Miniflare3({
11909
11942
  modules: [{ type: "ESModule", path: "index.mjs", contents: "" }],
11943
+ bindings,
11910
11944
  d1Databases: [CLOUDFLARE_BINDINGS.DB],
11911
11945
  d1Persist: dbDir,
11946
+ ...hasBucket && {
11947
+ r2Buckets: [CLOUDFLARE_BINDINGS.BUCKET],
11948
+ r2Persist: bucketDir
11949
+ },
11950
+ ...hasKV && {
11951
+ kvNamespaces: [CLOUDFLARE_BINDINGS.KV],
11952
+ kvPersist: kvDir
11953
+ },
11912
11954
  compatibilityDate: CLOUDFLARE_COMPATIBILITY_DATE
11913
11955
  });
11914
11956
  logger.newLine();
@@ -11916,7 +11958,7 @@ async function runDbSeedLocal(seedFile, options) {
11916
11958
  await resetDatabase(workspace, mf, { debug: options.debug });
11917
11959
  }
11918
11960
  try {
11919
- await executeSeedFile(seedFile, mf);
11961
+ await executeSeedFile(seedFile, mf, envSecrets);
11920
11962
  } finally {
11921
11963
  await mf.dispose();
11922
11964
  }
@@ -14954,6 +14996,7 @@ export {
14954
14996
  getAuthenticatedEnvironments,
14955
14997
  getBaseUrl,
14956
14998
  getBestUnit,
14999
+ getBucket,
14957
15000
  getBucketKey,
14958
15001
  getCallbackUrl,
14959
15002
  getCliContext,
@@ -7,7 +7,7 @@
7
7
 
8
8
  import { desc } from 'drizzle-orm'
9
9
 
10
- import { getDb, schema } from '../../../db'
10
+ import { getDb, schema } from 'db'
11
11
 
12
12
  /**
13
13
  * GET /api/sample/database
@@ -11,10 +11,20 @@ import { playcademy } from '@playcademy/better-auth/server'
11
11
 
12
12
  import { getDb } from '../../db'
13
13
 
14
- import type { Context } from 'hono'
14
+ function getAuthSecret(c: Context): string {
15
+ const secret = c.env.secrets?.BETTER_AUTH_SECRET
16
+ if (!secret) {
17
+ throw new Error(
18
+ 'BETTER_AUTH_SECRET is required. ' +
19
+ 'Set it locally in .env or deploy with: playcademy secret set BETTER_AUTH_SECRET <value>'
20
+ )
21
+ }
22
+ return secret
23
+ }
15
24
 
16
25
  export function getAuth(c: Context) {
17
26
  const db = getDb(c.env.DB)
27
+ const secret = getAuthSecret(c)
18
28
 
19
29
  // CUSTOMIZABLE: Configure trusted origins for CORS
20
30
  // These origins are allowed to make cross-origin requests to your game's auth endpoints.
@@ -31,6 +41,8 @@ export function getAuth(c: Context) {
31
41
  usePlural: false,
32
42
  }),
33
43
 
44
+ secret,
45
+
34
46
  trustedOrigins,
35
47
  {{EMAIL_AND_PASSWORD}}{{SOCIAL_PROVIDERS}}
36
48
  // REQUIRED: Platform integration
package/dist/utils.js CHANGED
@@ -3829,7 +3829,7 @@ import { join as join8 } from "path";
3829
3829
  // package.json
3830
3830
  var package_default2 = {
3831
3831
  name: "playcademy",
3832
- version: "0.14.11",
3832
+ version: "0.14.12",
3833
3833
  type: "module",
3834
3834
  exports: {
3835
3835
  ".": {
package/dist/version.js CHANGED
@@ -1,7 +1,7 @@
1
1
  // package.json
2
2
  var package_default = {
3
3
  name: "playcademy",
4
- version: "0.14.11",
4
+ version: "0.14.12",
5
5
  type: "module",
6
6
  exports: {
7
7
  ".": {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playcademy",
3
- "version": "0.14.11-alpha.8",
3
+ "version": "0.14.12-alpha.1",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {