@aneuhold/core-ts-api-lib 3.0.1 → 3.0.2

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 (63) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/lib/browser.d.ts +5 -7
  3. package/lib/browser.d.ts.map +1 -1
  4. package/lib/browser.js +1 -2
  5. package/lib/browser.js.map +1 -1
  6. package/lib/browser.ts +6 -19
  7. package/lib/services/APIService/APIService.d.ts +2 -2
  8. package/lib/services/APIService/APIService.d.ts.map +1 -1
  9. package/lib/services/APIService/APIService.ts +2 -2
  10. package/lib/services/GCloudAPIService/GCloudAPIService.d.ts +2 -2
  11. package/lib/services/GCloudAPIService/GCloudAPIService.d.ts.map +1 -1
  12. package/lib/services/GCloudAPIService/GCloudAPIService.js +9 -14
  13. package/lib/services/GCloudAPIService/GCloudAPIService.js.map +1 -1
  14. package/lib/services/GCloudAPIService/GCloudAPIService.ts +11 -16
  15. package/lib/types/AuthCheckPassword.d.ts +13 -0
  16. package/lib/types/AuthCheckPassword.d.ts.map +1 -0
  17. package/lib/types/AuthCheckPassword.js +2 -0
  18. package/lib/types/AuthCheckPassword.js.map +1 -0
  19. package/lib/types/AuthCheckPassword.ts +13 -0
  20. package/lib/types/AuthValidateUser.d.ts +34 -0
  21. package/lib/types/AuthValidateUser.d.ts.map +1 -0
  22. package/lib/types/AuthValidateUser.js +2 -0
  23. package/lib/types/AuthValidateUser.js.map +1 -0
  24. package/lib/types/AuthValidateUser.ts +35 -0
  25. package/lib/{services/DOFunctionService/functions/projectDashboard.d.ts → types/ProjectDashboard.d.ts} +4 -15
  26. package/lib/types/ProjectDashboard.d.ts.map +1 -0
  27. package/lib/types/ProjectDashboard.js +2 -0
  28. package/lib/types/ProjectDashboard.js.map +1 -0
  29. package/lib/{services/DOFunctionService/functions/projectDashboard.ts → types/ProjectDashboard.ts} +3 -27
  30. package/package.json +8 -8
  31. package/lib/services/DOFunctionService/DOFunction.d.ts +0 -109
  32. package/lib/services/DOFunctionService/DOFunction.d.ts.map +0 -1
  33. package/lib/services/DOFunctionService/DOFunction.js +0 -87
  34. package/lib/services/DOFunctionService/DOFunction.js.map +0 -1
  35. package/lib/services/DOFunctionService/DOFunction.ts +0 -165
  36. package/lib/services/DOFunctionService/DOFunctionService.d.ts +0 -54
  37. package/lib/services/DOFunctionService/DOFunctionService.d.ts.map +0 -1
  38. package/lib/services/DOFunctionService/DOFunctionService.js +0 -157
  39. package/lib/services/DOFunctionService/DOFunctionService.js.map +0 -1
  40. package/lib/services/DOFunctionService/DOFunctionService.ts +0 -191
  41. package/lib/services/DOFunctionService/functions/authCheckPassword.d.ts +0 -30
  42. package/lib/services/DOFunctionService/functions/authCheckPassword.d.ts.map +0 -1
  43. package/lib/services/DOFunctionService/functions/authCheckPassword.js +0 -26
  44. package/lib/services/DOFunctionService/functions/authCheckPassword.js.map +0 -1
  45. package/lib/services/DOFunctionService/functions/authCheckPassword.ts +0 -46
  46. package/lib/services/DOFunctionService/functions/authValidateUser.d.ts +0 -56
  47. package/lib/services/DOFunctionService/functions/authValidateUser.d.ts.map +0 -1
  48. package/lib/services/DOFunctionService/functions/authValidateUser.js +0 -32
  49. package/lib/services/DOFunctionService/functions/authValidateUser.js.map +0 -1
  50. package/lib/services/DOFunctionService/functions/authValidateUser.ts +0 -72
  51. package/lib/services/DOFunctionService/functions/projectDashboard.d.ts.map +0 -1
  52. package/lib/services/DOFunctionService/functions/projectDashboard.js +0 -19
  53. package/lib/services/DOFunctionService/functions/projectDashboard.js.map +0 -1
  54. package/lib/tests/ExampleFunction.d.ts +0 -15
  55. package/lib/tests/ExampleFunction.d.ts.map +0 -1
  56. package/lib/tests/ExampleFunction.js +0 -16
  57. package/lib/tests/ExampleFunction.js.map +0 -1
  58. package/lib/tests/ExampleFunction.ts +0 -31
  59. package/lib/tests/TestUtil.d.ts +0 -10
  60. package/lib/tests/TestUtil.d.ts.map +0 -1
  61. package/lib/tests/TestUtil.js +0 -17
  62. package/lib/tests/TestUtil.js.map +0 -1
  63. package/lib/tests/TestUtil.ts +0 -17
@@ -1,109 +0,0 @@
1
- import type { APIResponse } from '../../types/APIResponse.js';
2
- /**
3
- * The input to a Digital Ocean function must always be an object.
4
- */
5
- export type DOFunctionInput = object;
6
- /**
7
- * The output from a Digital Ocean function must always be an object. This
8
- * is the data that actually matters and doesn't require parsing the `body`
9
- * property.
10
- */
11
- export type DOFunctionOutput = object;
12
- /**
13
- * Raw input to a Digital Ocean function. This is with the expectation that
14
- * `web: raw` is set in the `project.yml` file.
15
- */
16
- export interface DOFunctionRawInput {
17
- http: {
18
- /**
19
- * The body to be parsed or deserialized.
20
- */
21
- body: string;
22
- headers: {
23
- accept?: string;
24
- 'accept-encoding'?: string;
25
- /**
26
- * This is important.
27
- */
28
- 'content-type'?: string;
29
- host?: string;
30
- 'user-agent'?: string;
31
- 'x-forwarded-for'?: string;
32
- 'x-forwarded-proto'?: string;
33
- 'x-request-id'?: string;
34
- };
35
- /**
36
- * This needs to be used to determine if the body is base64 encoded.
37
- */
38
- isBase64Encoded: boolean;
39
- method?: string;
40
- path?: string;
41
- queryString?: string;
42
- };
43
- }
44
- /**
45
- * Raw output from a Digital Ocean function must always be an object with
46
- * a body property. The body property must be a string that is base64 encoded
47
- * or an object. With how this project is set up, it will always be base64
48
- * encoded to support BSON types.
49
- */
50
- export interface DOFunctionRawOutput {
51
- /**
52
- * The body is a base64 encoded string.
53
- */
54
- body: string;
55
- statusCode: number;
56
- headers: {
57
- /**
58
- * This is different than what gets passed in. This is on purpose. DO
59
- * functions changes the header name when being passed in, but not when
60
- * being passed out.
61
- */
62
- 'Content-Type': string;
63
- };
64
- }
65
- /**
66
- * Type guard to check if an input object conforms to the DOFunctionRawInput structure.
67
- *
68
- * @param input - The input object to check.
69
- * @returns True if the input is DOFunctionRawInput, false otherwise.
70
- */
71
- export declare function isDOFunctionRawInput(input: unknown): input is DOFunctionRawInput;
72
- /**
73
- * An abstract class representing a Digital Ocean Function.
74
- *
75
- * @template TInput - The type of the input to the function, extending {@link DOFunctionInput}.
76
- * @template TOutput - The type of the output from the function, extending {@link DOFunctionOutput}.
77
- */
78
- export default abstract class DOFunction<TInput extends DOFunctionInput, TOutput extends DOFunctionOutput> {
79
- /**
80
- * The URL of the digital ocean function.
81
- */
82
- protected url?: string;
83
- protected functionName: string;
84
- protected constructor();
85
- /**
86
- * Sets the URL of the Digital Ocean function.
87
- *
88
- * @param url - The URL to set.
89
- */
90
- setUrl(url: string): void;
91
- /**
92
- * A generic call method for any Digital Ocean Function from the client.
93
- * This gets pretty crazy with the serialization logic. It has been tested
94
- * heavily.
95
- *
96
- * @param input - The input to the function.
97
- * @returns A promise that resolves to the output of the function call, wrapped in {@link DOFunctionCallOutput}.
98
- * @throws {Error} Will throw an error if the URL is not set.
99
- */
100
- call(input: TInput): Promise<APIResponse<TOutput>>;
101
- /**
102
- * Decodes the response from the Digital Ocean function.
103
- *
104
- * @param response - The response to decode.
105
- * @returns The decoded output.
106
- */
107
- private decodeResponse;
108
- }
109
- //# sourceMappingURL=DOFunction.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DOFunction.d.ts","sourceRoot":"","sources":["../../../src/services/DOFunctionService/DOFunction.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAE9D;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC;AAErC;;;;GAIG;AACH,MAAM,MAAM,gBAAgB,GAAG,MAAM,CAAC;AAEtC;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE;QACJ;;WAEG;QACH,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE;YACP,MAAM,CAAC,EAAE,MAAM,CAAC;YAChB,iBAAiB,CAAC,EAAE,MAAM,CAAC;YAC3B;;eAEG;YACH,cAAc,CAAC,EAAE,MAAM,CAAC;YACxB,IAAI,CAAC,EAAE,MAAM,CAAC;YACd,YAAY,CAAC,EAAE,MAAM,CAAC;YACtB,iBAAiB,CAAC,EAAE,MAAM,CAAC;YAC3B,mBAAmB,CAAC,EAAE,MAAM,CAAC;YAC7B,cAAc,CAAC,EAAE,MAAM,CAAC;SACzB,CAAC;QACF;;WAEG;QACH,eAAe,EAAE,OAAO,CAAC;QACzB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;CACH;AAED;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE;QACP;;;;WAIG;QACH,cAAc,EAAE,MAAM,CAAC;KACxB,CAAC;CACH;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,kBAAkB,CAShF;AAED;;;;;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,WAAW,CAAC,OAAO,CAAC,CAAC;IAgBxD;;;;;OAKG;YACW,cAAc;CAgB7B"}
@@ -1,87 +0,0 @@
1
- import { BSON } from 'bson';
2
- /**
3
- * Type guard to check if an input object conforms to the DOFunctionRawInput structure.
4
- *
5
- * @param input - The input object to check.
6
- * @returns True if the input is DOFunctionRawInput, false otherwise.
7
- */
8
- export function isDOFunctionRawInput(input) {
9
- return (!!input &&
10
- typeof input === 'object' &&
11
- 'http' in input &&
12
- typeof input.http === 'object' &&
13
- 'body' in input.http && // Check for essential http properties
14
- 'isBase64Encoded' in input.http);
15
- }
16
- /**
17
- * An abstract class representing a Digital Ocean Function.
18
- *
19
- * @template TInput - The type of the input to the function, extending {@link DOFunctionInput}.
20
- * @template TOutput - The type of the output from the function, extending {@link DOFunctionOutput}.
21
- */
22
- export default class DOFunction {
23
- /**
24
- * The URL of the digital ocean function.
25
- */
26
- url;
27
- functionName;
28
- constructor() {
29
- this.functionName = this.constructor.name;
30
- }
31
- /**
32
- * Sets the URL of the Digital Ocean function.
33
- *
34
- * @param url - The URL to set.
35
- */
36
- setUrl(url) {
37
- this.url = url;
38
- }
39
- /**
40
- * A generic call method for any Digital Ocean Function from the client.
41
- * This gets pretty crazy with the serialization logic. It has been tested
42
- * heavily.
43
- *
44
- * @param input - The input to the function.
45
- * @returns A promise that resolves to the output of the function call, wrapped in {@link DOFunctionCallOutput}.
46
- * @throws {Error} Will throw an error if the URL is not set.
47
- */
48
- async call(input) {
49
- if (!this.url) {
50
- throw new Error(`${this.functionName} URL is not set`);
51
- }
52
- const response = await fetch(this.url, {
53
- method: 'POST',
54
- headers: {
55
- Connection: 'keep-alive',
56
- 'Content-Type': 'application/octet-stream',
57
- Accept: 'application/octet-stream'
58
- },
59
- body: Buffer.from(BSON.serialize(input))
60
- });
61
- return await this.decodeResponse(response);
62
- }
63
- /**
64
- * Decodes the response from the Digital Ocean function.
65
- *
66
- * @param response - The response to decode.
67
- * @returns The decoded output.
68
- */
69
- async decodeResponse(response) {
70
- const isBson = response.headers.get('Content-Type') === 'application/octet-stream';
71
- if (isBson) {
72
- const buffer = await response.arrayBuffer();
73
- const uint8Array = new Uint8Array(buffer);
74
- return BSON.deserialize(uint8Array);
75
- }
76
- else {
77
- // This normally only happens if there is an error
78
- const result = (await response.json());
79
- return {
80
- success: false,
81
- errors: [JSON.stringify(result, null, 2)],
82
- data: {}
83
- };
84
- }
85
- }
86
- }
87
- //# sourceMappingURL=DOFunction.js.map
@@ -1 +0,0 @@
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"}
@@ -1,165 +0,0 @@
1
- import { BSON } from 'bson';
2
- import type { APIResponse } from '../../types/APIResponse.js';
3
-
4
- /**
5
- * The input to a Digital Ocean function must always be an object.
6
- */
7
- export type DOFunctionInput = object;
8
-
9
- /**
10
- * The output from a Digital Ocean function must always be an object. This
11
- * is the data that actually matters and doesn't require parsing the `body`
12
- * property.
13
- */
14
- export type DOFunctionOutput = object;
15
-
16
- /**
17
- * Raw input to a Digital Ocean function. This is with the expectation that
18
- * `web: raw` is set in the `project.yml` file.
19
- */
20
- export interface DOFunctionRawInput {
21
- http: {
22
- /**
23
- * The body to be parsed or deserialized.
24
- */
25
- body: string;
26
- headers: {
27
- accept?: string;
28
- 'accept-encoding'?: string;
29
- /**
30
- * This is important.
31
- */
32
- 'content-type'?: string;
33
- host?: string;
34
- 'user-agent'?: string;
35
- 'x-forwarded-for'?: string;
36
- 'x-forwarded-proto'?: string;
37
- 'x-request-id'?: string;
38
- };
39
- /**
40
- * This needs to be used to determine if the body is base64 encoded.
41
- */
42
- isBase64Encoded: boolean;
43
- method?: string;
44
- path?: string;
45
- queryString?: string;
46
- };
47
- }
48
-
49
- /**
50
- * Raw output from a Digital Ocean function must always be an object with
51
- * a body property. The body property must be a string that is base64 encoded
52
- * or an object. With how this project is set up, it will always be base64
53
- * encoded to support BSON types.
54
- */
55
- export interface DOFunctionRawOutput {
56
- /**
57
- * The body is a base64 encoded string.
58
- */
59
- body: string;
60
- statusCode: number;
61
- headers: {
62
- /**
63
- * This is different than what gets passed in. This is on purpose. DO
64
- * functions changes the header name when being passed in, but not when
65
- * being passed out.
66
- */
67
- 'Content-Type': string;
68
- };
69
- }
70
-
71
- /**
72
- * Type guard to check if an input object conforms to the DOFunctionRawInput structure.
73
- *
74
- * @param input - The input object to check.
75
- * @returns True if the input is DOFunctionRawInput, false otherwise.
76
- */
77
- export function isDOFunctionRawInput(input: unknown): input is DOFunctionRawInput {
78
- return (
79
- !!input &&
80
- typeof input === 'object' &&
81
- 'http' in input &&
82
- typeof (input as DOFunctionRawInput).http === 'object' &&
83
- 'body' in (input as DOFunctionRawInput).http && // Check for essential http properties
84
- 'isBase64Encoded' in (input as DOFunctionRawInput).http
85
- );
86
- }
87
-
88
- /**
89
- * An abstract class representing a Digital Ocean Function.
90
- *
91
- * @template TInput - The type of the input to the function, extending {@link DOFunctionInput}.
92
- * @template TOutput - The type of the output from the function, extending {@link DOFunctionOutput}.
93
- */
94
- export default abstract class DOFunction<
95
- TInput extends DOFunctionInput,
96
- TOutput extends DOFunctionOutput
97
- > {
98
- /**
99
- * The URL of the digital ocean function.
100
- */
101
- protected url?: string;
102
-
103
- protected functionName: string;
104
-
105
- protected constructor() {
106
- this.functionName = this.constructor.name;
107
- }
108
-
109
- /**
110
- * Sets the URL of the Digital Ocean function.
111
- *
112
- * @param url - The URL to set.
113
- */
114
- setUrl(url: string) {
115
- this.url = url;
116
- }
117
-
118
- /**
119
- * A generic call method for any Digital Ocean Function from the client.
120
- * This gets pretty crazy with the serialization logic. It has been tested
121
- * heavily.
122
- *
123
- * @param input - The input to the function.
124
- * @returns A promise that resolves to the output of the function call, wrapped in {@link DOFunctionCallOutput}.
125
- * @throws {Error} Will throw an error if the URL is not set.
126
- */
127
- async call(input: TInput): Promise<APIResponse<TOutput>> {
128
- if (!this.url) {
129
- throw new Error(`${this.functionName} URL is not set`);
130
- }
131
- const response = await fetch(this.url, {
132
- method: 'POST',
133
- headers: {
134
- Connection: 'keep-alive',
135
- 'Content-Type': 'application/octet-stream',
136
- Accept: 'application/octet-stream'
137
- },
138
- body: Buffer.from(BSON.serialize(input))
139
- });
140
- return await this.decodeResponse(response);
141
- }
142
-
143
- /**
144
- * Decodes the response from the Digital Ocean function.
145
- *
146
- * @param response - The response to decode.
147
- * @returns The decoded output.
148
- */
149
- private async decodeResponse(response: Response): Promise<APIResponse<TOutput>> {
150
- const isBson = response.headers.get('Content-Type') === 'application/octet-stream';
151
- if (isBson) {
152
- const buffer = await response.arrayBuffer();
153
- const uint8Array = new Uint8Array(buffer);
154
- return BSON.deserialize(uint8Array) as APIResponse<TOutput>;
155
- } else {
156
- // This normally only happens if there is an error
157
- const result = (await response.json()) as unknown;
158
- return {
159
- success: false,
160
- errors: [JSON.stringify(result, null, 2)],
161
- data: {} as TOutput
162
- };
163
- }
164
- }
165
- }
@@ -1,54 +0,0 @@
1
- import type { APIResponse } from '../../types/APIResponse.js';
2
- import type { DOFunctionInput, DOFunctionOutput, DOFunctionRawInput, DOFunctionRawOutput } from './DOFunction.js';
3
- import AuthCheckPassword from './functions/authCheckPassword.js';
4
- import AuthValidateUser from './functions/authValidateUser.js';
5
- import ProjectDashboard from './functions/projectDashboard.js';
6
- /**
7
- * A service to provide some utility related to Digital Ocean functions.
8
- */
9
- export default class DOFunctionService {
10
- /**
11
- * {@link AuthCheckPassword} function instance.
12
- */
13
- static authCheckPassword: AuthCheckPassword;
14
- /**
15
- * {@link AuthValidateUser} function instance.
16
- */
17
- static authValidateUser: AuthValidateUser;
18
- /**
19
- * {@link ProjectDashboard} function instance.
20
- */
21
- static projectDashboard: ProjectDashboard;
22
- /**
23
- * A generic method to handle any API request on the backend. This has
24
- * no use on the frontend.
25
- *
26
- * This will take care of returning the error if the handler throws, and
27
- * managing tracing spans via the registered ITracer.
28
- * Ideally the handler should not throw though unless something really
29
- * unexpected happened.
30
- *
31
- * @param functionName - The name to use for the root tracing span.
32
- * @param rawInputFromDO - The raw input for the function.
33
- * @param handler - The handler function to process the input.
34
- * @returns The raw output of the function call.
35
- */
36
- static handleApiRequest<TInput extends DOFunctionInput, TOutput extends DOFunctionOutput>(functionName: string, rawInputFromDO: DOFunctionRawInput | TInput, handler: (input: TInput) => Promise<APIResponse<TOutput>>): Promise<DOFunctionRawOutput>;
37
- /**
38
- * Deserializes the raw input into a typed input object using type guards.
39
- * Handles raw HTTP input, the DO UI wrapper, or already deserialized input.
40
- *
41
- * @param inputFromDO - The raw input received from the DO environment.
42
- * @returns The deserialized input object of type TInput.
43
- */
44
- private static deserializeInput;
45
- /**
46
- * Serializes the output object into a base64 string. This could be updated
47
- * to support other serialization methods in the future.
48
- *
49
- * @param output - The output object to serialize.
50
- * @returns The serialized output as a base64 string.
51
- */
52
- private static serializeOutput;
53
- }
54
- //# sourceMappingURL=DOFunctionService.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DOFunctionService.d.ts","sourceRoot":"","sources":["../../../src/services/DOFunctionService/DOFunctionService.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EACV,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,iBAAiB,MAAM,kCAAkC,CAAC;AACjE,OAAO,gBAAgB,MAAM,iCAAiC,CAAC;AAC/D,OAAO,gBAAgB,MAAM,iCAAiC,CAAC;AAE/D;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC;;OAEG;IACH,MAAM,CAAC,iBAAiB,EAAE,iBAAiB,CAAmC;IAE9E;;OAEG;IACH,MAAM,CAAC,gBAAgB,EAAE,gBAAgB,CAAkC;IAE3E;;OAEG;IACH,MAAM,CAAC,gBAAgB,EAAE,gBAAgB,CAAkC;IAE3E;;;;;;;;;;;;;OAaG;WACU,gBAAgB,CAAC,MAAM,SAAS,eAAe,EAAE,OAAO,SAAS,gBAAgB,EAC5F,YAAY,EAAE,MAAM,EACpB,cAAc,EAAE,kBAAkB,GAAG,MAAM,EAC3C,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,GACxD,OAAO,CAAC,mBAAmB,CAAC;IA2D/B;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IA4D/B;;;;;;OAMG;IACH,OAAO,CAAC,MAAM,CAAC,eAAe;CAM/B"}
@@ -1,157 +0,0 @@
1
- import { DR } from '@aneuhold/core-ts-lib';
2
- import { BSON } from 'bson';
3
- import { isDOFunctionRawInput } from './DOFunction.js';
4
- import AuthCheckPassword from './functions/authCheckPassword.js';
5
- import AuthValidateUser from './functions/authValidateUser.js';
6
- import ProjectDashboard from './functions/projectDashboard.js';
7
- /**
8
- * A service to provide some utility related to Digital Ocean functions.
9
- */
10
- export default class DOFunctionService {
11
- /**
12
- * {@link AuthCheckPassword} function instance.
13
- */
14
- static authCheckPassword = AuthCheckPassword.getFunction();
15
- /**
16
- * {@link AuthValidateUser} function instance.
17
- */
18
- static authValidateUser = AuthValidateUser.getFunction();
19
- /**
20
- * {@link ProjectDashboard} function instance.
21
- */
22
- static projectDashboard = ProjectDashboard.getFunction();
23
- /**
24
- * A generic method to handle any API request on the backend. This has
25
- * no use on the frontend.
26
- *
27
- * This will take care of returning the error if the handler throws, and
28
- * managing tracing spans via the registered ITracer.
29
- * Ideally the handler should not throw though unless something really
30
- * unexpected happened.
31
- *
32
- * @param functionName - The name to use for the root tracing span.
33
- * @param rawInputFromDO - The raw input for the function.
34
- * @param handler - The handler function to process the input.
35
- * @returns The raw output of the function call.
36
- */
37
- static async handleApiRequest(functionName, rawInputFromDO, handler) {
38
- DR.logger.info(`[DOFunctionService] handleApiRequest called for "${functionName}".`); // Log entry
39
- DR.logger.info(`[DOFunctionService] Calling DR.tracer.startSpan for "${functionName}"...`); // Log before startSpan
40
- return DR.tracer.startSpan(functionName, async (span) => {
41
- DR.logger.info(`[DOFunctionService] Tracer span callback started for "${functionName}".`); // Log span callback start
42
- const rawOutput = {
43
- body: '',
44
- statusCode: 200,
45
- headers: {
46
- 'Content-Type': 'application/octet-stream'
47
- }
48
- };
49
- const defaultOutput = {
50
- success: false,
51
- errors: [],
52
- data: {}
53
- };
54
- try {
55
- DR.logger.info(`[DOFunctionService] Deserializing input for "${functionName}"...`); // Log before deserialize
56
- const input = this.deserializeInput(rawInputFromDO);
57
- DR.logger.info(`[DOFunctionService] Calling handler function for "${functionName}"...`); // Log before handler
58
- const output = await handler(input);
59
- DR.logger.info(`[DOFunctionService] Handler function finished for "${functionName}".`); // Log after handler
60
- DR.logger.info(`[DOFunctionService] Serializing output for "${functionName}"...`); // Log before serialize
61
- rawOutput.body = this.serializeOutput(output);
62
- if (!output.success) {
63
- DR.logger.warn(`[DOFunctionService] Handler reported failure for "${functionName}". Setting status code 400.`); // Log handler failure
64
- rawOutput.statusCode = 400;
65
- span?.setStatus({ code: 2, message: 'handler_error' });
66
- }
67
- else {
68
- DR.logger.success(`[DOFunctionService] Handler reported success for "${functionName}". Setting status code 200.`); // Log handler success
69
- span?.setStatus({ code: 1, message: 'ok' });
70
- }
71
- }
72
- catch (e) {
73
- DR.logger.error(`[DOFunctionService] Error caught in handleApiRequest for "${functionName}": ${String(e)}`); // Log error
74
- DR.tracer.captureException(e);
75
- span?.setStatus({ code: 2, message: 'internal_error' });
76
- const error = e;
77
- defaultOutput.errors.push(JSON.stringify(error, null, 2));
78
- rawOutput.body = JSON.stringify(defaultOutput);
79
- rawOutput.headers['Content-Type'] = 'application/json';
80
- rawOutput.statusCode = 500;
81
- }
82
- DR.logger.info(`[DOFunctionService] Tracer span callback finished for "${functionName}". Returning rawOutput.`); // Log span callback end
83
- return rawOutput;
84
- });
85
- }
86
- /**
87
- * Deserializes the raw input into a typed input object using type guards.
88
- * Handles raw HTTP input, the DO UI wrapper, or already deserialized input.
89
- *
90
- * @param inputFromDO - The raw input received from the DO environment.
91
- * @returns The deserialized input object of type TInput.
92
- */
93
- static deserializeInput(inputFromDO) {
94
- DR.logger.info(`[DOFunctionService] deserializeInput received: ${JSON.stringify(inputFromDO)}`);
95
- // 1. Check if it's the standard DOFunctionRawInput (from web: raw)
96
- if (isDOFunctionRawInput(inputFromDO)) {
97
- DR.logger.info('[DOFunctionService] Input matches DOFunctionRawInput (via type guard). Proceeding with raw deserialization.');
98
- const { http } = inputFromDO;
99
- const { body, isBase64Encoded, headers } = http;
100
- let decodedBody;
101
- if (isBase64Encoded) {
102
- DR.logger.info('[DOFunctionService] Body is base64 encoded, decoding...');
103
- decodedBody = Buffer.from(body, 'base64');
104
- }
105
- else {
106
- DR.logger.info('[DOFunctionService] Body is not base64 encoded, using utf8.');
107
- decodedBody = Buffer.from(body, 'utf8');
108
- }
109
- const isBson = headers['content-type'] === 'application/octet-stream';
110
- let requestData;
111
- if (isBson) {
112
- DR.logger.info('[DOFunctionService] Deserializing BSON body.');
113
- try {
114
- requestData = BSON.deserialize(decodedBody);
115
- }
116
- catch (bsonError) {
117
- DR.logger.error(`[DOFunctionService] BSON deserialization failed: ${String(bsonError)}. Falling back to JSON parse.`);
118
- try {
119
- requestData = JSON.parse(decodedBody.toString('utf8'));
120
- }
121
- catch (jsonError) {
122
- DR.logger.error(`[DOFunctionService] JSON fallback parse failed: ${String(jsonError)}`);
123
- throw new Error('Failed to deserialize input body as BSON or JSON.');
124
- }
125
- }
126
- }
127
- else {
128
- DR.logger.info('[DOFunctionService] Deserializing non-BSON body (assuming JSON).');
129
- try {
130
- requestData = JSON.parse(decodedBody.toString('utf8'));
131
- }
132
- catch (jsonError) {
133
- DR.logger.error(`[DOFunctionService] JSON parse failed: ${String(jsonError)}`);
134
- throw new Error('Failed to deserialize input body as JSON.');
135
- }
136
- }
137
- return requestData;
138
- }
139
- // 2. Assume it's already the correct TInput type
140
- else {
141
- DR.logger.info('[DOFunctionService] Input does not match RawInput. Assuming input is already deserialized TInput.');
142
- return inputFromDO;
143
- }
144
- }
145
- /**
146
- * Serializes the output object into a base64 string. This could be updated
147
- * to support other serialization methods in the future.
148
- *
149
- * @param output - The output object to serialize.
150
- * @returns The serialized output as a base64 string.
151
- */
152
- static serializeOutput(output) {
153
- const bsonBuffer = BSON.serialize(output);
154
- return Buffer.from(bsonBuffer).toString('base64');
155
- }
156
- }
157
- //# sourceMappingURL=DOFunctionService.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DOFunctionService.js","sourceRoot":"","sources":["../../../src/services/DOFunctionService/DOFunctionService.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,uBAAuB,CAAC;AAC3C,OAAO,EAAE,IAAI,EAAE,MAAM,MAAM,CAAC;AAQ5B,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,iBAAiB,MAAM,kCAAkC,CAAC;AACjE,OAAO,gBAAgB,MAAM,iCAAiC,CAAC;AAC/D,OAAO,gBAAgB,MAAM,iCAAiC,CAAC;AAE/D;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC;;OAEG;IACH,MAAM,CAAC,iBAAiB,GAAsB,iBAAiB,CAAC,WAAW,EAAE,CAAC;IAE9E;;OAEG;IACH,MAAM,CAAC,gBAAgB,GAAqB,gBAAgB,CAAC,WAAW,EAAE,CAAC;IAE3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