@playcademy/sdk 0.1.5 → 0.1.7

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.d.ts CHANGED
@@ -3160,6 +3160,10 @@ interface IntegrationsConfig {
3160
3160
  customRoutes?: CustomRoutesIntegration | boolean;
3161
3161
  /** Database (optional) */
3162
3162
  database?: DatabaseIntegration | boolean;
3163
+ /** Key-Value storage (optional) */
3164
+ kv?: boolean;
3165
+ /** Bucket storage (optional) */
3166
+ bucket?: boolean;
3163
3167
  }
3164
3168
  /**
3165
3169
  * Unified Playcademy configuration
@@ -3713,9 +3717,10 @@ declare class PlaycademyClient {
3713
3717
  * @param method - HTTP method
3714
3718
  * @param body - Request body (optional)
3715
3719
  * @param headers - Additional headers (optional)
3716
- * @returns Promise resolving to the response data
3720
+ * @param raw - If true, returns raw Response instead of parsing (optional)
3721
+ * @returns Promise resolving to the response data or raw Response
3717
3722
  */
3718
- protected requestGameBackend<T>(path: string, method: Method, body?: unknown, headers?: Record<string, string>): Promise<T>;
3723
+ protected requestGameBackend<T>(path: string, method: Method, body?: unknown, headers?: Record<string, string>, raw?: boolean): Promise<T>;
3719
3724
  /**
3720
3725
  * Ensures a gameId is available, throwing an error if not.
3721
3726
  *
@@ -4163,6 +4168,7 @@ declare class PlaycademyClient {
4163
4168
  patch<T = unknown>(path: string, body?: unknown, headers?: Record<string, string>): Promise<T>;
4164
4169
  delete<T = unknown>(path: string, headers?: Record<string, string>): Promise<T>;
4165
4170
  request<T = unknown>(path: string, method: Method, body?: unknown, headers?: Record<string, string>): Promise<T>;
4171
+ download(path: string, method?: Method, body?: unknown, headers?: Record<string, string>): Promise<Response>;
4166
4172
  };
4167
4173
  /** Auto-initializes a PlaycademyClient with context from the environment */
4168
4174
  static init: typeof init;
package/dist/index.js CHANGED
@@ -935,28 +935,42 @@ function checkDevWarnings(data) {
935
935
  console.warn(`[Playcademy Dev Warning] ${warningType}`);
936
936
  }
937
937
  }
938
+ function prepareRequestBody(body, headers) {
939
+ if (body instanceof FormData) {
940
+ return body;
941
+ }
942
+ if (body instanceof ArrayBuffer || body instanceof Blob || ArrayBuffer.isView(body)) {
943
+ if (!headers["Content-Type"]) {
944
+ headers["Content-Type"] = "application/octet-stream";
945
+ }
946
+ return body;
947
+ }
948
+ if (body !== undefined && body !== null) {
949
+ headers["Content-Type"] = "application/json";
950
+ return JSON.stringify(body);
951
+ }
952
+ return;
953
+ }
938
954
  async function request({
939
955
  path,
940
956
  baseUrl,
941
957
  method = "GET",
942
958
  body,
943
- extraHeaders = {}
959
+ extraHeaders = {},
960
+ raw = false
944
961
  }) {
945
962
  const url = baseUrl.replace(/\/$/, "") + (path.startsWith("/") ? path : `/${path}`);
946
963
  const headers = { ...extraHeaders };
947
- let payload;
948
- if (body instanceof FormData) {
949
- payload = body;
950
- } else if (body !== undefined && body !== null) {
951
- payload = JSON.stringify(body);
952
- headers["Content-Type"] = "application/json";
953
- }
964
+ const payload = prepareRequestBody(body, headers);
954
965
  const res = await fetch(url, {
955
966
  method,
956
967
  headers,
957
968
  body: payload,
958
969
  credentials: "omit"
959
970
  });
971
+ if (raw) {
972
+ return res;
973
+ }
960
974
  if (!res.ok) {
961
975
  const clonedRes = res.clone();
962
976
  const errorBody = await clonedRes.json().catch(() => clonedRes.text().catch(() => {
@@ -978,8 +992,8 @@ async function request({
978
992
  throw err;
979
993
  }
980
994
  }
981
- const raw = await res.text().catch(() => "");
982
- return raw && raw.length > 0 ? raw : undefined;
995
+ const rawText = await res.text().catch(() => "");
996
+ return rawText && rawText.length > 0 ? rawText : undefined;
983
997
  }
984
998
  async function fetchManifest(assetBundleBase) {
985
999
  const manifestUrl = `${assetBundleBase.replace(/\/$/, "")}/playcademy.manifest.json`;
@@ -2276,6 +2290,9 @@ function createBackendNamespace(client) {
2276
2290
  },
2277
2291
  async request(path, method, body, headers) {
2278
2292
  return client["requestGameBackend"](normalizePath(path), method, body, headers);
2293
+ },
2294
+ async download(path, method = "GET", body, headers) {
2295
+ return client["requestGameBackend"](normalizePath(path), method, body, headers, true);
2279
2296
  }
2280
2297
  };
2281
2298
  }
@@ -2542,7 +2559,7 @@ var init_client = __esm(() => {
2542
2559
  extraHeaders: effectiveHeaders
2543
2560
  });
2544
2561
  }
2545
- async requestGameBackend(path, method, body, headers) {
2562
+ async requestGameBackend(path, method, body, headers, raw) {
2546
2563
  const effectiveHeaders = {
2547
2564
  ...headers,
2548
2565
  ...this.authStrategy.getHeaders()
@@ -2552,7 +2569,8 @@ var init_client = __esm(() => {
2552
2569
  method,
2553
2570
  body,
2554
2571
  baseUrl: this.getGameBackendUrl(),
2555
- extraHeaders: effectiveHeaders
2572
+ extraHeaders: effectiveHeaders,
2573
+ raw
2556
2574
  });
2557
2575
  }
2558
2576
  _ensureGameId() {
package/dist/server.d.ts CHANGED
@@ -50,6 +50,10 @@ interface IntegrationsConfig {
50
50
  customRoutes?: CustomRoutesIntegration | boolean;
51
51
  /** Database (optional) */
52
52
  database?: DatabaseIntegration | boolean;
53
+ /** Key-Value storage (optional) */
54
+ kv?: boolean;
55
+ /** Bucket storage (optional) */
56
+ bucket?: boolean;
53
57
  }
54
58
  /**
55
59
  * Unified Playcademy configuration
package/dist/types.d.ts CHANGED
@@ -3929,6 +3929,10 @@ interface IntegrationsConfig {
3929
3929
  customRoutes?: CustomRoutesIntegration | boolean;
3930
3930
  /** Database (optional) */
3931
3931
  database?: DatabaseIntegration | boolean;
3932
+ /** Key-Value storage (optional) */
3933
+ kv?: boolean;
3934
+ /** Bucket storage (optional) */
3935
+ bucket?: boolean;
3932
3936
  }
3933
3937
  /**
3934
3938
  * Unified Playcademy configuration
@@ -4401,9 +4405,10 @@ declare class PlaycademyClient {
4401
4405
  * @param method - HTTP method
4402
4406
  * @param body - Request body (optional)
4403
4407
  * @param headers - Additional headers (optional)
4404
- * @returns Promise resolving to the response data
4408
+ * @param raw - If true, returns raw Response instead of parsing (optional)
4409
+ * @returns Promise resolving to the response data or raw Response
4405
4410
  */
4406
- protected requestGameBackend<T>(path: string, method: Method, body?: unknown, headers?: Record<string, string>): Promise<T>;
4411
+ protected requestGameBackend<T>(path: string, method: Method, body?: unknown, headers?: Record<string, string>, raw?: boolean): Promise<T>;
4407
4412
  /**
4408
4413
  * Ensures a gameId is available, throwing an error if not.
4409
4414
  *
@@ -4851,6 +4856,7 @@ declare class PlaycademyClient {
4851
4856
  patch<T = unknown>(path: string, body?: unknown, headers?: Record<string, string>): Promise<T>;
4852
4857
  delete<T = unknown>(path: string, headers?: Record<string, string>): Promise<T>;
4853
4858
  request<T = unknown>(path: string, method: Method, body?: unknown, headers?: Record<string, string>): Promise<T>;
4859
+ download(path: string, method?: Method, body?: unknown, headers?: Record<string, string>): Promise<Response>;
4854
4860
  };
4855
4861
  /** Auto-initializes a PlaycademyClient with context from the environment */
4856
4862
  static init: typeof init;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playcademy/sdk",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -37,12 +37,12 @@
37
37
  "@playcademy/constants": "0.0.1",
38
38
  "@playcademy/data": "0.0.1",
39
39
  "@playcademy/logger": "0.0.1",
40
- "@playcademy/sandbox": "0.1.0",
40
+ "@playcademy/sandbox": "0.1.7",
41
41
  "@playcademy/test": "0.0.1",
42
42
  "@playcademy/timeback": "0.0.1",
43
43
  "@playcademy/utils": "0.0.1",
44
44
  "@types/bun": "latest",
45
- "playcademy": "0.11.4",
45
+ "playcademy": "0.13.16",
46
46
  "rollup": "^4.50.2",
47
47
  "rollup-plugin-dts": "^6.2.3",
48
48
  "typescript": "^5.7.2",