playcademy 0.9.0 → 0.10.0

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/index.js CHANGED
@@ -6261,7 +6261,8 @@ var formatLog = (level, message, context2) => {
6261
6261
  return JSON.stringify(logEntry);
6262
6262
  };
6263
6263
  var performLog = (level, message, context2) => {
6264
- if (level === "debug" && false) {
6264
+ if (level === "debug" && process.env.PLAYCADEMY_EMBEDDED) {
6265
+ return;
6265
6266
  }
6266
6267
  if (isBrowser()) {
6267
6268
  logInBrowser(level, message, context2);
@@ -8943,6 +8944,31 @@ function createNotificationsNamespace(client) {
8943
8944
  }
8944
8945
  var init_notifications = () => {
8945
8946
  };
8947
+ function createBackendNamespace(client) {
8948
+ function normalizePath(path) {
8949
+ return path.startsWith("/") ? path : `/${path}`;
8950
+ }
8951
+ return {
8952
+ async get(path, headers) {
8953
+ return client["requestGameBackend"](normalizePath(path), "GET", void 0, headers);
8954
+ },
8955
+ async post(path, body, headers) {
8956
+ return client["requestGameBackend"](normalizePath(path), "POST", body, headers);
8957
+ },
8958
+ async put(path, body, headers) {
8959
+ return client["requestGameBackend"](normalizePath(path), "PUT", body, headers);
8960
+ },
8961
+ async patch(path, body, headers) {
8962
+ return client["requestGameBackend"](normalizePath(path), "PATCH", body, headers);
8963
+ },
8964
+ async delete(path, headers) {
8965
+ return client["requestGameBackend"](normalizePath(path), "DELETE", void 0, headers);
8966
+ },
8967
+ async request(path, method, body, headers) {
8968
+ return client["requestGameBackend"](normalizePath(path), method, body, headers);
8969
+ }
8970
+ };
8971
+ }
8946
8972
  var init_namespaces = __esm2(() => {
8947
8973
  init_identity();
8948
8974
  init_runtime();
@@ -8982,6 +9008,9 @@ function buildAllowedOrigins(explicit) {
8982
9008
  return ref ? [ref] : [];
8983
9009
  }
8984
9010
  function isOriginAllowed(origin, allowlist) {
9011
+ if (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1") {
9012
+ return true;
9013
+ }
8985
9014
  if (!allowlist || allowlist.length === 0) {
8986
9015
  console.error("[Playcademy SDK] No allowed origins configured. Consider passing allowedParentOrigins explicitly to init().");
8987
9016
  return false;
@@ -9254,6 +9283,7 @@ var init_client = __esm2(() => {
9254
9283
  realtime = createRealtimeNamespace(this);
9255
9284
  achievements = createAchievementsNamespace(this);
9256
9285
  notifications = createNotificationsNamespace(this);
9286
+ backend = createBackendNamespace(this);
9257
9287
  static init = init;
9258
9288
  static login = login2;
9259
9289
  static identity = identity;
@@ -10491,7 +10521,7 @@ async function confirmDeploymentPlan(plan, context2) {
10491
10521
  import { join as join6 } from "node:path";
10492
10522
  import { blueBright, underline } from "colorette";
10493
10523
  function displayCurrentConfiguration(context2) {
10494
- const { config, existingGame } = context2;
10524
+ const { config } = context2;
10495
10525
  logger.newLine();
10496
10526
  logger.highlight("Current Configuration:");
10497
10527
  logger.newLine();
@@ -10513,10 +10543,8 @@ function displayCurrentConfiguration(context2) {
10513
10543
  }
10514
10544
  if (context2.isGameDeployed) {
10515
10545
  logger.data("Status", "Deployed", 1);
10516
- } else if (existingGame) {
10517
- logger.data("Status", "Not deployed", 1);
10518
10546
  } else {
10519
- logger.data("Status", "New deployment", 1);
10547
+ logger.data("Status", "Not deployed", 1);
10520
10548
  }
10521
10549
  logger.newLine();
10522
10550
  }
@@ -10942,7 +10970,7 @@ function displayRegisteredRoutes(integrations, customRoutes = []) {
10942
10970
  // src/lib/dev/reload.ts
10943
10971
  import { join as join9 } from "path";
10944
10972
  import chokidar from "chokidar";
10945
- function startHotReload(onReload) {
10973
+ function startHotReload(onReload, options = {}) {
10946
10974
  const workspace = getWorkspace();
10947
10975
  const watchPaths = [
10948
10976
  join9(workspace, "api"),
@@ -10957,33 +10985,22 @@ function startHotReload(onReload) {
10957
10985
  pollInterval: 100
10958
10986
  }
10959
10987
  });
10960
- watcher.on("change", async () => {
10961
- try {
10962
- await onReload();
10963
- logger.success("Reloaded");
10964
- } catch (error) {
10965
- logger.newLine();
10966
- logger.error(`Reload failed: ${error instanceof Error ? error.message : String(error)}`);
10967
- }
10968
- });
10969
- watcher.on("add", async () => {
10970
- try {
10971
- await onReload();
10972
- logger.success("Reloaded");
10973
- } catch (error) {
10974
- logger.newLine();
10975
- logger.error(`Reload failed: ${error instanceof Error ? error.message : String(error)}`);
10976
- }
10988
+ const logSuccess = options.onSuccess || (() => logger.success("Reloaded"));
10989
+ const logError = options.onError || ((error) => {
10990
+ logger.newLine();
10991
+ logger.error(`Reload failed: ${error instanceof Error ? error.message : String(error)}`);
10977
10992
  });
10978
- watcher.on("unlink", async () => {
10993
+ const handleReload = async (path) => {
10979
10994
  try {
10980
10995
  await onReload();
10981
- logger.success("Reloaded");
10996
+ logSuccess(path);
10982
10997
  } catch (error) {
10983
- logger.newLine();
10984
- logger.error(`Reload failed: ${error instanceof Error ? error.message : String(error)}`);
10998
+ logError(error);
10985
10999
  }
10986
- });
11000
+ };
11001
+ watcher.on("change", handleReload);
11002
+ watcher.on("add", handleReload);
11003
+ watcher.on("unlink", handleReload);
10987
11004
  return watcher;
10988
11005
  }
10989
11006
 
@@ -12034,7 +12051,6 @@ var listCommand = new Command9("list").alias("ls").description("List all games")
12034
12051
  logger.newLine();
12035
12052
  });
12036
12053
  } catch (error) {
12037
- logger.newLine();
12038
12054
  logger.error(
12039
12055
  `Failed to list games: ${error instanceof Error ? error.message : "Unknown error"}`
12040
12056
  );
@@ -1,3 +1,34 @@
1
+ /**
2
+ * ─────────────────────────────────────────────────────────────────
3
+ * Calling your backend from your frontend:
4
+ * ─────────────────────────────────────────────────────────────────
5
+ *
6
+ * In your game's frontend, use the Playcademy SDK client to call
7
+ * your custom backend routes:
8
+ *
9
+ * ```typescript
10
+ * import { PlaycademyClient } from 'playcademy'
11
+ *
12
+ * const client = PlaycademyClient.init()
13
+ *
14
+ * // GET request to /api/hello
15
+ * const data = await client.backend.get('/hello')
16
+ * console.log(data.message)
17
+ *
18
+ * // POST request to /api/hello
19
+ * const result = await client.backend.post('/hello', { name: 'Player' })
20
+ * console.log(result.received)
21
+ *
22
+ * // Other HTTP methods are also available:
23
+ * await client.backend.put('/settings', settings)
24
+ * await client.backend.patch('/profile', updates)
25
+ * await client.backend.delete('/cache')
26
+ *
27
+ * // Custom methods
28
+ * await client.backend.request('/custom', 'OPTIONS')
29
+ * ```
30
+ */
31
+
1
32
  /**
2
33
  * Sample API route
3
34
  *
package/dist/utils.js CHANGED
@@ -1717,7 +1717,7 @@ function sql(strings, ...params) {
1717
1717
  return new SQL([new StringChunk(str)]);
1718
1718
  }
1719
1719
  sql2.raw = raw;
1720
- function join3(chunks, separator) {
1720
+ function join4(chunks, separator) {
1721
1721
  const result = [];
1722
1722
  for (const [i, chunk] of chunks.entries()) {
1723
1723
  if (i > 0 && separator !== void 0) {
@@ -1727,7 +1727,7 @@ function sql(strings, ...params) {
1727
1727
  }
1728
1728
  return new SQL(result);
1729
1729
  }
1730
- sql2.join = join3;
1730
+ sql2.join = join4;
1731
1731
  function identifier(value) {
1732
1732
  return new Name(value);
1733
1733
  }
@@ -3478,7 +3478,8 @@ var formatLog = (level, message, context2) => {
3478
3478
  return JSON.stringify(logEntry);
3479
3479
  };
3480
3480
  var performLog = (level, message, context2) => {
3481
- if (level === "debug" && false) {
3481
+ if (level === "debug" && process.env.PLAYCADEMY_EMBEDDED) {
3482
+ return;
3482
3483
  }
3483
3484
  if (isBrowser()) {
3484
3485
  logInBrowser(level, message, context2);
@@ -6160,6 +6161,31 @@ function createNotificationsNamespace(client) {
6160
6161
  }
6161
6162
  var init_notifications = () => {
6162
6163
  };
6164
+ function createBackendNamespace(client) {
6165
+ function normalizePath(path) {
6166
+ return path.startsWith("/") ? path : `/${path}`;
6167
+ }
6168
+ return {
6169
+ async get(path, headers) {
6170
+ return client["requestGameBackend"](normalizePath(path), "GET", void 0, headers);
6171
+ },
6172
+ async post(path, body, headers) {
6173
+ return client["requestGameBackend"](normalizePath(path), "POST", body, headers);
6174
+ },
6175
+ async put(path, body, headers) {
6176
+ return client["requestGameBackend"](normalizePath(path), "PUT", body, headers);
6177
+ },
6178
+ async patch(path, body, headers) {
6179
+ return client["requestGameBackend"](normalizePath(path), "PATCH", body, headers);
6180
+ },
6181
+ async delete(path, headers) {
6182
+ return client["requestGameBackend"](normalizePath(path), "DELETE", void 0, headers);
6183
+ },
6184
+ async request(path, method, body, headers) {
6185
+ return client["requestGameBackend"](normalizePath(path), method, body, headers);
6186
+ }
6187
+ };
6188
+ }
6163
6189
  var init_namespaces = __esm2(() => {
6164
6190
  init_identity();
6165
6191
  init_runtime();
@@ -6199,6 +6225,9 @@ function buildAllowedOrigins(explicit) {
6199
6225
  return ref ? [ref] : [];
6200
6226
  }
6201
6227
  function isOriginAllowed(origin, allowlist) {
6228
+ if (window.location.hostname === "localhost" || window.location.hostname === "127.0.0.1") {
6229
+ return true;
6230
+ }
6202
6231
  if (!allowlist || allowlist.length === 0) {
6203
6232
  console.error("[Playcademy SDK] No allowed origins configured. Consider passing allowedParentOrigins explicitly to init().");
6204
6233
  return false;
@@ -6471,6 +6500,7 @@ var init_client = __esm2(() => {
6471
6500
  realtime = createRealtimeNamespace(this);
6472
6501
  achievements = createAchievementsNamespace(this);
6473
6502
  notifications = createNotificationsNamespace(this);
6503
+ backend = createBackendNamespace(this);
6474
6504
  static init = init;
6475
6505
  static login = login2;
6476
6506
  static identity = identity;
@@ -6857,9 +6887,47 @@ async function startDevServer(port, config, options = {}) {
6857
6887
  port
6858
6888
  });
6859
6889
  }
6890
+
6891
+ // src/lib/dev/reload.ts
6892
+ import { join as join3 } from "path";
6893
+ import chokidar from "chokidar";
6894
+ function startHotReload(onReload, options = {}) {
6895
+ const workspace = getWorkspace();
6896
+ const watchPaths = [
6897
+ join3(workspace, "api"),
6898
+ join3(workspace, "playcademy.config.js"),
6899
+ join3(workspace, "playcademy.config.json")
6900
+ ];
6901
+ const watcher = chokidar.watch(watchPaths, {
6902
+ persistent: true,
6903
+ ignoreInitial: true,
6904
+ awaitWriteFinish: {
6905
+ stabilityThreshold: 100,
6906
+ pollInterval: 100
6907
+ }
6908
+ });
6909
+ const logSuccess = options.onSuccess || (() => logger.success("Reloaded"));
6910
+ const logError = options.onError || ((error) => {
6911
+ logger.newLine();
6912
+ logger.error(`Reload failed: ${error instanceof Error ? error.message : String(error)}`);
6913
+ });
6914
+ const handleReload = async (path) => {
6915
+ try {
6916
+ await onReload();
6917
+ logSuccess(path);
6918
+ } catch (error) {
6919
+ logError(error);
6920
+ }
6921
+ };
6922
+ watcher.on("change", handleReload);
6923
+ watcher.on("add", handleReload);
6924
+ watcher.on("unlink", handleReload);
6925
+ return watcher;
6926
+ }
6860
6927
  export {
6861
6928
  findConfigPath as findPlaycademyConfigPath,
6862
6929
  loadConfig as loadPlaycademyConfig,
6863
6930
  startDevServer as startPlaycademyDevServer,
6931
+ startHotReload as startPlaycademyHotReload,
6864
6932
  validateConfig as validatePlaycademyConfig
6865
6933
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "playcademy",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "type": "module",
5
5
  "module": "./dist/index.js",
6
6
  "exports": {