@playcademy/sdk 0.1.6 → 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
@@ -3162,6 +3162,8 @@ interface IntegrationsConfig {
3162
3162
  database?: DatabaseIntegration | boolean;
3163
3163
  /** Key-Value storage (optional) */
3164
3164
  kv?: boolean;
3165
+ /** Bucket storage (optional) */
3166
+ bucket?: boolean;
3165
3167
  }
3166
3168
  /**
3167
3169
  * Unified Playcademy configuration
@@ -3715,9 +3717,10 @@ declare class PlaycademyClient {
3715
3717
  * @param method - HTTP method
3716
3718
  * @param body - Request body (optional)
3717
3719
  * @param headers - Additional headers (optional)
3718
- * @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
3719
3722
  */
3720
- 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>;
3721
3724
  /**
3722
3725
  * Ensures a gameId is available, throwing an error if not.
3723
3726
  *
@@ -4165,6 +4168,7 @@ declare class PlaycademyClient {
4165
4168
  patch<T = unknown>(path: string, body?: unknown, headers?: Record<string, string>): Promise<T>;
4166
4169
  delete<T = unknown>(path: string, headers?: Record<string, string>): Promise<T>;
4167
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>;
4168
4172
  };
4169
4173
  /** Auto-initializes a PlaycademyClient with context from the environment */
4170
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
@@ -52,6 +52,8 @@ interface IntegrationsConfig {
52
52
  database?: DatabaseIntegration | boolean;
53
53
  /** Key-Value storage (optional) */
54
54
  kv?: boolean;
55
+ /** Bucket storage (optional) */
56
+ bucket?: boolean;
55
57
  }
56
58
  /**
57
59
  * Unified Playcademy configuration
package/dist/types.d.ts CHANGED
@@ -3931,6 +3931,8 @@ interface IntegrationsConfig {
3931
3931
  database?: DatabaseIntegration | boolean;
3932
3932
  /** Key-Value storage (optional) */
3933
3933
  kv?: boolean;
3934
+ /** Bucket storage (optional) */
3935
+ bucket?: boolean;
3934
3936
  }
3935
3937
  /**
3936
3938
  * Unified Playcademy configuration
@@ -4403,9 +4405,10 @@ declare class PlaycademyClient {
4403
4405
  * @param method - HTTP method
4404
4406
  * @param body - Request body (optional)
4405
4407
  * @param headers - Additional headers (optional)
4406
- * @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
4407
4410
  */
4408
- 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>;
4409
4412
  /**
4410
4413
  * Ensures a gameId is available, throwing an error if not.
4411
4414
  *
@@ -4853,6 +4856,7 @@ declare class PlaycademyClient {
4853
4856
  patch<T = unknown>(path: string, body?: unknown, headers?: Record<string, string>): Promise<T>;
4854
4857
  delete<T = unknown>(path: string, headers?: Record<string, string>): Promise<T>;
4855
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>;
4856
4860
  };
4857
4861
  /** Auto-initializes a PlaycademyClient with context from the environment */
4858
4862
  static init: typeof init;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@playcademy/sdk",
3
- "version": "0.1.6",
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.1",
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.12.9",
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",