@aneuhold/core-ts-api-lib 2.2.3 → 2.2.5
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 +14 -4
- package/lib/browser.d.ts +12 -0
- package/lib/browser.d.ts.map +1 -0
- package/lib/browser.js +5 -0
- package/lib/browser.js.map +1 -0
- package/lib/browser.ts +42 -0
- package/lib/index.d.ts +1 -11
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +3 -4
- package/lib/index.js.map +1 -1
- package/lib/index.ts +3 -42
- package/lib/services/GCloudAPIService/GCloudAPIService.d.ts +8 -2
- package/lib/services/GCloudAPIService/GCloudAPIService.d.ts.map +1 -1
- package/lib/services/GCloudAPIService/GCloudAPIService.js +25 -16
- package/lib/services/GCloudAPIService/GCloudAPIService.js.map +1 -1
- package/lib/services/GCloudAPIService/GCloudAPIService.ts +27 -19
- package/package.json +20 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,17 +5,26 @@ 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.
|
|
8
|
+
## 🔖 [2.2.5] (2025-11-04)
|
|
9
9
|
|
|
10
10
|
### 🏗️ Changed
|
|
11
11
|
|
|
12
|
-
-
|
|
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`
|
|
13
16
|
|
|
14
|
-
## 🔖 [2.2.
|
|
17
|
+
## 🔖 [2.2.5] (2025-11-04)
|
|
18
|
+
|
|
19
|
+
### ✅ Added
|
|
20
|
+
|
|
21
|
+
- New browser-safe bundle: added src/browser.ts and updated exports for browser/node compatibility.
|
|
15
22
|
|
|
16
23
|
### 🏗️ Changed
|
|
17
24
|
|
|
18
|
-
-
|
|
25
|
+
- Refactored exports in package.json for browser/node/default support.
|
|
26
|
+
- Marked package as side-effect free in package.json ("sideEffects": false).
|
|
27
|
+
- Refactored src/index.ts to re-export from browser.ts.
|
|
19
28
|
|
|
20
29
|
## 🔖 [2.2.1] (2025-09-08)
|
|
21
30
|
|
|
@@ -75,6 +84,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
|
|
|
75
84
|
|
|
76
85
|
<!-- Link References -->
|
|
77
86
|
|
|
87
|
+
[2.2.5]: https://github.com/aneuhold/ts-libs/compare/core-ts-api-lib-v2.2.3...core-ts-api-lib-v2.2.5
|
|
78
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
|
|
79
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
|
|
80
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
|
package/lib/browser.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import APIService from './services/APIService/APIService.js';
|
|
2
|
+
import { DOFunctionRawInput, DOFunctionRawOutput } from './services/DOFunctionService/DOFunction.js';
|
|
3
|
+
import DOFunctionService from './services/DOFunctionService/DOFunctionService.js';
|
|
4
|
+
import { AuthCheckPasswordInput, AuthCheckPasswordOutput } from './services/DOFunctionService/functions/authCheckPassword.js';
|
|
5
|
+
import { AuthValidateUserInput, AuthValidateUserOutput } from './services/DOFunctionService/functions/authValidateUser.js';
|
|
6
|
+
import { ProjectDashboardInput, ProjectDashboardOptions, ProjectDashboardOutput } from './services/DOFunctionService/functions/projectDashboard.js';
|
|
7
|
+
import { APIResponse } from './types/APIResponse.js';
|
|
8
|
+
import { DashboardConfig } from './types/DashboardConfig.js';
|
|
9
|
+
import { Translation, Translations } from './types/Translations.js';
|
|
10
|
+
export { APIService, DOFunctionService };
|
|
11
|
+
export type { APIResponse, AuthCheckPasswordInput, AuthCheckPasswordOutput, AuthValidateUserInput, AuthValidateUserOutput, DashboardConfig, DOFunctionRawInput, DOFunctionRawOutput, ProjectDashboardInput, ProjectDashboardOptions, ProjectDashboardOutput, Translation, Translations };
|
|
12
|
+
//# sourceMappingURL=browser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EACL,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,4CAA4C,CAAC;AACpD,OAAO,iBAAiB,MAAM,mDAAmD,CAAC;AAClF,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACxB,MAAM,6DAA6D,CAAC;AACrE,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACvB,MAAM,4DAA4D,CAAC;AACpE,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,4DAA4D,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAGpE,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,CAAC;AAGzC,YAAY,EACV,WAAW,EACX,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,sBAAsB,EACtB,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,WAAW,EACX,YAAY,EACb,CAAC"}
|
package/lib/browser.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import APIService from './services/APIService/APIService.js';
|
|
2
|
+
import DOFunctionService from './services/DOFunctionService/DOFunctionService.js';
|
|
3
|
+
// Export all browser-safe functions and classes from this library
|
|
4
|
+
export { APIService, DOFunctionService };
|
|
5
|
+
//# sourceMappingURL=browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser.js","sourceRoot":"","sources":["../src/browser.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,qCAAqC,CAAC;AAK7D,OAAO,iBAAiB,MAAM,mDAAmD,CAAC;AAkBlF,kEAAkE;AAClE,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,CAAC"}
|
package/lib/browser.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import APIService from './services/APIService/APIService.js';
|
|
2
|
+
import {
|
|
3
|
+
DOFunctionRawInput,
|
|
4
|
+
DOFunctionRawOutput
|
|
5
|
+
} from './services/DOFunctionService/DOFunction.js';
|
|
6
|
+
import DOFunctionService from './services/DOFunctionService/DOFunctionService.js';
|
|
7
|
+
import {
|
|
8
|
+
AuthCheckPasswordInput,
|
|
9
|
+
AuthCheckPasswordOutput
|
|
10
|
+
} from './services/DOFunctionService/functions/authCheckPassword.js';
|
|
11
|
+
import {
|
|
12
|
+
AuthValidateUserInput,
|
|
13
|
+
AuthValidateUserOutput
|
|
14
|
+
} from './services/DOFunctionService/functions/authValidateUser.js';
|
|
15
|
+
import {
|
|
16
|
+
ProjectDashboardInput,
|
|
17
|
+
ProjectDashboardOptions,
|
|
18
|
+
ProjectDashboardOutput
|
|
19
|
+
} from './services/DOFunctionService/functions/projectDashboard.js';
|
|
20
|
+
import { APIResponse } from './types/APIResponse.js';
|
|
21
|
+
import { DashboardConfig } from './types/DashboardConfig.js';
|
|
22
|
+
import { Translation, Translations } from './types/Translations.js';
|
|
23
|
+
|
|
24
|
+
// Export all browser-safe functions and classes from this library
|
|
25
|
+
export { APIService, DOFunctionService };
|
|
26
|
+
|
|
27
|
+
// Export TypeScript types where needed
|
|
28
|
+
export type {
|
|
29
|
+
APIResponse,
|
|
30
|
+
AuthCheckPasswordInput,
|
|
31
|
+
AuthCheckPasswordOutput,
|
|
32
|
+
AuthValidateUserInput,
|
|
33
|
+
AuthValidateUserOutput,
|
|
34
|
+
DashboardConfig,
|
|
35
|
+
DOFunctionRawInput,
|
|
36
|
+
DOFunctionRawOutput,
|
|
37
|
+
ProjectDashboardInput,
|
|
38
|
+
ProjectDashboardOptions,
|
|
39
|
+
ProjectDashboardOutput,
|
|
40
|
+
Translation,
|
|
41
|
+
Translations
|
|
42
|
+
};
|
package/lib/index.d.ts
CHANGED
|
@@ -1,12 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
import { DOFunctionRawInput, DOFunctionRawOutput } from './services/DOFunctionService/DOFunction.js';
|
|
3
|
-
import DOFunctionService from './services/DOFunctionService/DOFunctionService.js';
|
|
4
|
-
import { AuthCheckPasswordInput, AuthCheckPasswordOutput } from './services/DOFunctionService/functions/authCheckPassword.js';
|
|
5
|
-
import { AuthValidateUserInput, AuthValidateUserOutput } from './services/DOFunctionService/functions/authValidateUser.js';
|
|
6
|
-
import { ProjectDashboardInput, ProjectDashboardOptions, ProjectDashboardOutput } from './services/DOFunctionService/functions/projectDashboard.js';
|
|
7
|
-
import { APIResponse } from './types/APIResponse.js';
|
|
8
|
-
import { DashboardConfig } from './types/DashboardConfig.js';
|
|
9
|
-
import { Translation, Translations } from './types/Translations.js';
|
|
10
|
-
export { APIService, DOFunctionService };
|
|
11
|
-
export type { APIResponse, AuthCheckPasswordInput, AuthCheckPasswordOutput, AuthValidateUserInput, AuthValidateUserOutput, DashboardConfig, DOFunctionRawInput, DOFunctionRawOutput, ProjectDashboardInput, ProjectDashboardOptions, ProjectDashboardOutput, Translation, Translations };
|
|
1
|
+
export * from './browser.js';
|
|
12
2
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,cAAc,cAAc,CAAC"}
|
package/lib/index.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export { APIService, DOFunctionService };
|
|
1
|
+
// Export all browser-safe exports from browser.ts
|
|
2
|
+
// Since all exports in this library are browser-compatible, we simply re-export everything
|
|
3
|
+
export * from './browser.js';
|
|
5
4
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,2FAA2F;AAC3F,cAAc,cAAc,CAAC"}
|
package/lib/index.ts
CHANGED
|
@@ -1,42 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
DOFunctionRawOutput
|
|
5
|
-
} from './services/DOFunctionService/DOFunction.js';
|
|
6
|
-
import DOFunctionService from './services/DOFunctionService/DOFunctionService.js';
|
|
7
|
-
import {
|
|
8
|
-
AuthCheckPasswordInput,
|
|
9
|
-
AuthCheckPasswordOutput
|
|
10
|
-
} from './services/DOFunctionService/functions/authCheckPassword.js';
|
|
11
|
-
import {
|
|
12
|
-
AuthValidateUserInput,
|
|
13
|
-
AuthValidateUserOutput
|
|
14
|
-
} from './services/DOFunctionService/functions/authValidateUser.js';
|
|
15
|
-
import {
|
|
16
|
-
ProjectDashboardInput,
|
|
17
|
-
ProjectDashboardOptions,
|
|
18
|
-
ProjectDashboardOutput
|
|
19
|
-
} from './services/DOFunctionService/functions/projectDashboard.js';
|
|
20
|
-
import { APIResponse } from './types/APIResponse.js';
|
|
21
|
-
import { DashboardConfig } from './types/DashboardConfig.js';
|
|
22
|
-
import { Translation, Translations } from './types/Translations.js';
|
|
23
|
-
|
|
24
|
-
// Export all the functions and classes from this library
|
|
25
|
-
export { APIService, DOFunctionService };
|
|
26
|
-
|
|
27
|
-
// Export TypeScript types where needed
|
|
28
|
-
export type {
|
|
29
|
-
APIResponse,
|
|
30
|
-
AuthCheckPasswordInput,
|
|
31
|
-
AuthCheckPasswordOutput,
|
|
32
|
-
AuthValidateUserInput,
|
|
33
|
-
AuthValidateUserOutput,
|
|
34
|
-
DashboardConfig,
|
|
35
|
-
DOFunctionRawInput,
|
|
36
|
-
DOFunctionRawOutput,
|
|
37
|
-
ProjectDashboardInput,
|
|
38
|
-
ProjectDashboardOptions,
|
|
39
|
-
ProjectDashboardOutput,
|
|
40
|
-
Translation,
|
|
41
|
-
Translations
|
|
42
|
-
};
|
|
1
|
+
// Export all browser-safe exports from browser.ts
|
|
2
|
+
// Since all exports in this library are browser-compatible, we simply re-export everything
|
|
3
|
+
export * from './browser.js';
|
|
@@ -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
|
-
* @
|
|
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":"
|
|
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
|
-
* @
|
|
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
|
-
|
|
42
|
-
|
|
41
|
+
Connection: 'keep-alive',
|
|
42
|
+
'Content-Type': 'application/octet-stream',
|
|
43
|
+
Accept: 'application/octet-stream'
|
|
43
44
|
},
|
|
44
|
-
body:
|
|
45
|
+
body: Buffer.from(BSON.serialize(input))
|
|
45
46
|
});
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
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: [
|
|
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":"
|
|
1
|
+
{"version":3,"file":"GCloudAPIService.js","sourceRoot":"","sources":["../../../src/services/GCloudAPIService/GCloudAPIService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAO5B;;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;;;;;;OAMG;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,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,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
|
-
* @
|
|
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
|
-
|
|
57
|
-
|
|
56
|
+
Connection: 'keep-alive',
|
|
57
|
+
'Content-Type': 'application/octet-stream',
|
|
58
|
+
Accept: 'application/octet-stream'
|
|
58
59
|
},
|
|
59
|
-
body:
|
|
60
|
+
body: Buffer.from(BSON.serialize(input))
|
|
60
61
|
});
|
|
62
|
+
const decodedResponse = await this.decodeResponse<TOutput>(response);
|
|
63
|
+
return decodedResponse;
|
|
64
|
+
}
|
|
61
65
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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: [
|
|
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.
|
|
5
|
+
"version": "2.2.5",
|
|
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",
|
|
@@ -29,10 +29,29 @@
|
|
|
29
29
|
],
|
|
30
30
|
"exports": {
|
|
31
31
|
".": {
|
|
32
|
+
"browser": {
|
|
33
|
+
"types": "./lib/browser.d.ts",
|
|
34
|
+
"import": "./lib/browser.js"
|
|
35
|
+
},
|
|
36
|
+
"node": {
|
|
37
|
+
"types": "./lib/index.d.ts",
|
|
38
|
+
"import": "./lib/index.js"
|
|
39
|
+
},
|
|
40
|
+
"default": {
|
|
41
|
+
"types": "./lib/browser.d.ts",
|
|
42
|
+
"import": "./lib/browser.js"
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"./browser": {
|
|
46
|
+
"types": "./lib/browser.d.ts",
|
|
47
|
+
"import": "./lib/browser.js"
|
|
48
|
+
},
|
|
49
|
+
"./node": {
|
|
32
50
|
"types": "./lib/index.d.ts",
|
|
33
51
|
"import": "./lib/index.js"
|
|
34
52
|
}
|
|
35
53
|
},
|
|
54
|
+
"sideEffects": false,
|
|
36
55
|
"repository": {
|
|
37
56
|
"type": "git",
|
|
38
57
|
"url": "git+https://github.com/aneuhold/ts-libs.git",
|