lixnet 1.1.6 → 1.1.8

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/dist/exports.d.ts CHANGED
@@ -2,3 +2,4 @@ import LixnetServer from "./lib/server";
2
2
  import LixnetClient from "./lib/client";
3
3
  import LixnetPeer from "./lib/peer";
4
4
  export { LixnetServer, LixnetClient, LixnetPeer };
5
+ export type { LXN_ServerClient_EventType, LXNServerHandler, FunctionInput, } from "./lib/types";
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import LixnetLog from "./util/log";
3
3
  export default class LixnetServer {
4
- constructor({ debugLog = false, logger, jsonResponseMaker = Response.json, }) {
4
+ constructor({ debugLog = false, logger, jsonResponseMaker = (data, init) => Response.json(data, init), }) {
5
5
  this.events = {};
6
6
  this.logger = LixnetLog;
7
7
  this.debugLog = false;
@@ -52,14 +52,23 @@ export default class LixnetServer {
52
52
  ? event.schema.parse(jsonData.input)
53
53
  : jsonData.input;
54
54
  try {
55
+ let additionalInit = {};
56
+ const newRequest = {
57
+ ...request,
58
+ setAdditionalInit: (init) => {
59
+ additionalInit = init;
60
+ },
61
+ };
55
62
  const result = await event.handler({
56
- request,
63
+ request: newRequest,
57
64
  ...validatedInput,
58
65
  });
59
66
  if (result instanceof Response) {
60
67
  return result;
61
68
  }
62
- return this.jsonResponseMaker({ data: result });
69
+ return this.jsonResponseMaker({
70
+ data: result.headers,
71
+ }, additionalInit);
63
72
  }
64
73
  catch (error) {
65
74
  return this.jsonResponseMaker({
@@ -5,3 +5,6 @@ export type DebugLogger = ({ error, message, }: {
5
5
  export type FunctionInput<T> = T extends (input: infer TInput) => any ? TInput : never;
6
6
  export type LXNServerHandler<Input> = (input: Input) => Promise<any> | any;
7
7
  export type LXN_ServerClient_EventType = Record<string, LXNServerHandler<any>>;
8
+ export type LXN_ServerClient_Request = Request & {
9
+ setAdditionalInit: (init: ResponseInit) => void;
10
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lixnet",
3
- "version": "1.1.6",
3
+ "version": "1.1.8",
4
4
  "author": "Nitlix",
5
5
  "license": "MIT",
6
6
  "repository": {