@aneuhold/core-ts-api-lib 1.0.119 → 2.0.1

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.
Files changed (46) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +48 -3
  3. package/lib/index.d.ts +10 -10
  4. package/lib/index.d.ts.map +1 -1
  5. package/lib/index.js +5 -10
  6. package/lib/index.js.map +1 -0
  7. package/lib/index.ts +42 -0
  8. package/lib/services/APIService/APIService.d.ts +16 -4
  9. package/lib/services/APIService/APIService.d.ts.map +1 -1
  10. package/lib/services/APIService/APIService.js +17 -11
  11. package/lib/services/APIService/APIService.js.map +1 -0
  12. package/lib/services/APIService/APIService.ts +53 -0
  13. package/lib/services/DOFunctionService/DOFunction.d.ts +24 -0
  14. package/lib/services/DOFunctionService/DOFunction.d.ts.map +1 -1
  15. package/lib/services/DOFunctionService/DOFunction.js +35 -7
  16. package/lib/services/DOFunctionService/DOFunction.js.map +1 -0
  17. package/lib/services/DOFunctionService/DOFunction.ts +137 -0
  18. package/lib/services/DOFunctionService/DOFunctionService.d.ts +30 -5
  19. package/lib/services/DOFunctionService/DOFunctionService.d.ts.map +1 -1
  20. package/lib/services/DOFunctionService/DOFunctionService.js +36 -16
  21. package/lib/services/DOFunctionService/DOFunctionService.js.map +1 -0
  22. package/lib/services/DOFunctionService/DOFunctionService.ts +105 -0
  23. package/lib/services/DOFunctionService/functions/authCheckPassword.d.ts +17 -1
  24. package/lib/services/DOFunctionService/functions/authCheckPassword.d.ts.map +1 -1
  25. package/lib/services/DOFunctionService/functions/authCheckPassword.js +13 -8
  26. package/lib/services/DOFunctionService/functions/authCheckPassword.js.map +1 -0
  27. package/lib/services/DOFunctionService/functions/authCheckPassword.ts +48 -0
  28. package/lib/services/DOFunctionService/functions/authValidateUser.d.ts +32 -2
  29. package/lib/services/DOFunctionService/functions/authValidateUser.d.ts.map +1 -1
  30. package/lib/services/DOFunctionService/functions/authValidateUser.js +18 -8
  31. package/lib/services/DOFunctionService/functions/authValidateUser.js.map +1 -0
  32. package/lib/services/DOFunctionService/functions/authValidateUser.ts +74 -0
  33. package/lib/services/DOFunctionService/functions/projectDashboard.d.ts +52 -4
  34. package/lib/services/DOFunctionService/functions/projectDashboard.d.ts.map +1 -1
  35. package/lib/services/DOFunctionService/functions/projectDashboard.js +3 -8
  36. package/lib/services/DOFunctionService/functions/projectDashboard.js.map +1 -0
  37. package/lib/services/DOFunctionService/functions/projectDashboard.ts +127 -0
  38. package/lib/types/DashboardConfig.d.ts.map +1 -1
  39. package/lib/types/DashboardConfig.js +2 -2
  40. package/lib/types/DashboardConfig.js.map +1 -0
  41. package/lib/types/DashboardConfig.ts +14 -0
  42. package/lib/types/Translations.d.ts.map +1 -1
  43. package/lib/types/Translations.js +2 -2
  44. package/lib/types/Translations.js.map +1 -0
  45. package/lib/types/Translations.ts +14 -0
  46. package/package.json +36 -29
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) [2024] [Anton G Neuhold Jr]
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,5 +1,50 @@
1
- # Core TypeScript API Library
1
+ # Personal Core API Library
2
2
 
3
- ![npm](https://img.shields.io/npm/v/%40aneuhold%2Fcore-ts-api-lib)
3
+ [![JSR](https://jsr.io/badges/@aneuhold/core-ts-api-lib)](https://jsr.io/@aneuhold/core-ts-api-lib)
4
+ [![NPM](https://img.shields.io/npm/v/%40aneuhold%2Fcore-ts-api-lib)](https://www.npmjs.com/package/@aneuhold/core-ts-api-lib)
4
5
 
5
- A core library for interacting with and defining the backend API for personal projects. This can be pulled in to any frontend or backend personal project.
6
+ A library for interacting with the backend and defining the backend API for personal projects.
7
+
8
+ ## 📦 Installation
9
+
10
+ To add to a repo, follow the instructions below for your environment:
11
+
12
+ ### For Node using NPM
13
+
14
+ Run `yarn add @aneuhold/core-ts-api-lib`
15
+
16
+ ### For Node using JSR
17
+
18
+ The below instructions still allow for things like Renovate to work, and normal commands with yarn such as `yarn up`.
19
+
20
+ 1. Add the required JSR configuration to a `.yarnrc.yml` file if not there already:
21
+ ```yml
22
+ npmScopes:
23
+ jsr:
24
+ npmRegistryServer: 'https://npm.jsr.io'
25
+ ```
26
+ 1. Add the package with `yarn add @jsr/aneuhold__core-ts-api-lib`
27
+
28
+ ### For Deno
29
+
30
+ Run `deno add jsr:@aneuhold/core-ts-api-lib`
31
+
32
+ ## 🟢 Usage
33
+
34
+ Pull in one of the services and use it like so:
35
+
36
+ ```ts
37
+ import { APIService } from '@aneuhold/core-ts-api-lib';
38
+ // If using Node with JSR
39
+ // import { APIService } from '@jsr/aneuhold__core-ts-api-lib';
40
+
41
+ export default async function validateUser() {
42
+ const userInfo = await APIService.validateUser({
43
+ username: 'user',
44
+ password: 'pass'
45
+ });
46
+ console.log(userInfo);
47
+ }
48
+ ```
49
+
50
+ [See full documentation on usage at JSR!](https://jsr.io/@aneuhold/core-ts-api-lib/doc)
package/lib/index.d.ts CHANGED
@@ -1,11 +1,11 @@
1
- import APIService from './services/APIService/APIService';
2
- import { DOFunctionCallOutput, DOFunctionRawInput, DOFunctionRawOutput } from './services/DOFunctionService/DOFunction';
3
- import DOFunctionService from './services/DOFunctionService/DOFunctionService';
4
- import { AuthCheckPasswordInput, AuthCheckPasswordOutput } from './services/DOFunctionService/functions/authCheckPassword';
5
- import { AuthValidateUserInput, AuthValidateUserOutput } from './services/DOFunctionService/functions/authValidateUser';
6
- import { ProjectDashboardInput, ProjectDashboardOptions, ProjectDashboardOutput } from './services/DOFunctionService/functions/projectDashboard';
7
- import { DashboardConfig } from './types/DashboardConfig';
8
- import { Translation, Translations } from './types/Translations';
9
- export { DOFunctionService, APIService };
10
- export type { DOFunctionRawInput, DOFunctionRawOutput, DOFunctionCallOutput, AuthCheckPasswordInput, AuthCheckPasswordOutput, AuthValidateUserInput, AuthValidateUserOutput, ProjectDashboardInput, ProjectDashboardOutput, ProjectDashboardOptions, DashboardConfig, Translations, Translation };
1
+ import APIService from './services/APIService/APIService.js';
2
+ import { DOFunctionCallOutput, 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 { DashboardConfig } from './types/DashboardConfig.js';
8
+ import { Translation, Translations } from './types/Translations.js';
9
+ export { APIService, DOFunctionService };
10
+ export type { AuthCheckPasswordInput, AuthCheckPasswordOutput, AuthValidateUserInput, AuthValidateUserOutput, DashboardConfig, DOFunctionCallOutput, DOFunctionRawInput, DOFunctionRawOutput, ProjectDashboardInput, ProjectDashboardOptions, ProjectDashboardOutput, Translation, Translations };
11
11
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,kCAAkC,CAAC;AAC1D,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,yCAAyC,CAAC;AACjD,OAAO,iBAAiB,MAAM,gDAAgD,CAAC;AAC/E,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACxB,MAAM,0DAA0D,CAAC;AAClE,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACvB,MAAM,yDAAyD,CAAC;AACjE,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,yDAAyD,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAGjE,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,CAAC;AAGzC,YAAY,EACV,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,EACtB,uBAAuB,EACvB,eAAe,EACf,YAAY,EACZ,WAAW,EACZ,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"./src/","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,qCAAqC,CAAC;AAC7D,OAAO,EACL,oBAAoB,EACpB,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,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,sBAAsB,EACtB,uBAAuB,EACvB,qBAAqB,EACrB,sBAAsB,EACtB,eAAe,EACf,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,WAAW,EACX,YAAY,EACb,CAAC"}
package/lib/index.js CHANGED
@@ -1,10 +1,5 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.APIService = exports.DOFunctionService = void 0;
7
- const APIService_1 = __importDefault(require("./services/APIService/APIService"));
8
- exports.APIService = APIService_1.default;
9
- const DOFunctionService_1 = __importDefault(require("./services/DOFunctionService/DOFunctionService"));
10
- exports.DOFunctionService = DOFunctionService_1.default;
1
+ import APIService from './services/APIService/APIService.js';
2
+ import DOFunctionService from './services/DOFunctionService/DOFunctionService.js';
3
+ // Export all the functions and classes from this library
4
+ export { APIService, DOFunctionService };
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"./src/","sources":["index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,qCAAqC,CAAC;AAM7D,OAAO,iBAAiB,MAAM,mDAAmD,CAAC;AAiBlF,yDAAyD;AACzD,OAAO,EAAE,UAAU,EAAE,iBAAiB,EAAE,CAAC"}
package/lib/index.ts ADDED
@@ -0,0 +1,42 @@
1
+ import APIService from './services/APIService/APIService.js';
2
+ import {
3
+ DOFunctionCallOutput,
4
+ DOFunctionRawInput,
5
+ DOFunctionRawOutput
6
+ } from './services/DOFunctionService/DOFunction.js';
7
+ import DOFunctionService from './services/DOFunctionService/DOFunctionService.js';
8
+ import {
9
+ AuthCheckPasswordInput,
10
+ AuthCheckPasswordOutput
11
+ } from './services/DOFunctionService/functions/authCheckPassword.js';
12
+ import {
13
+ AuthValidateUserInput,
14
+ AuthValidateUserOutput
15
+ } from './services/DOFunctionService/functions/authValidateUser.js';
16
+ import {
17
+ ProjectDashboardInput,
18
+ ProjectDashboardOptions,
19
+ ProjectDashboardOutput
20
+ } from './services/DOFunctionService/functions/projectDashboard.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
+ AuthCheckPasswordInput,
30
+ AuthCheckPasswordOutput,
31
+ AuthValidateUserInput,
32
+ AuthValidateUserOutput,
33
+ DashboardConfig,
34
+ DOFunctionCallOutput,
35
+ DOFunctionRawInput,
36
+ DOFunctionRawOutput,
37
+ ProjectDashboardInput,
38
+ ProjectDashboardOptions,
39
+ ProjectDashboardOutput,
40
+ Translation,
41
+ Translations
42
+ };
@@ -1,5 +1,6 @@
1
- import { AuthValidateUserInput } from '../DOFunctionService/functions/authValidateUser';
2
- import { ProjectDashboardInput } from '../DOFunctionService/functions/projectDashboard';
1
+ import { DOFunctionCallOutput } from '../DOFunctionService/DOFunction.js';
2
+ import { AuthValidateUserInput, AuthValidateUserOutput } from '../DOFunctionService/functions/authValidateUser.js';
3
+ import { ProjectDashboardInput, ProjectDashboardOutput } from '../DOFunctionService/functions/projectDashboard.js';
3
4
  /**
4
5
  * A service for making calls to the backend API for personal projects. This is
5
6
  * abstracted so that the backend implementation can change over time.
@@ -8,13 +9,24 @@ export default class APIService {
8
9
  /**
9
10
  * Validates the provided username and password against the database and
10
11
  * returns the user's information if successful.
12
+ *
13
+ * @param input - The input containing username and password.
14
+ * @returns A promise that resolves to the user's information if validation is successful.
15
+ */
16
+ static validateUser(input: AuthValidateUserInput): Promise<DOFunctionCallOutput<AuthValidateUserOutput>>;
17
+ /**
18
+ * Sets the URL for the dashboard API.
19
+ *
20
+ * @param url - The URL to be set for the dashboard API.
11
21
  */
12
- static validateUser(input: AuthValidateUserInput): Promise<import("../..").DOFunctionCallOutput<import("../DOFunctionService/functions/authValidateUser").AuthValidateUserOutput>>;
13
22
  static setDashboardAPIUrl(url: string): void;
14
23
  /**
15
24
  * Calls the dashboard API and returns the result. This will fail if the
16
25
  * dashboard API URL has not been set. See {@link setDashboardAPIUrl}.
26
+ *
27
+ * @param input - The input for the dashboard API call.
28
+ * @returns A promise that resolves to the result of the dashboard API call.
17
29
  */
18
- static callDashboardAPI(input: ProjectDashboardInput): Promise<import("../..").DOFunctionCallOutput<import("../DOFunctionService/functions/projectDashboard").ProjectDashboardOutput>>;
30
+ static callDashboardAPI(input: ProjectDashboardInput): Promise<DOFunctionCallOutput<ProjectDashboardOutput>>;
19
31
  }
20
32
  //# sourceMappingURL=APIService.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"APIService.d.ts","sourceRoot":"","sources":["../../../src/services/APIService/APIService.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,iDAAiD,CAAC;AACxF,OAAO,EAAE,qBAAqB,EAAE,MAAM,iDAAiD,CAAC;AAExF;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B;;;OAGG;WACU,YAAY,CAAC,KAAK,EAAE,qBAAqB;IAKtD,MAAM,CAAC,kBAAkB,CAAC,GAAG,EAAE,MAAM;IAIrC;;;OAGG;WACU,gBAAgB,CAAC,KAAK,EAAE,qBAAqB;CAI3D"}
1
+ {"version":3,"file":"APIService.d.ts","sourceRoot":"./src/","sources":["services/APIService/APIService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAE1E,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACvB,MAAM,oDAAoD,CAAC;AAC5D,OAAO,EACL,qBAAqB,EACrB,sBAAsB,EACvB,MAAM,oDAAoD,CAAC;AAE5D;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B;;;;;;OAMG;WACU,YAAY,CACvB,KAAK,EAAE,qBAAqB,GAC3B,OAAO,CAAC,oBAAoB,CAAC,sBAAsB,CAAC,CAAC;IAKxD;;;;OAIG;IACH,MAAM,CAAC,kBAAkB,CAAC,GAAG,EAAE,MAAM;IAIrC;;;;;;OAMG;WACU,gBAAgB,CAC3B,KAAK,EAAE,qBAAqB,GAC3B,OAAO,CAAC,oBAAoB,CAAC,sBAAsB,CAAC,CAAC;CAIzD"}
@@ -1,32 +1,38 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- const DOFunctionService_1 = __importDefault(require("../DOFunctionService/DOFunctionService"));
1
+ import DOFunctionService from '../DOFunctionService/DOFunctionService.js';
7
2
  /**
8
3
  * A service for making calls to the backend API for personal projects. This is
9
4
  * abstracted so that the backend implementation can change over time.
10
5
  */
11
- class APIService {
6
+ export default class APIService {
12
7
  /**
13
8
  * Validates the provided username and password against the database and
14
9
  * returns the user's information if successful.
10
+ *
11
+ * @param input - The input containing username and password.
12
+ * @returns A promise that resolves to the user's information if validation is successful.
15
13
  */
16
14
  static async validateUser(input) {
17
- const result = await DOFunctionService_1.default.authValidateUser.call(input);
15
+ const result = await DOFunctionService.authValidateUser.call(input);
18
16
  return result;
19
17
  }
18
+ /**
19
+ * Sets the URL for the dashboard API.
20
+ *
21
+ * @param url - The URL to be set for the dashboard API.
22
+ */
20
23
  static setDashboardAPIUrl(url) {
21
- DOFunctionService_1.default.projectDashboard.setUrl(url);
24
+ DOFunctionService.projectDashboard.setUrl(url);
22
25
  }
23
26
  /**
24
27
  * Calls the dashboard API and returns the result. This will fail if the
25
28
  * dashboard API URL has not been set. See {@link setDashboardAPIUrl}.
29
+ *
30
+ * @param input - The input for the dashboard API call.
31
+ * @returns A promise that resolves to the result of the dashboard API call.
26
32
  */
27
33
  static async callDashboardAPI(input) {
28
- const result = await DOFunctionService_1.default.projectDashboard.call(input);
34
+ const result = await DOFunctionService.projectDashboard.call(input);
29
35
  return result;
30
36
  }
31
37
  }
32
- exports.default = APIService;
38
+ //# sourceMappingURL=APIService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"APIService.js","sourceRoot":"./src/","sources":["services/APIService/APIService.ts"],"names":[],"mappings":"AACA,OAAO,iBAAiB,MAAM,2CAA2C,CAAC;AAU1E;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU;IAC7B;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,CAAC,YAAY,CACvB,KAA4B;QAE5B,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACpE,OAAO,MAAM,CAAC;IAChB,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,kBAAkB,CAAC,GAAW;QACnC,iBAAiB,CAAC,gBAAgB,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IACjD,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAC3B,KAA4B;QAE5B,MAAM,MAAM,GAAG,MAAM,iBAAiB,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACpE,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
@@ -0,0 +1,53 @@
1
+ import { DOFunctionCallOutput } from '../DOFunctionService/DOFunction.js';
2
+ import DOFunctionService from '../DOFunctionService/DOFunctionService.js';
3
+ import {
4
+ AuthValidateUserInput,
5
+ AuthValidateUserOutput
6
+ } from '../DOFunctionService/functions/authValidateUser.js';
7
+ import {
8
+ ProjectDashboardInput,
9
+ ProjectDashboardOutput
10
+ } from '../DOFunctionService/functions/projectDashboard.js';
11
+
12
+ /**
13
+ * A service for making calls to the backend API for personal projects. This is
14
+ * abstracted so that the backend implementation can change over time.
15
+ */
16
+ export default class APIService {
17
+ /**
18
+ * Validates the provided username and password against the database and
19
+ * returns the user's information if successful.
20
+ *
21
+ * @param input - The input containing username and password.
22
+ * @returns A promise that resolves to the user's information if validation is successful.
23
+ */
24
+ static async validateUser(
25
+ input: AuthValidateUserInput
26
+ ): Promise<DOFunctionCallOutput<AuthValidateUserOutput>> {
27
+ const result = await DOFunctionService.authValidateUser.call(input);
28
+ return result;
29
+ }
30
+
31
+ /**
32
+ * Sets the URL for the dashboard API.
33
+ *
34
+ * @param url - The URL to be set for the dashboard API.
35
+ */
36
+ static setDashboardAPIUrl(url: string) {
37
+ DOFunctionService.projectDashboard.setUrl(url);
38
+ }
39
+
40
+ /**
41
+ * Calls the dashboard API and returns the result. This will fail if the
42
+ * dashboard API URL has not been set. See {@link setDashboardAPIUrl}.
43
+ *
44
+ * @param input - The input for the dashboard API call.
45
+ * @returns A promise that resolves to the result of the dashboard API call.
46
+ */
47
+ static async callDashboardAPI(
48
+ input: ProjectDashboardInput
49
+ ): Promise<DOFunctionCallOutput<ProjectDashboardOutput>> {
50
+ const result = await DOFunctionService.projectDashboard.call(input);
51
+ return result;
52
+ }
53
+ }
@@ -40,6 +40,9 @@ export interface DOFunctionRawOutput {
40
40
  'Content-Type': 'application/octet-stream';
41
41
  };
42
42
  }
43
+ /**
44
+ * A generic interface representing the output of a Digital Ocean function call.
45
+ */
43
46
  export interface DOFunctionCallOutput<TOutput extends DOFunctionOutput> {
44
47
  success: boolean;
45
48
  errors: string[];
@@ -49,6 +52,12 @@ export interface DOFunctionCallOutput<TOutput extends DOFunctionOutput> {
49
52
  * An abstract class that can be extended to define a Digital Ocean
50
53
  * function.
51
54
  */
55
+ /**
56
+ * An abstract class representing a Digital Ocean Function.
57
+ *
58
+ * @template TInput - The type of the input to the function, extending {@link DOFunctionInput}.
59
+ * @template TOutput - The type of the output from the function, extending {@link DOFunctionOutput}.
60
+ */
52
61
  export default abstract class DOFunction<TInput extends DOFunctionInput, TOutput extends DOFunctionOutput> {
53
62
  /**
54
63
  * The URL of the digital ocean function.
@@ -56,13 +65,28 @@ export default abstract class DOFunction<TInput extends DOFunctionInput, TOutput
56
65
  protected url?: string;
57
66
  protected functionName: string;
58
67
  protected constructor();
68
+ /**
69
+ * Sets the URL of the Digital Ocean function.
70
+ *
71
+ * @param url - The URL to set.
72
+ */
59
73
  setUrl(url: string): void;
60
74
  /**
61
75
  * A generic call method for any Digital Ocean Function from the client.
62
76
  * This gets pretty crazy with the serialization logic. It has been tested
63
77
  * heavily.
78
+ *
79
+ * @param input - The input to the function.
80
+ * @returns A promise that resolves to the output of the function call, wrapped in {@link DOFunctionCallOutput}.
81
+ * @throws Will throw an error if the URL is not set.
64
82
  */
65
83
  call(input: TInput): Promise<DOFunctionCallOutput<TOutput>>;
84
+ /**
85
+ * Decodes an {@link ArrayBuffer} into a {@link DOFunctionCallOutput}.
86
+ *
87
+ * @param buffer - The buffer to decode.
88
+ * @returns The decoded output.
89
+ */
66
90
  private decodeArrayBuffer;
67
91
  }
68
92
  //# sourceMappingURL=DOFunction.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DOFunction.d.ts","sourceRoot":"","sources":["../../../src/services/DOFunctionService/DOFunction.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC;AAErC;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEtC;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,IAAI,EAAE;QACJ;;;WAGG;QACH,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH;AAED;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE;QACP,cAAc,EAAE,0BAA0B,CAAC;KAC5C,CAAC;CACH;AAED,MAAM,WAAW,oBAAoB,CAAC,OAAO,SAAS,gBAAgB;IACpE,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,IAAI,EAAE,OAAO,CAAC;CACf;AAED;;;GAGG;AACH,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,UAAU,CACtC,MAAM,SAAS,eAAe,EAC9B,OAAO,SAAS,gBAAgB;IAEhC;;OAEG;IACH,SAAS,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAEvB,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC;IAE/B,SAAS;IAIT,MAAM,CAAC,GAAG,EAAE,MAAM;IAIlB;;;;OAIG;IACG,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAgBjE,OAAO,CAAC,iBAAiB;CAM1B"}
1
+ {"version":3,"file":"DOFunction.d.ts","sourceRoot":"./src/","sources":["services/DOFunctionService/DOFunction.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC;AAErC;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEtC;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;OAGG;IACH,IAAI,EAAE;QACJ;;;WAGG;QACH,IAAI,EAAE,MAAM,CAAC;KACd,CAAC;CACH;AAED;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE;QACP,cAAc,EAAE,0BAA0B,CAAC;KAC5C,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB,CAAC,OAAO,SAAS,gBAAgB;IACpE,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,IAAI,EAAE,OAAO,CAAC;CACf;AAED;;;GAGG;AACH;;;;;GAKG;AACH,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,UAAU,CACtC,MAAM,SAAS,eAAe,EAC9B,OAAO,SAAS,gBAAgB;IAEhC;;OAEG;IACH,SAAS,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAEvB,SAAS,CAAC,YAAY,EAAE,MAAM,CAAC;IAE/B,SAAS;IAIT;;;;OAIG;IACH,MAAM,CAAC,GAAG,EAAE,MAAM;IAIlB;;;;;;;;OAQG;IACG,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;IAiBjE;;;;;OAKG;IACH,OAAO,CAAC,iBAAiB;CAa1B"}
@@ -1,11 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const bson_1 = require("bson");
1
+ import { BSON } from 'bson';
4
2
  /**
5
3
  * An abstract class that can be extended to define a Digital Ocean
6
4
  * function.
7
5
  */
8
- class DOFunction {
6
+ /**
7
+ * An abstract class representing a Digital Ocean Function.
8
+ *
9
+ * @template TInput - The type of the input to the function, extending {@link DOFunctionInput}.
10
+ * @template TOutput - The type of the output from the function, extending {@link DOFunctionOutput}.
11
+ */
12
+ export default class DOFunction {
9
13
  /**
10
14
  * The URL of the digital ocean function.
11
15
  */
@@ -14,6 +18,11 @@ class DOFunction {
14
18
  constructor() {
15
19
  this.functionName = this.constructor.name;
16
20
  }
21
+ /**
22
+ * Sets the URL of the Digital Ocean function.
23
+ *
24
+ * @param url - The URL to set.
25
+ */
17
26
  setUrl(url) {
18
27
  this.url = url;
19
28
  }
@@ -21,11 +30,16 @@ class DOFunction {
21
30
  * A generic call method for any Digital Ocean Function from the client.
22
31
  * This gets pretty crazy with the serialization logic. It has been tested
23
32
  * heavily.
33
+ *
34
+ * @param input - The input to the function.
35
+ * @returns A promise that resolves to the output of the function call, wrapped in {@link DOFunctionCallOutput}.
36
+ * @throws Will throw an error if the URL is not set.
24
37
  */
25
38
  async call(input) {
26
39
  if (!this.url) {
27
40
  throw new Error(`${this.functionName} URL is not set`);
28
41
  }
42
+ const serializedInput = BSON.serialize(input);
29
43
  const result = await fetch(this.url, {
30
44
  method: 'POST',
31
45
  headers: {
@@ -33,13 +47,27 @@ class DOFunction {
33
47
  },
34
48
  // It isn't clear why this works by itself. It comes in to the function
35
49
  // as a base64 string.
36
- body: bson_1.BSON.serialize(input)
50
+ body: serializedInput
37
51
  });
38
52
  return this.decodeArrayBuffer(await result.arrayBuffer());
39
53
  }
54
+ /**
55
+ * Decodes an {@link ArrayBuffer} into a {@link DOFunctionCallOutput}.
56
+ *
57
+ * @param buffer - The buffer to decode.
58
+ * @returns The decoded output.
59
+ */
40
60
  decodeArrayBuffer(buffer) {
41
61
  const bytes = new Uint8Array(buffer);
42
- return bson_1.BSON.deserialize(bytes);
62
+ console.log('Buffer length:', bytes.length);
63
+ console.log('Buffer content:', bytes);
64
+ try {
65
+ return BSON.deserialize(bytes);
66
+ }
67
+ catch (error) {
68
+ console.error('Deserialization error:', error);
69
+ throw error;
70
+ }
43
71
  }
44
72
  }
45
- exports.default = DOFunction;
73
+ //# sourceMappingURL=DOFunction.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DOFunction.js","sourceRoot":"./src/","sources":["services/DOFunctionService/DOFunction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAyD5B;;;GAGG;AACH;;;;;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,eAAe,GAAG,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;QAC9C,MAAM,MAAM,GAAG,MAAM,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE;YACnC,MAAM,EAAE,MAAM;YACd,OAAO,EAAE;gBACP,cAAc,EAAE,0BAA0B;aAC3C;YACD,uEAAuE;YACvE,sBAAsB;YACtB,IAAI,EAAE,eAAe;SACtB,CAAC,CAAC;QACH,OAAO,IAAI,CAAC,iBAAiB,CAAC,MAAM,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;IAC5D,CAAC;IAED;;;;;OAKG;IACK,iBAAiB,CACvB,MAAmB;QAEnB,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;QACrC,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,KAAK,CAAC,MAAM,CAAC,CAAC;QAC5C,OAAO,CAAC,GAAG,CAAC,iBAAiB,EAAE,KAAK,CAAC,CAAC;QACtC,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,WAAW,CAAC,KAAK,CAAkC,CAAC;QAClE,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,KAAK,CAAC,CAAC;YAC/C,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,137 @@
1
+ import { BSON } from 'bson';
2
+
3
+ /**
4
+ * The input to a Digital Ocean function must always be an object.
5
+ */
6
+ export type DOFunctionInput = object;
7
+
8
+ /**
9
+ * The output from a Digital Ocean function must always be an object. This
10
+ * is the data that actually matters and doesn't require parsing the `body`
11
+ * property.
12
+ */
13
+ export type DOFunctionOutput = object;
14
+
15
+ /**
16
+ * Raw input to a Digital Ocean function will always have a data property
17
+ * which is a string. This string must be parsed using EJSON.parse.
18
+ */
19
+ export interface DOFunctionRawInput {
20
+ /**
21
+ * There are many other properties in the `http` object, but only the body
22
+ * property is used.
23
+ */
24
+ http: {
25
+ /**
26
+ * The body property needs to be parsed with atob, then put through some
27
+ * other processing.
28
+ */
29
+ body: string;
30
+ };
31
+ }
32
+
33
+ /**
34
+ * Raw output from a Digital Ocean function must always be an object with
35
+ * a body property. The body property must be a string that is base64 encoded
36
+ * or an object. With how this project is set up, it will always be base64
37
+ * encoded to support BSON types.
38
+ */
39
+ export interface DOFunctionRawOutput {
40
+ /**
41
+ * The body is a base64 encoded string.
42
+ */
43
+ body: string;
44
+ headers: {
45
+ 'Content-Type': 'application/octet-stream';
46
+ };
47
+ }
48
+
49
+ /**
50
+ * A generic interface representing the output of a Digital Ocean function call.
51
+ */
52
+ export interface DOFunctionCallOutput<TOutput extends DOFunctionOutput> {
53
+ success: boolean;
54
+ errors: string[];
55
+ data: TOutput;
56
+ }
57
+
58
+ /**
59
+ * An abstract class that can be extended to define a Digital Ocean
60
+ * function.
61
+ */
62
+ /**
63
+ * An abstract class representing a Digital Ocean Function.
64
+ *
65
+ * @template TInput - The type of the input to the function, extending {@link DOFunctionInput}.
66
+ * @template TOutput - The type of the output from the function, extending {@link DOFunctionOutput}.
67
+ */
68
+ export default abstract class DOFunction<
69
+ TInput extends DOFunctionInput,
70
+ TOutput extends DOFunctionOutput
71
+ > {
72
+ /**
73
+ * The URL of the digital ocean function.
74
+ */
75
+ protected url?: string;
76
+
77
+ protected functionName: string;
78
+
79
+ protected constructor() {
80
+ this.functionName = this.constructor.name;
81
+ }
82
+
83
+ /**
84
+ * Sets the URL of the Digital Ocean function.
85
+ *
86
+ * @param url - The URL to set.
87
+ */
88
+ setUrl(url: string) {
89
+ this.url = url;
90
+ }
91
+
92
+ /**
93
+ * A generic call method for any Digital Ocean Function from the client.
94
+ * This gets pretty crazy with the serialization logic. It has been tested
95
+ * heavily.
96
+ *
97
+ * @param input - The input to the function.
98
+ * @returns A promise that resolves to the output of the function call, wrapped in {@link DOFunctionCallOutput}.
99
+ * @throws Will throw an error if the URL is not set.
100
+ */
101
+ async call(input: TInput): Promise<DOFunctionCallOutput<TOutput>> {
102
+ if (!this.url) {
103
+ throw new Error(`${this.functionName} URL is not set`);
104
+ }
105
+ const serializedInput = BSON.serialize(input);
106
+ const result = await fetch(this.url, {
107
+ method: 'POST',
108
+ headers: {
109
+ 'Content-Type': 'application/octet-stream'
110
+ },
111
+ // It isn't clear why this works by itself. It comes in to the function
112
+ // as a base64 string.
113
+ body: serializedInput
114
+ });
115
+ return this.decodeArrayBuffer(await result.arrayBuffer());
116
+ }
117
+
118
+ /**
119
+ * Decodes an {@link ArrayBuffer} into a {@link DOFunctionCallOutput}.
120
+ *
121
+ * @param buffer - The buffer to decode.
122
+ * @returns The decoded output.
123
+ */
124
+ private decodeArrayBuffer(
125
+ buffer: ArrayBuffer
126
+ ): DOFunctionCallOutput<TOutput> {
127
+ const bytes = new Uint8Array(buffer);
128
+ console.log('Buffer length:', bytes.length);
129
+ console.log('Buffer content:', bytes);
130
+ try {
131
+ return BSON.deserialize(bytes) as DOFunctionCallOutput<TOutput>;
132
+ } catch (error) {
133
+ console.error('Deserialization error:', error);
134
+ throw error;
135
+ }
136
+ }
137
+ }
@@ -1,13 +1,22 @@
1
- import { DOFunctionCallOutput, DOFunctionInput, DOFunctionOutput, DOFunctionRawInput, DOFunctionRawOutput } from './DOFunction';
2
- import AuthCheckPassword from './functions/authCheckPassword';
3
- import AuthValidateUser from './functions/authValidateUser';
4
- import ProjectDashboard from './functions/projectDashboard';
1
+ import { DOFunctionCallOutput, DOFunctionInput, DOFunctionOutput, DOFunctionRawInput, DOFunctionRawOutput } from './DOFunction.js';
2
+ import AuthCheckPassword from './functions/authCheckPassword.js';
3
+ import AuthValidateUser from './functions/authValidateUser.js';
4
+ import ProjectDashboard from './functions/projectDashboard.js';
5
5
  /**
6
6
  * A service to provide some utility related to Digital Ocean functions.
7
7
  */
8
8
  export default class DOFunctionService {
9
- static auchCheckPassword: AuthCheckPassword;
9
+ /**
10
+ * {@link AuthCheckPassword} function instance.
11
+ */
12
+ static authCheckPassword: AuthCheckPassword;
13
+ /**
14
+ * {@link AuthValidateUser} function instance.
15
+ */
10
16
  static authValidateUser: AuthValidateUser;
17
+ /**
18
+ * {@link ProjectDashboard} function instance.
19
+ */
11
20
  static projectDashboard: ProjectDashboard;
12
21
  /**
13
22
  * A generic method to handle any API request on the backend. This has
@@ -16,9 +25,25 @@ export default class DOFunctionService {
16
25
  * This will take care of returning the error if the handler throws.
17
26
  * Ideally the handler should not throw though unless something really
18
27
  * unexpected happened.
28
+ *
29
+ * @param rawInput - The raw input for the function.
30
+ * @param handler - The handler function to process the input.
31
+ * @returns The raw output of the function call.
19
32
  */
20
33
  static handleApiRequest<TInput extends DOFunctionInput, TOutput extends DOFunctionOutput>(rawInput: DOFunctionRawInput, handler: (input: TInput) => Promise<DOFunctionCallOutput<TOutput>>): Promise<DOFunctionRawOutput>;
34
+ /**
35
+ * Deserializes the raw input into a typed input object.
36
+ *
37
+ * @param rawInput - The raw input to deserialize.
38
+ * @returns The deserialized input object.
39
+ */
21
40
  private static deserializeInput;
41
+ /**
42
+ * Serializes the output object into a base64 string.
43
+ *
44
+ * @param output - The output object to serialize.
45
+ * @returns The serialized output as a base64 string.
46
+ */
22
47
  private static serializeOutput;
23
48
  }
24
49
  //# sourceMappingURL=DOFunctionService.d.ts.map