@aneuhold/core-ts-api-lib 2.2.2 → 2.2.4

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/CHANGELOG.md CHANGED
@@ -5,6 +5,21 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## 🔖 [2.2.4] (2025-11-04)
9
+
10
+ ### 🏗️ Changed
11
+
12
+ - Switched `GCloudAPIService` to use BSON serialization for requests and responses
13
+ - Updated request and response `Content-Type` headers to `application/octet-stream`
14
+ - Added private `decodeResponse` helper for decoding API responses
15
+ - Improved error handling for non-BSON responses in `GCloudAPIService`
16
+
17
+ ## 🔖 [2.2.3] (2025-10-25)
18
+
19
+ ### 🏗️ Changed
20
+
21
+ - Updated dependencies in package.json for compatibility and security improvements
22
+
8
23
  ## 🔖 [2.2.2] (2025-10-17)
9
24
 
10
25
  ### 🏗️ Changed
@@ -69,6 +84,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
69
84
 
70
85
  <!-- Link References -->
71
86
 
87
+ [2.2.4]: https://github.com/aneuhold/ts-libs/compare/core-ts-api-lib-v2.2.3...core-ts-api-lib-v2.2.4
88
+ [2.2.3]: https://github.com/aneuhold/ts-libs/compare/core-ts-api-lib-v2.2.2...core-ts-api-lib-v2.2.3
72
89
  [2.2.2]: https://github.com/aneuhold/ts-libs/compare/core-ts-api-lib-v2.2.1...core-ts-api-lib-v2.2.2
73
90
  [2.2.1]: https://github.com/aneuhold/ts-libs/compare/core-ts-api-lib-v2.2.0...core-ts-api-lib-v2.2.1
74
91
  [2.2.0]: https://github.com/aneuhold/ts-libs/compare/core-ts-api-lib-v2.1.25...core-ts-api-lib-v2.2.0
@@ -95,7 +95,7 @@ export default abstract class DOFunction<TInput extends DOFunctionInput, TOutput
95
95
  *
96
96
  * @param input - The input to the function.
97
97
  * @returns A promise that resolves to the output of the function call, wrapped in {@link DOFunctionCallOutput}.
98
- * @throws Will throw an error if the URL is not set.
98
+ * @throws {Error} Will throw an error if the URL is not set.
99
99
  */
100
100
  call(input: TInput): Promise<APIResponse<TOutput>>;
101
101
  /**
@@ -43,7 +43,7 @@ export default class DOFunction {
43
43
  *
44
44
  * @param input - The input to the function.
45
45
  * @returns A promise that resolves to the output of the function call, wrapped in {@link DOFunctionCallOutput}.
46
- * @throws Will throw an error if the URL is not set.
46
+ * @throws {Error} Will throw an error if the URL is not set.
47
47
  */
48
48
  async call(input) {
49
49
  if (!this.url) {
@@ -56,7 +56,7 @@ export default class DOFunction {
56
56
  'Content-Type': 'application/octet-stream',
57
57
  Accept: 'application/octet-stream'
58
58
  },
59
- body: BSON.serialize(input)
59
+ body: Buffer.from(BSON.serialize(input))
60
60
  });
61
61
  return await this.decodeResponse(response);
62
62
  }
@@ -1 +1 @@
1
- {"version":3,"file":"DOFunction.js","sourceRoot":"","sources":["../../../src/services/DOFunctionService/DOFunction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAsE5B;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAc;IACjD,OAAO,CACL,CAAC,CAAC,KAAK;QACP,OAAO,KAAK,KAAK,QAAQ;QACzB,MAAM,IAAI,KAAK;QACf,OAAQ,KAA4B,CAAC,IAAI,KAAK,QAAQ;QACtD,MAAM,IAAK,KAA4B,CAAC,IAAI,IAAI,sCAAsC;QACtF,iBAAiB,IAAK,KAA4B,CAAC,IAAI,CACxD,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,OAAO,OAAgB,UAAU;IAItC;;OAEG;IACO,GAAG,CAAU;IAEb,YAAY,CAAS;IAE/B;QACE,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IAC5C,CAAC;IAED;;;;OAIG;IACH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ACJ,CAAC;IACH,CAAC;CACF"}
1
+ {"version":3,"file":"DOFunction.js","sourceRoot":"","sources":["../../../src/services/DOFunctionService/DOFunction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAsE5B;;;;;GAKG;AACH,MAAM,UAAU,oBAAoB,CAAC,KAAc;IACjD,OAAO,CACL,CAAC,CAAC,KAAK;QACP,OAAO,KAAK,KAAK,QAAQ;QACzB,MAAM,IAAI,KAAK;QACf,OAAQ,KAA4B,CAAC,IAAI,KAAK,QAAQ;QACtD,MAAM,IAAK,KAA4B,CAAC,IAAI,IAAI,sCAAsC;QACtF,iBAAiB,IAAK,KAA4B,CAAC,IAAI,CACxD,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,OAAO,OAAgB,UAAU;IAItC;;OAEG;IACO,GAAG,CAAU;IAEb,YAAY,CAAS;IAE/B;QACE,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC;IAC5C,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,GAAW;QAChB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;IACjB,CAAC;IAED;;;;;;;;OAQG;IACH,KAAK,CAAC,IAAI,CAAC,KAAa;QACtB,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,CAAC,YAAY,iBAAiB,CAAC,CAAC;QACzD,CAAC;QACD,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE;YACrC,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,UAAU,EAAE,YAAY;gBACxB,cAAc,EAAE,0BAA0B;gBAC1C,MAAM,EAAE,0BAA0B;aACnC;YACD,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;SACzC,CAAC,CAAC;QACH,OAAO,MAAM,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;IAC7C,CAAC;IAED;;;;;OAKG;IACK,KAAK,CAAC,cAAc,CAAC,QAAkB;QAC7C,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,KAAK,0BAA0B,CAAC;QACnF,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAC;YAC5C,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;YAC1C,OAAO,IAAI,CAAC,WAAW,CAAC,UAAU,CAAyB,CAAC;QAC9D,CAAC;aAAM,CAAC;YACN,kDAAkD;YAClD,MAAM,MAAM,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAY,CAAC;YAClD,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;gBACzC,IAAI,EAAE,EAAa;aACpB,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
@@ -122,7 +122,7 @@ export default abstract class DOFunction<
122
122
  *
123
123
  * @param input - The input to the function.
124
124
  * @returns A promise that resolves to the output of the function call, wrapped in {@link DOFunctionCallOutput}.
125
- * @throws Will throw an error if the URL is not set.
125
+ * @throws {Error} Will throw an error if the URL is not set.
126
126
  */
127
127
  async call(input: TInput): Promise<APIResponse<TOutput>> {
128
128
  if (!this.url) {
@@ -135,7 +135,7 @@ export default abstract class DOFunction<
135
135
  'Content-Type': 'application/octet-stream',
136
136
  Accept: 'application/octet-stream'
137
137
  },
138
- body: BSON.serialize(input)
138
+ body: Buffer.from(BSON.serialize(input))
139
139
  });
140
140
  return await this.decodeResponse(response);
141
141
  }
@@ -22,9 +22,15 @@ export default class GCloudAPIService {
22
22
  *
23
23
  * @param urlPath - The path to the endpoint.
24
24
  * @param input - The input to the endpoint.
25
- * @returns A promise that resolves to the output of the function call, wrapped in {@link APIResponse}.
26
- * @throws Will throw an error if the URL is not set.
25
+ * @throws {Error} Will throw an error if the URL is not set.
27
26
  */
28
27
  private static call;
28
+ /**
29
+ * Decodes the response from the Google Cloud API.
30
+ *
31
+ * @param response - The response to decode.
32
+ * @returns The decoded output.
33
+ */
34
+ private static decodeResponse;
29
35
  }
30
36
  //# sourceMappingURL=GCloudAPIService.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"GCloudAPIService.d.ts","sourceRoot":"","sources":["../../../src/services/GCloudAPIService/GCloudAPIService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACvB,MAAM,oDAAoD,CAAC;AAE5D;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,gBAAgB;;IAOnC;;;;OAIG;IACH,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAIhC;;;;OAIG;WACU,gBAAgB,CAC3B,KAAK,EAAE,qBAAqB,GAC3B,OAAO,CAAC,WAAW,CAAC,sBAAsB,CAAC,CAAC;IAI/C;;;;;;;OAOG;mBACkB,IAAI;CAoC1B"}
1
+ {"version":3,"file":"GCloudAPIService.d.ts","sourceRoot":"","sources":["../../../src/services/GCloudAPIService/GCloudAPIService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACzD,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACvB,MAAM,oDAAoD,CAAC;AAE5D;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,gBAAgB;;IAOnC;;;;OAIG;IACH,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI;IAIhC;;;;OAIG;WACU,gBAAgB,CAC3B,KAAK,EAAE,qBAAqB,GAC3B,OAAO,CAAC,WAAW,CAAC,sBAAsB,CAAC,CAAC;IAI/C;;;;;;OAMG;mBACkB,IAAI;IAqBzB;;;;;OAKG;mBACkB,cAAc;CAiBpC"}
@@ -1,3 +1,4 @@
1
+ import { BSON } from 'bson';
1
2
  /**
2
3
  * A service for interacting with the Google Cloud API service for personal projects.
3
4
  */
@@ -28,8 +29,7 @@ export default class GCloudAPIService {
28
29
  *
29
30
  * @param urlPath - The path to the endpoint.
30
31
  * @param input - The input to the endpoint.
31
- * @returns A promise that resolves to the output of the function call, wrapped in {@link APIResponse}.
32
- * @throws Will throw an error if the URL is not set.
32
+ * @throws {Error} Will throw an error if the URL is not set.
33
33
  */
34
34
  static async call(urlPath, input) {
35
35
  if (!this.#baseUrl) {
@@ -38,26 +38,35 @@ export default class GCloudAPIService {
38
38
  const response = await fetch(this.#baseUrl + urlPath, {
39
39
  method: 'POST',
40
40
  headers: {
41
- 'Content-Type': 'application/json',
42
- Accept: 'application/json'
41
+ Connection: 'keep-alive',
42
+ 'Content-Type': 'application/octet-stream',
43
+ Accept: 'application/octet-stream'
43
44
  },
44
- body: JSON.stringify(input)
45
+ body: Buffer.from(BSON.serialize(input))
45
46
  });
46
- if (!response.ok) {
47
- return {
48
- success: false,
49
- errors: [`HTTP ${response.status}: ${response.statusText}`],
50
- data: {}
51
- };
47
+ const decodedResponse = await this.decodeResponse(response);
48
+ return decodedResponse;
49
+ }
50
+ /**
51
+ * Decodes the response from the Google Cloud API.
52
+ *
53
+ * @param response - The response to decode.
54
+ * @returns The decoded output.
55
+ */
56
+ static async decodeResponse(response) {
57
+ const contentType = response.headers.get('Content-Type');
58
+ const isBson = contentType?.includes('application/octet-stream');
59
+ if (isBson) {
60
+ const buffer = await response.arrayBuffer();
61
+ const uint8Array = new Uint8Array(buffer);
62
+ return BSON.deserialize(uint8Array);
52
63
  }
53
- try {
64
+ else {
65
+ // This normally only happens if there is an error
54
66
  const result = (await response.json());
55
- return result;
56
- }
57
- catch (error) {
58
67
  return {
59
68
  success: false,
60
- errors: [`Failed to parse response: ${String(error)}`],
69
+ errors: [JSON.stringify(result, null, 2)],
61
70
  data: {}
62
71
  };
63
72
  }
@@ -1 +1 @@
1
- {"version":3,"file":"GCloudAPIService.js","sourceRoot":"","sources":["../../../src/services/GCloudAPIService/GCloudAPIService.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,gBAAgB;IACnC;;;OAGG;IACH,MAAM,CAAC,QAAQ,CAAU;IAEzB;;;;OAIG;IACH,MAAM,CAAC,MAAM,CAAC,GAAW;QACvB,IAAI,CAAC,QAAQ,GAAG,GAAG,CAAC;IACtB,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAC3B,KAA4B;QAE5B,OAAO,IAAI,CAAC,IAAI,CAAgD,mBAAmB,EAAE,KAAK,CAAC,CAAC;IAC9F,CAAC;IAED;;;;;;;OAOG;IACK,MAAM,CAAC,KAAK,CAAC,IAAI,CACvB,OAAe,EACf,KAAa;QAEb,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACnB,MAAM,IAAI,KAAK,CAAC,0BAA0B,CAAC,CAAC;QAC9C,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,QAAQ,GAAG,OAAO,EAAE;YACpD,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,kBAAkB;gBAClC,MAAM,EAAE,kBAAkB;aAC3B;YACD,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;SAC5B,CAAC,CAAC;QAEH,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;YACjB,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,CAAC,QAAQ,QAAQ,CAAC,MAAM,KAAK,QAAQ,CAAC,UAAU,EAAE,CAAC;gBAC3D,IAAI,EAAE,EAAa;aACpB,CAAC;QACJ,CAAC;QAED,IAAI,CAAC;YACH,MAA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C,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;SACzC,CAAC,CAAC;QACH,MAAM,eAAe,GAAG,MAAM,IAAI,CAAC,cAAc,CAAU,QAAQ,CAAC,CAAC;QACrE,OAAO,eAAe,CAAC;IACzB,CAAC;IAED;;;;;OAKG;IACK,MAAM,CAAC,KAAK,CAAC,cAAc,CAAU,QAAkB;QAC7D,MAAM,WAAW,GAAG,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QACzD,MAAM,MAAM,GAAG,WAAW,EAAE,QAAQ,CAAC,0BAA0B,CAAC,CAAC;QACjE,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,MAAM,GAAG,MAAM,QAAQ,CAAC,WAAW,EAAE,CAAC;YAC5C,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;YAC1C,OAAO,IAAI,CAAC,WAAW,CAAC,UAAU,CAAyB,CAAC;QAC9D,CAAC;aAAM,CAAC;YACN,kDAAkD;YAClD,MAAM,MAAM,GAAG,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAY,CAAC;YAClD,OAAO;gBACL,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;gBACzC,IAAI,EAAE,EAAa;aACpB,CAAC;QACJ,CAAC;IACH,CAAC;CACF"}
@@ -1,3 +1,4 @@
1
+ import { BSON } from 'bson';
1
2
  import { APIResponse } from '../../types/APIResponse.js';
2
3
  import {
3
4
  ProjectDashboardInput,
@@ -39,10 +40,9 @@ export default class GCloudAPIService {
39
40
  *
40
41
  * @param urlPath - The path to the endpoint.
41
42
  * @param input - The input to the endpoint.
42
- * @returns A promise that resolves to the output of the function call, wrapped in {@link APIResponse}.
43
- * @throws Will throw an error if the URL is not set.
43
+ * @throws {Error} Will throw an error if the URL is not set.
44
44
  */
45
- private static async call<TInput, TOutput>(
45
+ private static async call<TInput extends object, TOutput>(
46
46
  urlPath: string,
47
47
  input: TInput
48
48
  ): Promise<APIResponse<TOutput>> {
@@ -53,27 +53,35 @@ export default class GCloudAPIService {
53
53
  const response = await fetch(this.#baseUrl + urlPath, {
54
54
  method: 'POST',
55
55
  headers: {
56
- 'Content-Type': 'application/json',
57
- Accept: 'application/json'
56
+ Connection: 'keep-alive',
57
+ 'Content-Type': 'application/octet-stream',
58
+ Accept: 'application/octet-stream'
58
59
  },
59
- body: JSON.stringify(input)
60
+ body: Buffer.from(BSON.serialize(input))
60
61
  });
62
+ const decodedResponse = await this.decodeResponse<TOutput>(response);
63
+ return decodedResponse;
64
+ }
61
65
 
62
- if (!response.ok) {
63
- return {
64
- success: false,
65
- errors: [`HTTP ${response.status}: ${response.statusText}`],
66
- data: {} as TOutput
67
- };
68
- }
69
-
70
- try {
71
- const result = (await response.json()) as APIResponse<TOutput>;
72
- return result;
73
- } catch (error) {
66
+ /**
67
+ * Decodes the response from the Google Cloud API.
68
+ *
69
+ * @param response - The response to decode.
70
+ * @returns The decoded output.
71
+ */
72
+ private static async decodeResponse<TOutput>(response: Response): Promise<APIResponse<TOutput>> {
73
+ const contentType = response.headers.get('Content-Type');
74
+ const isBson = contentType?.includes('application/octet-stream');
75
+ if (isBson) {
76
+ const buffer = await response.arrayBuffer();
77
+ const uint8Array = new Uint8Array(buffer);
78
+ return BSON.deserialize(uint8Array) as APIResponse<TOutput>;
79
+ } else {
80
+ // This normally only happens if there is an error
81
+ const result = (await response.json()) as unknown;
74
82
  return {
75
83
  success: false,
76
- errors: [`Failed to parse response: ${String(error)}`],
84
+ errors: [JSON.stringify(result, null, 2)],
77
85
  data: {} as TOutput
78
86
  };
79
87
  }
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@aneuhold/core-ts-api-lib",
3
3
  "author": "Anton G. Neuhold Jr.",
4
4
  "license": "MIT",
5
- "version": "2.2.2",
5
+ "version": "2.2.4",
6
6
  "description": "A library for interacting with the backend and defining the backend API for personal projects.",
7
7
  "packageManager": "pnpm@10.12.1",
8
8
  "type": "module",
@@ -51,18 +51,18 @@
51
51
  "dependencies": {
52
52
  "@aneuhold/core-ts-db-lib": "*",
53
53
  "@aneuhold/core-ts-lib": "*",
54
- "bson": "^6.2.0"
54
+ "bson": "^6.10.4"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@aneuhold/local-npm-registry": "*",
58
- "@aneuhold/main-scripts": "^2.5.2",
59
- "@types/node": "^22.15.32",
60
- "eslint": "^9.29.0",
61
- "jsr": "^0.13.4",
62
- "prettier": "^3.5.3",
58
+ "@aneuhold/main-scripts": "^2.6.1",
59
+ "@types/node": "^24.9.1",
60
+ "eslint": "^9.38.0",
61
+ "jsr": "^0.13.5",
62
+ "prettier": "^3.6.2",
63
63
  "rimraf": "^6.0.1",
64
- "tsx": "^4.20.3",
65
- "typescript": "^5.8.3",
66
- "vitest": "^3.2.4"
64
+ "tsx": "^4.20.6",
65
+ "typescript": "^5.9.3",
66
+ "vitest": "^4.0.3"
67
67
  }
68
68
  }