@aneuhold/core-ts-api-lib 1.0.19 → 1.0.21

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.
@@ -13,25 +13,31 @@ export type DOFunctionOutput = object;
13
13
  * which is a string. This string must be parsed using EJSON.parse.
14
14
  */
15
15
  export interface DOFunctionRawInput {
16
- data: string;
16
+ /**
17
+ * There are many other properties in the `http` object, but only the body
18
+ * property is used.
19
+ */
20
+ http: {
21
+ /**
22
+ * The body property needs to be parsed with atob, then put through some
23
+ * other processing.
24
+ */
25
+ body: string;
26
+ };
17
27
  }
18
28
  /**
19
29
  * Raw output from a Digital Ocean function must always be an object with
20
- * a body property. The body property must also be an object.
30
+ * a body property. The body property must be a string that is base64 encoded
31
+ * or an object. With how this project is set up, it will always be base64
32
+ * encoded to support BSON types.
21
33
  */
22
34
  export interface DOFunctionRawOutput {
23
35
  /**
24
- * The body is an object, which means it will automatically be serialized to
25
- * JSON and the Content-Type header will be set to application/json.
26
- *
27
- * Because the output typically depends on bson, the data must be serialized
28
- * to EJSON using the EJSON.stringify. Then when it is received, it must be
29
- * parsed using EJSON.parse.
36
+ * The body is a base64 encoded string.
30
37
  */
31
- body: {
32
- success: boolean;
33
- errors: string[];
34
- data: string;
38
+ body: string;
39
+ headers: {
40
+ 'Content-Type': 'application/octet-stream';
35
41
  };
36
42
  }
37
43
  export interface DOFunctionCallOutput<TOutput extends DOFunctionOutput> {
@@ -52,8 +58,11 @@ export default abstract class DOFunction<TInput extends DOFunctionInput, TOutput
52
58
  protected constructor();
53
59
  setUrl(url: string): void;
54
60
  /**
55
- * A generic call method for any digital ocean function.
61
+ * A generic call method for any Digital Ocean Function from the client.
62
+ * This gets pretty crazy with the serialization logic. It has been tested
63
+ * heavily.
56
64
  */
57
65
  call(input: TInput): Promise<DOFunctionCallOutput<TOutput>>;
66
+ private decodeArrayBuffer;
58
67
  }
59
68
  //# 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,IAAI,EAAE,MAAM,CAAC;CACd;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;;;;OAOG;IACH,IAAI,EAAE;QACJ,OAAO,EAAE,OAAO,CAAC;QACjB,MAAM,EAAE,MAAM,EAAE,CAAC;QACjB,IAAI,EAAE,MAAM,CAAC;KACd,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;;OAEG;IACG,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;CAsBlE"}
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"}
@@ -18,29 +18,28 @@ class DOFunction {
18
18
  this.url = url;
19
19
  }
20
20
  /**
21
- * A generic call method for any digital ocean function.
21
+ * A generic call method for any Digital Ocean Function from the client.
22
+ * This gets pretty crazy with the serialization logic. It has been tested
23
+ * heavily.
22
24
  */
23
25
  async call(input) {
24
26
  if (!this.url) {
25
27
  throw new Error(`${this.functionName} URL is not set`);
26
28
  }
27
- const rawInput = {
28
- data: bson_1.EJSON.stringify(input, { relaxed: false })
29
- };
30
29
  const result = await fetch(`${this.url}`, {
31
30
  method: 'POST',
32
31
  headers: {
33
- 'Content-Type': 'application/json'
32
+ 'Content-Type': 'application/octet-stream'
34
33
  },
35
- body: JSON.stringify(rawInput)
34
+ // It isn't clear why this works by itself. It comes in to the function
35
+ // as a base64 string.
36
+ body: bson_1.BSON.serialize(input)
36
37
  });
37
- // This is the reduced form of the DOFunctionRawOutput. Without the body.
38
- const json = await result.json();
39
- return {
40
- success: json.success,
41
- errors: json.errors,
42
- data: bson_1.EJSON.parse(json.data)
43
- };
38
+ return this.decodeArrayBuffer(await result.arrayBuffer());
39
+ }
40
+ decodeArrayBuffer(buffer) {
41
+ const bytes = new Uint8Array(buffer);
42
+ return bson_1.BSON.deserialize(bytes);
44
43
  }
45
44
  }
46
45
  exports.default = DOFunction;
@@ -18,5 +18,7 @@ export default class DOFunctionService {
18
18
  * unexpected happened.
19
19
  */
20
20
  static handleApiRequest<TInput extends DOFunctionInput, TOutput extends DOFunctionOutput>(rawInput: DOFunctionRawInput, handler: (input: TInput) => Promise<DOFunctionCallOutput<TOutput>>): Promise<DOFunctionRawOutput>;
21
+ private static deserializeInput;
22
+ private static serializeOutput;
21
23
  }
22
24
  //# sourceMappingURL=DOFunctionService.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"DOFunctionService.d.ts","sourceRoot":"","sources":["../../../src/services/DOFunctionService/DOFunctionService.ts"],"names":[],"mappings":"AACA,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,cAAc,CAAC;AACtB,OAAO,iBAAiB,MAAM,+BAA+B,CAAC;AAC9D,OAAO,gBAAgB,MAAM,8BAA8B,CAAC;AAC5D,OAAO,gBAAgB,MAAM,8BAA8B,CAAC;AAE5D;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC,MAAM,CAAC,iBAAiB,oBAAmC;IAE3D,MAAM,CAAC,gBAAgB,mBAAkC;IAEzD,MAAM,CAAC,gBAAgB,mBAAkC;IAEzD;;;;;;;OAOG;WACU,gBAAgB,CAC3B,MAAM,SAAS,eAAe,EAC9B,OAAO,SAAS,gBAAgB,EAEhC,QAAQ,EAAE,kBAAkB,EAC5B,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,GACjE,OAAO,CAAC,mBAAmB,CAAC;CAmBhC"}
1
+ {"version":3,"file":"DOFunctionService.d.ts","sourceRoot":"","sources":["../../../src/services/DOFunctionService/DOFunctionService.ts"],"names":[],"mappings":"AACA,OAAO,EACL,oBAAoB,EACpB,eAAe,EACf,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,cAAc,CAAC;AACtB,OAAO,iBAAiB,MAAM,+BAA+B,CAAC;AAC9D,OAAO,gBAAgB,MAAM,8BAA8B,CAAC;AAC5D,OAAO,gBAAgB,MAAM,8BAA8B,CAAC;AAE5D;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,iBAAiB;IACpC,MAAM,CAAC,iBAAiB,oBAAmC;IAE3D,MAAM,CAAC,gBAAgB,mBAAkC;IAEzD,MAAM,CAAC,gBAAgB,mBAAkC;IAEzD;;;;;;;OAOG;WACU,gBAAgB,CAC3B,MAAM,SAAS,eAAe,EAC9B,OAAO,SAAS,gBAAgB,EAEhC,QAAQ,EAAE,kBAAkB,EAC5B,OAAO,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC,GACjE,OAAO,CAAC,mBAAmB,CAAC;IAwB/B,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAY/B,OAAO,CAAC,MAAM,CAAC,eAAe;CAM/B"}
@@ -23,24 +23,41 @@ class DOFunctionService {
23
23
  * unexpected happened.
24
24
  */
25
25
  static async handleApiRequest(rawInput, handler) {
26
- const input = bson_1.EJSON.parse(rawInput.data);
26
+ const input = this.deserializeInput(rawInput);
27
27
  const rawOutput = {
28
- body: {
29
- success: false,
30
- errors: [],
31
- data: ''
28
+ body: '',
29
+ headers: {
30
+ 'Content-Type': 'application/octet-stream'
32
31
  }
33
32
  };
33
+ // Default output if something goes wrong
34
+ const defaultOutput = {
35
+ success: false,
36
+ errors: [],
37
+ data: {}
38
+ };
34
39
  try {
35
40
  const output = await handler(input);
36
- rawOutput.body.success = output.success;
37
- rawOutput.body.errors = output.errors;
38
- rawOutput.body.data = bson_1.EJSON.stringify(output.data, { relaxed: false });
41
+ rawOutput.body = this.serializeOutput(output);
39
42
  }
40
43
  catch (error) {
41
- rawOutput.body.errors.push(JSON.stringify(error));
44
+ defaultOutput.errors.push(JSON.stringify(error));
45
+ rawOutput.body = this.serializeOutput(defaultOutput);
42
46
  }
43
47
  return rawOutput;
44
48
  }
49
+ static deserializeInput(rawInput) {
50
+ const binaryString = atob(rawInput.http.body);
51
+ const len = binaryString.length;
52
+ const bytes = new Uint8Array(len);
53
+ for (let i = 0; i < len; i += 1) {
54
+ bytes[i] = binaryString.charCodeAt(i);
55
+ }
56
+ return bson_1.BSON.deserialize(bytes);
57
+ }
58
+ static serializeOutput(output) {
59
+ const uInt8Array = bson_1.BSON.serialize(output);
60
+ return Buffer.from(uInt8Array).toString('base64');
61
+ }
45
62
  }
46
63
  exports.default = DOFunctionService;
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { UUID } from 'crypto';
3
- import { DashboardTask, DashboardUserConfig } from '@aneuhold/core-ts-db-lib';
3
+ import { DashboardTask, DashboardUserConfig, UserCTO } from '@aneuhold/core-ts-db-lib';
4
4
  import { Translations } from '../../../types/Translations';
5
5
  import DOFunction, { DOFunctionInput, DOFunctionOutput } from '../DOFunction';
6
6
  export interface ProjectDashboardOptions {
@@ -8,6 +8,7 @@ export interface ProjectDashboardOptions {
8
8
  translations?: boolean;
9
9
  userConfig?: boolean;
10
10
  tasks?: boolean;
11
+ collaborators?: boolean;
11
12
  };
12
13
  insert?: {
13
14
  tasks?: DashboardTask[];
@@ -28,6 +29,7 @@ export interface ProjectDashboardOutput extends DOFunctionOutput {
28
29
  translations?: Translations;
29
30
  userConfig?: DashboardUserConfig;
30
31
  tasks?: DashboardTask[];
32
+ collaborators?: UserCTO[];
31
33
  }
32
34
  /**
33
35
  * The Digital Ocean function which handles all data requests for the
@@ -1 +1 @@
1
- {"version":3,"file":"projectDashboard.d.ts","sourceRoot":"","sources":["../../../../src/services/DOFunctionService/functions/projectDashboard.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,UAAU,EAAE,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAE9E,MAAM,WAAW,uBAAuB;IACtC,GAAG,CAAC,EAAE;QACJ,YAAY,CAAC,EAAE,OAAO,CAAC;QACvB,UAAU,CAAC,EAAE,OAAO,CAAC;QACrB,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB,CAAC;IACF,MAAM,CAAC,EAAE;QACP,KAAK,CAAC,EAAE,aAAa,EAAE,CAAC;KACzB,CAAC;IACF,MAAM,CAAC,EAAE;QACP,UAAU,CAAC,EAAE,mBAAmB,CAAC;QACjC,KAAK,CAAC,EAAE,aAAa,EAAE,CAAC;KACzB,CAAC;IACF,MAAM,CAAC,EAAE;QACP,KAAK,CAAC,EAAE,aAAa,EAAE,CAAC;KACzB,CAAC;CACH;AAED,MAAM,WAAW,qBAAsB,SAAQ,eAAe;IAC5D,MAAM,EAAE,IAAI,CAAC;IACb,OAAO,EAAE,uBAAuB,CAAC;CAClC;AAED,MAAM,WAAW,sBAAuB,SAAQ,gBAAgB;IAC9D,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,UAAU,CAAC,EAAE,mBAAmB,CAAC;IACjC,KAAK,CAAC,EAAE,aAAa,EAAE,CAAC;CACzB;AAED;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,UAAU,CACtD,qBAAqB,EACrB,sBAAsB,CACvB;IACC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAmB;IAE1C,OAAO;IAIP,MAAM,CAAC,WAAW;CAMnB"}
1
+ {"version":3,"file":"projectDashboard.d.ts","sourceRoot":"","sources":["../../../../src/services/DOFunctionService/functions/projectDashboard.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC;AAC9B,OAAO,EACL,aAAa,EACb,mBAAmB,EACnB,OAAO,EACR,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,UAAU,EAAE,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AAE9E,MAAM,WAAW,uBAAuB;IACtC,GAAG,CAAC,EAAE;QACJ,YAAY,CAAC,EAAE,OAAO,CAAC;QACvB,UAAU,CAAC,EAAE,OAAO,CAAC;QACrB,KAAK,CAAC,EAAE,OAAO,CAAC;QAChB,aAAa,CAAC,EAAE,OAAO,CAAC;KACzB,CAAC;IACF,MAAM,CAAC,EAAE;QACP,KAAK,CAAC,EAAE,aAAa,EAAE,CAAC;KACzB,CAAC;IACF,MAAM,CAAC,EAAE;QACP,UAAU,CAAC,EAAE,mBAAmB,CAAC;QACjC,KAAK,CAAC,EAAE,aAAa,EAAE,CAAC;KACzB,CAAC;IACF,MAAM,CAAC,EAAE;QACP,KAAK,CAAC,EAAE,aAAa,EAAE,CAAC;KACzB,CAAC;CACH;AAED,MAAM,WAAW,qBAAsB,SAAQ,eAAe;IAC5D,MAAM,EAAE,IAAI,CAAC;IACb,OAAO,EAAE,uBAAuB,CAAC;CAClC;AAED,MAAM,WAAW,sBAAuB,SAAQ,gBAAgB;IAC9D,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,UAAU,CAAC,EAAE,mBAAmB,CAAC;IACjC,KAAK,CAAC,EAAE,aAAa,EAAE,CAAC;IACxB,aAAa,CAAC,EAAE,OAAO,EAAE,CAAC;CAC3B;AAED;;;GAGG;AACH,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,UAAU,CACtD,qBAAqB,EACrB,sBAAsB,CACvB;IACC,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAmB;IAE1C,OAAO;IAIP,MAAM,CAAC,WAAW;CAMnB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aneuhold/core-ts-api-lib",
3
- "version": "1.0.19",
3
+ "version": "1.0.21",
4
4
  "description": "A library for interacting with the backend and defining the backend API for personal projects.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -34,7 +34,7 @@
34
34
  "test": "jest"
35
35
  },
36
36
  "dependencies": {
37
- "@aneuhold/core-ts-db-lib": "^1.0.16",
37
+ "@aneuhold/core-ts-db-lib": "^1.0.18",
38
38
  "@aneuhold/core-ts-lib": "^1.1.9",
39
39
  "bson": "^6.2.0"
40
40
  },