@creator.co/wapi 1.2.0-beta9 → 1.2.1-beta1

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/README.md CHANGED
@@ -5,5 +5,4 @@ TODOs:
5
5
  - sast
6
6
  - js-docs
7
7
  - readme docs
8
- - improve types
9
- - cleanup deps
8
+ - improve types
package/dist/index.d.ts CHANGED
@@ -5,6 +5,7 @@ import Process from "./src/BaseEvent/Process";
5
5
  import Transaction from "./src/BaseEvent/Transaction";
6
6
  import Configuration from "./src/Config/Configuration";
7
7
  import Crypto from "./src/Crypto/Crypto";
8
+ import JWT from "./src/Crypto/JWT";
8
9
  import Mailer from "./src/Mailer/Mailer";
9
10
  import Router, { Route } from "./src/Server/Router";
10
- export { Transaction, Process, EventProcessor, Router, Mailer, Crypto, Configuration, Response, Utils, Route, };
11
+ export { Transaction, Process, EventProcessor, Router, Mailer, Crypto, JWT, Configuration, Response, Utils, Route, };
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Utils = exports.Response = exports.Configuration = exports.Crypto = exports.Mailer = exports.Router = exports.EventProcessor = exports.Process = exports.Transaction = void 0;
3
+ exports.Utils = exports.Response = exports.Configuration = exports.JWT = exports.Crypto = exports.Mailer = exports.Router = exports.EventProcessor = exports.Process = exports.Transaction = void 0;
4
4
  var Response_1 = require("./src/API/Response");
5
5
  exports.Response = Response_1.default;
6
6
  var Utils_1 = require("./src/API/Utils");
@@ -15,6 +15,8 @@ var Configuration_1 = require("./src/Config/Configuration");
15
15
  exports.Configuration = Configuration_1.default;
16
16
  var Crypto_1 = require("./src/Crypto/Crypto");
17
17
  exports.Crypto = Crypto_1.default;
18
+ var JWT_1 = require("./src/Crypto/JWT");
19
+ exports.JWT = JWT_1.default;
18
20
  var Mailer_1 = require("./src/Mailer/Mailer");
19
21
  exports.Mailer = Mailer_1.default;
20
22
  var Router_1 = require("./src/Server/Router");
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,+CAAyC;AAqBvC,mBArBK,kBAAQ,CAqBL;AApBV,yCAAmC;AAsBjC,gBAtBK,eAAK,CAsBL;AArBP,iEAA2D;AAYzD,yBAZK,wBAAc,CAYL;AAXhB,mDAA6C;AAU3C,kBAVK,iBAAO,CAUL;AATT,2DAAqD;AAQnD,sBARK,qBAAW,CAQL;AAPb,4DAAsD;AAcpD,wBAdK,uBAAa,CAcL;AAbf,8CAAwC;AAYtC,iBAZK,gBAAM,CAYL;AAXR,8CAAwC;AAUtC,iBAVK,gBAAM,CAUL;AATR,8CAAmD;AAOjD,iBAPK,gBAAM,CAOL"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;AAAA,+CAAyC;AAuBvC,mBAvBK,kBAAQ,CAuBL;AAtBV,yCAAmC;AAwBjC,gBAxBK,eAAK,CAwBL;AAvBP,iEAA2D;AAazD,yBAbK,wBAAc,CAaL;AAZhB,mDAA6C;AAW3C,kBAXK,iBAAO,CAWL;AAVT,2DAAqD;AASnD,sBATK,qBAAW,CASL;AARb,4DAAsD;AAgBpD,wBAhBK,uBAAa,CAgBL;AAff,8CAAwC;AAatC,iBAbK,gBAAM,CAaL;AAZR,wCAAkC;AAahC,cAbK,aAAG,CAaL;AAZL,8CAAwC;AAUtC,iBAVK,gBAAM,CAUL;AATR,8CAAmD;AAOjD,iBAPK,gBAAM,CAOL"}
package/dist/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@creator.co/wapi",
3
- "version": "1.2.0-beta8",
3
+ "version": "1.2.1-beta1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -28,6 +28,7 @@
28
28
  "email-templates": "^11.1.1",
29
29
  "express": "^4.18.2",
30
30
  "json-stringify-safe": "^5.0.1",
31
+ "jsonwebtoken": "^9.0.2",
31
32
  "node-cache": "^5.1.2",
32
33
  "parse-duration": "^1.1.0",
33
34
  "sha1": "^1.1.1",
@@ -38,6 +39,7 @@
38
39
  "devDependencies": {
39
40
  "@types/aws-lambda": "^8.10.119",
40
41
  "@types/express": "^4.17.19",
42
+ "@types/jsonwebtoken": "^9.0.3",
41
43
  "@types/node": "^20.5.7",
42
44
  "@typescript-eslint/eslint-plugin": "^6.5.0",
43
45
  "@typescript-eslint/parser": "^6.5.0",
@@ -1,6 +1,6 @@
1
1
  import type { Context, APIGatewayEvent } from "aws-lambda";
2
2
  import Logger from "../Logger/Logger";
3
- export default class Request<T> {
3
+ export default class Request<InputType> {
4
4
  private requestEvent;
5
5
  private context;
6
6
  constructor(requestEvent: APIGatewayEvent, context: Context, logger: Logger);
@@ -10,7 +10,7 @@ export default class Request<T> {
10
10
  getContextParam(cxtParam: string): any | null;
11
11
  containsPathParam(paramName: string): boolean;
12
12
  getPathParam(paramName: string): string | null;
13
- getBody(): T;
13
+ getBody(): InputType;
14
14
  getPath(): string;
15
15
  getMethod(): string;
16
16
  getPathParams(): object | null;
@@ -4,7 +4,7 @@ export type ResponseErrorType = {
4
4
  err: string;
5
5
  errCode?: string;
6
6
  };
7
- export default class Response<B = null> {
7
+ export default class Response<BodyType = null> {
8
8
  private _statusCode;
9
9
  private _body;
10
10
  private _isPipingOut;
@@ -13,17 +13,17 @@ export default class Response<B = null> {
13
13
  readonly rawBody: boolean;
14
14
  readonly throwOnErrors: boolean;
15
15
  readonly disableTransactionID: boolean;
16
- constructor(statusCode: number, body: B, optBehaviour?: {
16
+ constructor(statusCode: number, body: BodyType, optBehaviour?: {
17
17
  shouldStream?: boolean;
18
18
  rawBody?: boolean;
19
19
  throwOnErrors?: boolean;
20
20
  disableTransactionID?: boolean;
21
21
  } | undefined);
22
22
  getCode(): number;
23
- getBody(): B;
23
+ getBody(): BodyType;
24
24
  appendIntoBody(key: string, value: any): void;
25
25
  appendHeader(key: string, value: any): void;
26
- build(context: Context, transaction: Transaction<any, B>, _optDoNotCallContext: boolean): Promise<void>;
26
+ build(context: Context, transaction: Transaction<any, any, any>, _optDoNotCallContext: boolean): Promise<void>;
27
27
  private _pipe;
28
28
  private _rawContext;
29
29
  static MissingParamResponse(paramName: string): Response<ResponseErrorType>;
@@ -31,9 +31,9 @@ export default class Response<B = null> {
31
31
  static BadRequestResponse(msg?: string, errCode?: string, optBody?: any): Response<ResponseErrorType>;
32
32
  static BadRequestResponseWithRollback(msg: string, errCode: string, optBody?: any): Response<ResponseErrorType>;
33
33
  static UnauthorizedResponse(msg: string, errCode: string): Response<ResponseErrorType>;
34
- static SuccessResponse<T>(body: T): Response<T>;
34
+ static SuccessResponse<BodyType>(body: BodyType): Response<BodyType>;
35
35
  static RedirectResponse(url: string): Response<null>;
36
36
  static SuccessNoContentResponse(): Response<null>;
37
37
  static SuccessStreamResponse(stream: any, contentType: string): Response;
38
- static SimpleResponse<T>(body: T, optionalCode?: number): Response<T>;
38
+ static SimpleResponse<BodyType>(body: BodyType, optionalCode?: number): Response<BodyType>;
39
39
  }
@@ -1 +1 @@
1
- {"version":3,"file":"Response.js","sourceRoot":"","sources":["../../../src/API/Response.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,sCAAgC;AAChC,EAAE;AACF;IAA0B,+BAAK;IAC7B,qBAAY,IAAS;QAArB,iBAIC;QAHC,IAAM,GAAG,GAAG,IAAI,IAAI,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,gBAAgB,CAAA;gBAClE,kBAAM,GAAG,CAAC;QACV,KAAI,CAAC,IAAI,GAAG,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,cAAc,CAAA;;IAC9D,CAAC;IACH,kBAAC;A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,UAAwC,IAAc;QACpD,OAAO,IAAI,QAAQ,CAAW,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAa,CAAC,CAAA;IACpE,CAAC;IACa,yBAAgB,GAA9B,UAA+B,GAAW;QACxC,IAAM,IAAI,GAAG,IAAI,QAAQ,CAAO,GAAG,EAAE,IAAI,CAAC,CAAA;QAC1C,IAAI,CAAC,YAAY,CAAC,UAAU,EAAE,GAAG,CAAC,CAAA;QAClC,OAAO,IAAI,CAAA;IACb,CAAC;IACa,iCAAwB,GAAtC;QACE,OAAO,IAAI,QAAQ,CAAO,GAAG,EAAE,IAAI,CAAC,CAAA;IACtC,CAAC;IACa,8BAAqB,GAAnC,UACE,MAAW,EACX,WAAmB;QAEnB,IAAM,IAAI,GAAG,IAAI,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE;YACnD,YAAY,EAAE,IAAI;SACnB,CAAC,CAAA;QACF,IAAI,CAAC,YAAY,CAAC,YAAY,EAAE,YAAY,CAAC,CAAA;QAC7C,IAAI,WAAW;YAAE,IAAI,CAAC,YAAY,CAAC,cAAc,EAAE,WAAW,CAAC,CAAA;QAC/D,OAAO,IAAI,CAAA;IACb,CAAC;IACa,uBAAc,GAA5B,UACE,IAAc,EACd,YAAqB;QAErB,IAAM,IAAI,GAAG,IAAI,QAAQ,CAAW,YAAY,IAAI,GAAG,EAAE,IAAI,CAAC,CAAA;QAC9D,OAAO,IAAI,CAAA;IACb,CAAC;IACH,eAAC;AAAD,CAAC,AAhMD,IAgMC"}
@@ -1,7 +1,7 @@
1
1
  import type { Context, SQSBatchResponse, SQSEvent } from "aws-lambda";
2
2
  import Transaction, { TransactionConfig } from "./Transaction";
3
3
  import Response, { ResponseErrorType } from "../API/Response";
4
- export type EventProcessorExecution = (transaction: Transaction<null, ResponseErrorType>, recordContent: string | object) => Promise<Response | SQSBatchResponse>;
4
+ export type EventProcessorExecution = (transaction: Transaction<null, ResponseErrorType, SQSBatchResponse>, recordContent: string | object) => Promise<Response | SQSBatchResponse>;
5
5
  export default class EventProcessor {
6
6
  private readonly _allowFailure;
7
7
  private readonly _apiConfig;
@@ -1,27 +1,27 @@
1
- import type { APIGatewayEvent, Context, SQSBatchResponse, SQSEvent } from "aws-lambda";
1
+ import type { APIGatewayEvent, Context, SQSEvent } from "aws-lambda";
2
2
  import Request from "../API/Request";
3
3
  import Response, { ResponseErrorType } from "../API/Response";
4
4
  import Logger, { LoggerConfig } from "../Logger/Logger";
5
5
  import Publisher, { PublisherConfig } from "../Publisher/Publisher";
6
- export type TransactionExecution<T, B = null> = (transaction: T) => Promise<Response<B> | SQSBatchResponse>;
6
+ export type TransactionExecution<TransactionType, ResponseInnerType, MiscRespType = null> = (transaction: TransactionType) => Promise<Response<ResponseInnerType> | Response<ResponseErrorType> | MiscRespType>;
7
7
  export type TransactionConfig = {
8
8
  throwOnErrors?: boolean;
9
9
  syncReturn?: boolean;
10
10
  logger?: LoggerConfig;
11
11
  publisher?: PublisherConfig;
12
12
  };
13
- export default class Transaction<T = object, B = null> {
13
+ export default class Transaction<InputType = object, ResponseInnerType = null, MiscRespType = null> {
14
14
  private event;
15
15
  private context;
16
16
  private response;
17
17
  private syncReturn;
18
18
  private retrowErrors;
19
19
  readonly logger: Logger;
20
- readonly request: Request<T>;
20
+ readonly request: Request<InputType>;
21
21
  readonly publisher: Publisher;
22
- responseProxy: (response: Response<B>) => Promise<void>;
22
+ responseProxy: (response: Response<ResponseInnerType>) => Promise<void>;
23
23
  constructor(event: APIGatewayEvent | SQSEvent, context: Context, config?: TransactionConfig);
24
- execute(executionFunc: TransactionExecution<Transaction<T, B>, B>): Promise<Response<B | ResponseErrorType> | null | SQSBatchResponse>;
24
+ execute(executionFunc: TransactionExecution<Transaction<InputType, ResponseInnerType, MiscRespType>, ResponseInnerType, MiscRespType>): Promise<Response<ResponseInnerType | ResponseErrorType> | MiscRespType>;
25
25
  private iexecute;
26
26
  private executeDBTransactions;
27
27
  private executeLoggerFlush;
@@ -1 +1 @@
1
- {"version":3,"file":"Transaction.js","sourceRoot":"","sources":["../../../src/BaseEvent/Transaction.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,0CAAoC;AACpC,4CAA6D;AAC7D,sCAAgC;AAChC,2CAAuD;AACvD,oDAAmE;AAenE;IAWE,EAAE;IACF,qBACE,KAAiC,EACjC,OAAgB,EAChB,MAA0B;QAE1B,IAAM,aAAa,GAAG,OAAO,CAAC,YAAY;YACxC,CAAC,CAAC,OAAO,CAAC,YAAY;YACtB,CAAC,CAAmB,KAAM,CAAC,cAAc;gBACzC,CAAC,CAAmB,KAAM,CAAC,cAAc,CAAC,SAAS;gBACnD,CAAC,CAAC,SAAS,CAAA;QACb,kBAAkB;QAClB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAA;QACpB,kJAAkJ;QAClJ,IAAI,CAAC,aAAa,GAAG,IAAI,CAAA;QACzB,oBAAoB;QACpB,IAAI,CAAC,UAAU,GAAG,CAAC,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,UAAU,CAAA,CAAA;QACtC,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC,CAAA,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,aAAa,CAAA,CAAA,CAAC,4BAA4B;QACxE,aAAa;QACb,IAAI,CAAC,MAAM,GAAG,IAAI,gBAAM,CAAC,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,MAAM,EAAE,aAAa,CAAC,CAAA;QACvD,IAAI,CAAC,OAAO,GAAG,IAAI,iBAAO,CAAI,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,CAAA;QACpE,I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mentType;
3
+ isLocal?: boolean;
4
+ isRemote?: boolean;
5
5
  required?: boolean;
6
6
  cachingPolicy?: string;
7
7
  };
8
8
  };
9
- type ExtractRemote<Type> = keyof {
10
- [Property in keyof Type]: Type[Property] extends {
11
- type: EnvironmentType.PlainRemote | EnvironmentType.SecureRemote;
12
- } ? Property : never;
9
+ type ExtractRemote<Type> = {
10
+ [Property in keyof Type]-?: Type[Property] extends {
11
+ isRemote: true;
12
+ } ? Property : null;
13
13
  };
14
- type ExtractLocal<Type> = keyof {
15
- [Property in keyof Type]: Type[Property] extends {
16
- type: EnvironmentType.Local;
17
- } ? Property : never;
14
+ type ExtractLocal<Type> = {
15
+ [Property in keyof Type]-?: Type[Property] extends {
16
+ isLocal: true;
17
+ } ? Property : null;
18
18
  };
19
+ type OmitKeysByValueType<T, U> = {
20
+ [P in keyof T]: T[P] extends U ? never : P;
21
+ }[keyof T];
22
+ type OmitByValueType<T, V> = T extends infer _ ? {
23
+ [key in OmitKeysByValueType<T, V>]: T[key];
24
+ } : never;
19
25
  export default class Configuration<T extends ConfigurationSchema> {
20
26
  private readonly schema;
21
27
  private readonly remotePrefix;
22
28
  constructor(schema: T, remotePrefix: string);
23
- get(propName: ExtractLocal<T>): any;
24
- asyncGet(propName: ExtractRemote<T>): Promise<any>;
29
+ get(propName: keyof OmitByValueType<ExtractLocal<T>, null>): any;
30
+ asyncGet(propName: keyof OmitByValueType<ExtractRemote<T>, null>): Promise<any>;
25
31
  private getCachedValue;
26
32
  private cacheValue;
27
33
  }
@@ -47,33 +47,33 @@ var Configuration = /** @class */ (function () {
47
47
  this.remotePrefix = remotePrefix;
48
48
  }
49
49
  Configuration.prototype.get = function (propName) {
50
- propName = propName; // TODO: find a better way, this seems to come from keyof
51
- var propSchema = this.schema[propName];
52
- var v = this.getCachedValue(propName);
50
+ var propString = propName;
51
+ var propSchema = this.schema[propString];
52
+ var v = this.getCachedValue(propString);
53
53
  v =
54
54
  v ||
55
- new EnvironmentVar_1.default(propName, propSchema.type, propSchema.required, this.remotePrefix).syncResolve();
56
- this.cacheValue(propName, v, propSchema.cachingPolicy);
55
+ new EnvironmentVar_1.default(propString, EnvironmentVar_1.EnvironmentType.Local, propSchema.required, this.remotePrefix).syncResolve();
56
+ this.cacheValue(propString, v, propSchema.cachingPolicy);
57
57
  return v;
58
58
  };
59
59
  Configuration.prototype.asyncGet = function (propName) {
60
60
  return __awaiter(this, void 0, void 0, function () {
61
- var propSchema, v, _a;
61
+ var propString, propSchema, v, _a;
62
62
  return __generator(this, function (_b) {
63
63
  switch (_b.label) {
64
64
  case 0:
65
- propName = propName; // TODO: find a better way, this seems to come from keyof
66
- propSchema = this.schema[propName];
67
- v = this.getCachedValue(propName);
65
+ propString = propName;
66
+ propSchema = this.schema[propString];
67
+ v = this.getCachedValue(propString);
68
68
  _a = v;
69
69
  if (_a) return [3 /*break*/, 2];
70
- return [4 /*yield*/, new EnvironmentVar_1.default(propName, propSchema.type, propSchema.required, this.remotePrefix).resolve()];
70
+ return [4 /*yield*/, new EnvironmentVar_1.default(propString, EnvironmentVar_1.EnvironmentType.PlainRemote, propSchema.required, this.remotePrefix).resolve()];
71
71
  case 1:
72
72
  _a = (_b.sent());
73
73
  _b.label = 2;
74
74
  case 2:
75
75
  v = _a;
76
- this.cacheValue(propName, v, propSchema.cachingPolicy);
76
+ this.cacheValue(propString, v, propSchema.cachingPolicy);
77
77
  return [2 /*return*/, v];
78
78
  }
79
79
  });
@@ -1 +1 @@
1
- {"version":3,"file":"Configuration.js","sourceRoot":"","sources":["../../../src/Config/Configuration.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qCAAsC;AACtC,+CAAgD;AAEhD,mDAAkE;AAElE,qCAAqC;AACrC,IAAM,UAAU,GAAG,IAAI,QAAQ,EAAE,CAAA;AA2BjC;IAGE,uBAAY,MAAS,EAAE,YAAoB;QACzC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CA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IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAA;wBAErC,KAAA,CAAC,CAAA;gCAAD,wBAAC;wBACA,qBAAM,IAAI,wBAAc,CACvB,UAAU,EACV,gCAAe,CAAC,WAAW,EAC3B,UAAU,CAAC,QAAQ,EACnB,IAAI,CAAC,YAAY,CAClB,CAAC,OAAO,EAAE,EAAA;;wBALX,KAAA,CAAC,SAKU,CAAC,CAAA;;;wBAPd,CAAC,KAOa,CAAA;wBACd,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,CAAC,EAAE,UAAU,CAAC,aAAa,CAAC,CAAA;wBACxD,sBAAO,CAAC,EAAA;;;;KACT;IACD,gBAAgB;IACR,sCAAc,GAAtB,UAAuB,QAAgB;QACrC,OAAO,UAAU,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;IACjC,CAAC;IACO,kCAAU,GAAlB,UACE,QAAgB,EAChB,KAAU,EACV,MAAqB;QAArB,uBAAA,EAAA,aAAqB;QAErB,UAAU,CAAC,GAAG,CAAC,QAAQ,EAAE,KAAK,EAAE,cAAc,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAA;IAC9D,CAAC;IACH,oBAAC;AAAD,CAAC,AAnDD,IAmDC"}
@@ -0,0 +1,17 @@
1
+ import * as jwt from "jsonwebtoken";
2
+ type JWTValidationResponse = {
3
+ isValid: true;
4
+ decodedToken: jwt.JwtPayload;
5
+ } | {
6
+ isValid: false;
7
+ isExpired?: boolean;
8
+ };
9
+ export default class JWT {
10
+ private readonly tokenClient;
11
+ private readonly tokenSecret;
12
+ private readonly defaultExpiration;
13
+ constructor(tokenClient: string, tokenSecret: string, defaultExpiration?: string);
14
+ createToken(data: object, expiration?: string): Promise<string>;
15
+ validateToken(token: string): Promise<JWTValidationResponse>;
16
+ }
17
+ export {};
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ var jwt = require("jsonwebtoken");
40
+ var JWT = /** @class */ (function () {
41
+ function JWT(tokenClient, tokenSecret, defaultExpiration) {
42
+ this.tokenClient = tokenClient;
43
+ this.tokenSecret = tokenSecret;
44
+ this.defaultExpiration = defaultExpiration;
45
+ }
46
+ //
47
+ JWT.prototype.createToken = function (data, expiration) {
48
+ return __awaiter(this, void 0, void 0, function () {
49
+ var exp;
50
+ return __generator(this, function (_a) {
51
+ exp = expiration || this.defaultExpiration;
52
+ return [2 /*return*/, jwt.sign(data, this.tokenSecret, exp ? { expiresIn: exp } : {})];
53
+ });
54
+ });
55
+ };
56
+ JWT.prototype.validateToken = function (token) {
57
+ return __awaiter(this, void 0, void 0, function () {
58
+ var isValid, payload;
59
+ return __generator(this, function (_a) {
60
+ try {
61
+ isValid = jwt.verify(token, this.tokenSecret);
62
+ if (!isValid)
63
+ throw new Error("Issue with token validation!");
64
+ else {
65
+ payload = jwt.decode(token, { json: true });
66
+ if (payload)
67
+ return [2 /*return*/, { isValid: true, decodedToken: payload }];
68
+ else
69
+ throw new Error("Issue while decoding token!");
70
+ }
71
+ }
72
+ catch (err) {
73
+ console.error(err);
74
+ if (err instanceof jwt.TokenExpiredError)
75
+ return [2 /*return*/, { isValid: false, isExpired: true }];
76
+ }
77
+ return [2 /*return*/, { isValid: false }];
78
+ });
79
+ });
80
+ };
81
+ return JWT;
82
+ }());
83
+ exports.default = JWT;
84
+ //# sourceMappingURL=JWT.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"JWT.js","sourceRoot":"","sources":["../../../src/Crypto/JWT.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,kCAAmC;AASnC;IAIE,aACE,WAAmB,EACnB,WAAmB,EACnB,iBAA0B;QAE1B,IAAI,CAAC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ionConfig, TransactionExecution } from "../BaseEve
4
4
  export interface Route<InputType = any, OutputType = any> {
5
5
  path: string;
6
6
  method: string;
7
- handler: TransactionExecution<Transaction<InputType>, OutputType | ResponseErrorType>;
7
+ handler: TransactionExecution<Transaction<InputType, OutputType | ResponseErrorType>, OutputType | ResponseErrorType>;
8
8
  inputSchema?: z.ZodObject<any>;
9
9
  }
10
10
  export type RouterConfig = TransactionConfig & {
@@ -1 +1 @@
1
- {"version":3,"file":"Router.js","sourceRoot":"","sources":["../../../src/Server/Router.ts"],"names":[],"mappings":";;AAEA,yDAAmD;AACnD,uCAAiC;AAEjC,sCAAgC;AA+BhC;IAGE,gBAAY,MAAoB;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,EAAE;YAC9B,CAAC,CAAC,IAAI,yBAAe,CAAC,MAAM,CAAC;YAC7B,CAAC,CAAC,IAAI,gBAAM,CAAC,MAAM,CAAC,CAAA;IACxB,CAAC;IACM,0BAAS,GAAhB;QACE,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAA;IAChC,CAAC;IACO,4BAAW,GAAnB;QACE,OAAO,eAAK,CAAC,qBAAqB,EAAE,CAAA;IACtC,CAAC;IACH,aAAC;AAAD,CAAC,AAfD,IAeC"}
1
+ {"version":3,"file":"Router.js","sourceRoot":"","sources":["../../../src/Server/Router.ts"],"names":[],"mappings":";;AAEA,yDAAmD;AACnD,uCAAiC;AAEjC,sCAAgC;AAqChC;IAGE,gBAAY,MAAoB;QAC9B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,EAAE;YAC9B,CAAC,CAAC,IAAI,yBAAe,CAAC,MAAM,CAAC;YAC7B,CAAC,CAAC,IAAI,gBAAM,CAAC,MAAM,CAAC,CAAA;IACxB,CAAC;IACM,0BAAS,GAAhB;QACE,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,CAAA;IAChC,CAAC;IACO,4BAAW,GAAnB;QACE,OAAO,eAAK,CAAC,qBAAqB,EAAE,CAAA;IACtC,CAAC;IACH,aAAC;AAAD,CAAC,AAfD,IAeC"}
package/index.ts CHANGED
@@ -5,6 +5,7 @@ import Process from "./src/BaseEvent/Process"
5
5
  import Transaction from "./src/BaseEvent/Transaction"
6
6
  import Configuration from "./src/Config/Configuration"
7
7
  import Crypto from "./src/Crypto/Crypto"
8
+ import JWT from "./src/Crypto/JWT"
8
9
  import Mailer from "./src/Mailer/Mailer"
9
10
  import Router, { Route } from "./src/Server/Router"
10
11
 
@@ -17,6 +18,7 @@ export {
17
18
  // Externally initialized clients
18
19
  Mailer,
19
20
  Crypto,
21
+ JWT,
20
22
  Configuration,
21
23
  // Responses
22
24
  Response,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@creator.co/wapi",
3
- "version": "1.2.0-beta9",
3
+ "version": "1.2.1-beta1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -28,6 +28,7 @@
28
28
  "email-templates": "^11.1.1",
29
29
  "express": "^4.18.2",
30
30
  "json-stringify-safe": "^5.0.1",
31
+ "jsonwebtoken": "^9.0.2",
31
32
  "node-cache": "^5.1.2",
32
33
  "parse-duration": "^1.1.0",
33
34
  "sha1": "^1.1.1",
@@ -38,6 +39,7 @@
38
39
  "devDependencies": {
39
40
  "@types/aws-lambda": "^8.10.119",
40
41
  "@types/express": "^4.17.19",
42
+ "@types/jsonwebtoken": "^9.0.3",
41
43
  "@types/node": "^20.5.7",
42
44
  "@typescript-eslint/eslint-plugin": "^6.5.0",
43
45
  "@typescript-eslint/parser": "^6.5.0",
@@ -3,7 +3,7 @@ import type { Context, APIGatewayEvent } from "aws-lambda"
3
3
  import Utils from "./Utils"
4
4
  import Logger from "../Logger/Logger"
5
5
  //
6
- export default class Request<T> {
6
+ export default class Request<InputType> {
7
7
  private requestEvent: APIGatewayEvent
8
8
  private context: Context
9
9
  constructor(requestEvent: APIGatewayEvent, context: Context, logger: Logger) {
@@ -49,7 +49,7 @@ export default class Request<T> {
49
49
  )
50
50
  }
51
51
  //body
52
- public getBody(): T {
52
+ public getBody(): InputType {
53
53
  let b: any = null
54
54
  try {
55
55
  b = this.requestEvent.body
@@ -16,7 +16,7 @@ export type ResponseErrorType = {
16
16
  errCode?: string
17
17
  }
18
18
  //
19
- export default class Response<B = null> {
19
+ export default class Response<BodyType = null> {
20
20
  private _statusCode: number
21
21
  private _body: any
22
22
  private _isPipingOut: boolean
@@ -28,7 +28,7 @@ export default class Response<B = null> {
28
28
  //
29
29
  constructor(
30
30
  statusCode: number,
31
- body: B,
31
+ body: BodyType,
32
32
  optBehaviour?:
33
33
  | {
34
34
  shouldStream?: boolean
@@ -57,7 +57,7 @@ export default class Response<B = null> {
57
57
  public getCode(): number {
58
58
  return this._statusCode
59
59
  }
60
- public getBody(): B {
60
+ public getBody(): BodyType {
61
61
  return this._body
62
62
  }
63
63
  public appendIntoBody(key: string, value: any): void {
@@ -68,7 +68,7 @@ export default class Response<B = null> {
68
68
  }
69
69
  public async build(
70
70
  context: Context,
71
- transaction: Transaction<any, B>,
71
+ transaction: Transaction<any, any, any>,
72
72
  _optDoNotCallContext: boolean,
73
73
  ): Promise<void> {
74
74
  //Stream support
@@ -113,7 +113,7 @@ export default class Response<B = null> {
113
113
  }
114
114
  private _rawContext(
115
115
  context: Context,
116
- transaction: Transaction<null, B>,
116
+ transaction: Transaction<null, BodyType>,
117
117
  ): void {
118
118
  //log response and respond to context
119
119
  transaction.logger.debug(this._body)
@@ -179,8 +179,8 @@ export default class Response<B = null> {
179
179
  ...(errCode ? { errCode: errCode } : {}),
180
180
  })
181
181
  }
182
- public static SuccessResponse<T>(body: T): Response<T> {
183
- return new Response<T>(200, (body ? body : {}) as T)
182
+ public static SuccessResponse<BodyType>(body: BodyType): Response<BodyType> {
183
+ return new Response<BodyType>(200, (body ? body : {}) as BodyType)
184
184
  }
185
185
  public static RedirectResponse(url: string): Response<null> {
186
186
  const resp = new Response<null>(302, null)
@@ -201,8 +201,11 @@ export default class Response<B = null> {
201
201
  if (contentType) resp.appendHeader("Content-type", contentType)
202
202
  return resp
203
203
  }
204
- public static SimpleResponse<T>(body: T, optionalCode?: number): Response<T> {
205
- const resp = new Response<T>(optionalCode || 200, body)
204
+ public static SimpleResponse<BodyType>(
205
+ body: BodyType,
206
+ optionalCode?: number,
207
+ ): Response<BodyType> {
208
+ const resp = new Response<BodyType>(optionalCode || 200, body)
206
209
  return resp
207
210
  }
208
211
  }
@@ -6,7 +6,7 @@ import Globals from "../Globals"
6
6
 
7
7
  // Handler
8
8
  export type EventProcessorExecution = (
9
- transaction: Transaction<null, ResponseErrorType>,
9
+ transaction: Transaction<null, ResponseErrorType, SQSBatchResponse>,
10
10
  recordContent: string | object,
11
11
  ) => Promise<Response | SQSBatchResponse>
12
12
 
@@ -48,7 +48,7 @@ export default class EventProcessor {
48
48
  if (this._event.Records && this._event.Records.length > 0) {
49
49
  //safe check for empty events?
50
50
  //init transaction for all records
51
- return await new Transaction<null, null | ResponseErrorType>(
51
+ return await new Transaction<null, ResponseErrorType, SQSBatchResponse>(
52
52
  this._event,
53
53
  this._context,
54
54
  {
@@ -1,9 +1,4 @@
1
- import type {
2
- APIGatewayEvent,
3
- Context,
4
- SQSBatchResponse,
5
- SQSEvent,
6
- } from "aws-lambda"
1
+ import type { APIGatewayEvent, Context, SQSEvent } from "aws-lambda"
7
2
 
8
3
  import Request from "../API/Request"
9
4
  import Response, { ResponseErrorType } from "../API/Response"
@@ -12,9 +7,15 @@ import Logger, { LoggerConfig } from "../Logger/Logger"
12
7
  import Publisher, { PublisherConfig } from "../Publisher/Publisher"
13
8
 
14
9
  // Request
15
- export type TransactionExecution<T, B = null> = (
16
- transaction: T,
17
- ) => Promise<Response<B> | SQSBatchResponse>
10
+ export type TransactionExecution<
11
+ TransactionType,
12
+ ResponseInnerType,
13
+ MiscRespType = null,
14
+ > = (
15
+ transaction: TransactionType,
16
+ ) => Promise<
17
+ Response<ResponseInnerType> | Response<ResponseErrorType> | MiscRespType
18
+ >
18
19
  // Config
19
20
  export type TransactionConfig = {
20
21
  throwOnErrors?: boolean
@@ -24,17 +25,24 @@ export type TransactionConfig = {
24
25
  publisher?: PublisherConfig
25
26
  }
26
27
 
27
- export default class Transaction<T = object, B = null> {
28
+ export default class Transaction<
29
+ InputType = object,
30
+ ResponseInnerType = null,
31
+ MiscRespType = null,
32
+ > {
28
33
  private event: any
29
34
  private context: Context
30
- private response: Response<B | ResponseErrorType> | null | SQSBatchResponse
35
+ private response:
36
+ | Response<ResponseInnerType | ResponseErrorType>
37
+ | MiscRespType
38
+ | null
31
39
  private syncReturn: boolean
32
40
  private retrowErrors: boolean
33
41
  //
34
42
  public readonly logger: Logger
35
- public readonly request: Request<T>
43
+ public readonly request: Request<InputType>
36
44
  public readonly publisher: Publisher
37
- public responseProxy: (response: Response<B>) => Promise<void>
45
+ public responseProxy: (response: Response<ResponseInnerType>) => Promise<void>
38
46
  //
39
47
  constructor(
40
48
  event: APIGatewayEvent | SQSEvent,
@@ -57,14 +65,18 @@ export default class Transaction<T = object, B = null> {
57
65
  this.retrowErrors = !!config?.throwOnErrors /* retrow internal errors */
58
66
  // components
59
67
  this.logger = new Logger(config?.logger, transactionId)
60
- this.request = new Request<T>(this.event, this.context, this.logger)
68
+ this.request = new Request<InputType>(this.event, this.context, this.logger)
61
69
  this.publisher = new Publisher(config?.publisher)
62
70
  }
63
71
 
64
72
  //Main interface
65
73
  public async execute(
66
- executionFunc: TransactionExecution<Transaction<T, B>, B>,
67
- ): Promise<Response<B | ResponseErrorType> | null | SQSBatchResponse> {
74
+ executionFunc: TransactionExecution<
75
+ Transaction<InputType, ResponseInnerType, MiscRespType>,
76
+ ResponseInnerType,
77
+ MiscRespType
78
+ >,
79
+ ): Promise<Response<ResponseInnerType | ResponseErrorType> | MiscRespType> {
68
80
  await this.executeLoggerFlush(async () => {
69
81
  await this.executeDBTransactions(async () => {
70
82
  return await this.iexecute(executionFunc)
@@ -77,7 +89,11 @@ export default class Transaction<T = object, B = null> {
77
89
  }
78
90
  //Executions
79
91
  private async iexecute(
80
- executionFunc: TransactionExecution<Transaction<T, B>, B>,
92
+ executionFunc: TransactionExecution<
93
+ Transaction<InputType, ResponseInnerType, MiscRespType>,
94
+ ResponseInnerType,
95
+ MiscRespType
96
+ >,
81
97
  ): Promise<boolean> {
82
98
  let executionFailed = true //failed til we say no!
83
99
  //safe execution handler
@@ -8,29 +8,42 @@ const cacheStore = new MemCache()
8
8
 
9
9
  export type ConfigurationSchema = {
10
10
  [name: string]: {
11
- type: EnvironmentType
11
+ isLocal?: boolean
12
+ isRemote?: boolean
12
13
  required?: boolean
13
14
  cachingPolicy?: string
14
15
  }
15
16
  }
16
17
 
17
18
  // runtime type infer to ConfigurationSchema keys, which type is remote
18
- type ExtractRemote<Type> = keyof {
19
- [Property in keyof Type]: Type[Property] extends {
20
- type: EnvironmentType.PlainRemote | EnvironmentType.SecureRemote
19
+ type ExtractRemote<Type> = {
20
+ [Property in keyof Type]-?: Type[Property] extends {
21
+ isRemote: true
21
22
  }
22
23
  ? Property
23
- : never
24
+ : null
24
25
  }
25
26
  // runtime type infer to ConfigurationSchema keys, which type is local
26
- type ExtractLocal<Type> = keyof {
27
- [Property in keyof Type]: Type[Property] extends {
28
- type: EnvironmentType.Local
27
+ type ExtractLocal<Type> = {
28
+ [Property in keyof Type]-?: Type[Property] extends {
29
+ isLocal: true
29
30
  }
30
31
  ? Property
31
- : never
32
+ : null
32
33
  }
33
34
 
35
+ // Helpers to filter null keys
36
+ type OmitKeysByValueType<T, U> = {
37
+ [P in keyof T]: T[P] extends U ? never : P
38
+ }[keyof T]
39
+
40
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
41
+ type OmitByValueType<T, V> = T extends infer _
42
+ ? {
43
+ [key in OmitKeysByValueType<T, V>]: T[key]
44
+ }
45
+ : never
46
+
34
47
  export default class Configuration<T extends ConfigurationSchema> {
35
48
  private readonly schema: T
36
49
  private readonly remotePrefix: string
@@ -39,34 +52,36 @@ export default class Configuration<T extends ConfigurationSchema> {
39
52
  this.remotePrefix = remotePrefix
40
53
  }
41
54
 
42
- public get(propName: ExtractLocal<T>): any {
43
- propName = propName as string // TODO: find a better way, this seems to come from keyof
44
- const propSchema = this.schema[propName]
45
- let v = this.getCachedValue(propName)
55
+ public get(propName: keyof OmitByValueType<ExtractLocal<T>, null>): any {
56
+ const propString = propName as string
57
+ const propSchema = this.schema[propString]
58
+ let v = this.getCachedValue(propString)
46
59
  v =
47
60
  v ||
48
61
  new EnvironmentVar<string>(
49
- propName,
50
- propSchema.type,
62
+ propString,
63
+ EnvironmentType.Local,
51
64
  propSchema.required,
52
65
  this.remotePrefix,
53
66
  ).syncResolve()
54
- this.cacheValue(propName, v, propSchema.cachingPolicy)
67
+ this.cacheValue(propString, v, propSchema.cachingPolicy)
55
68
  return v
56
69
  }
57
- public async asyncGet(propName: ExtractRemote<T>): Promise<any> {
58
- propName = propName as string // TODO: find a better way, this seems to come from keyof
59
- const propSchema = this.schema[propName]
60
- let v = this.getCachedValue(propName)
70
+ public async asyncGet(
71
+ propName: keyof OmitByValueType<ExtractRemote<T>, null>,
72
+ ): Promise<any> {
73
+ const propString = propName as string
74
+ const propSchema = this.schema[propString]
75
+ let v = this.getCachedValue(propString)
61
76
  v =
62
77
  v ||
63
78
  (await new EnvironmentVar<string>(
64
- propName,
65
- propSchema.type,
79
+ propString,
80
+ EnvironmentType.PlainRemote,
66
81
  propSchema.required,
67
82
  this.remotePrefix,
68
83
  ).resolve())
69
- this.cacheValue(propName, v, propSchema.cachingPolicy)
84
+ this.cacheValue(propString, v, propSchema.cachingPolicy)
70
85
  return v
71
86
  }
72
87
  // caching layer
@@ -0,0 +1,45 @@
1
+ import * as jwt from "jsonwebtoken"
2
+
3
+ type JWTValidationResponse =
4
+ | { isValid: true; decodedToken: jwt.JwtPayload }
5
+ | {
6
+ isValid: false
7
+ isExpired?: boolean
8
+ }
9
+
10
+ export default class JWT {
11
+ private readonly tokenClient: string
12
+ private readonly tokenSecret: string
13
+ private readonly defaultExpiration: string
14
+ constructor(
15
+ tokenClient: string,
16
+ tokenSecret: string,
17
+ defaultExpiration?: string,
18
+ ) {
19
+ this.tokenClient = tokenClient
20
+ this.tokenSecret = tokenSecret
21
+ this.defaultExpiration = defaultExpiration
22
+ }
23
+ //
24
+ async createToken(data: object, expiration?: string): Promise<string> {
25
+ const exp = expiration || this.defaultExpiration
26
+ return jwt.sign(data, this.tokenSecret, exp ? { expiresIn: exp } : {})
27
+ }
28
+ async validateToken(token: string): Promise<JWTValidationResponse> {
29
+ try {
30
+ // Check if is valid
31
+ const isValid = jwt.verify(token, this.tokenSecret)
32
+ if (!isValid) throw new Error("Issue with token validation!")
33
+ else {
34
+ const payload = jwt.decode(token, { json: true })
35
+ if (payload) return { isValid: true, decodedToken: payload }
36
+ else throw new Error("Issue while decoding token!")
37
+ }
38
+ } catch (err) {
39
+ console.error(err)
40
+ if (err instanceof jwt.TokenExpiredError)
41
+ return { isValid: false, isExpired: true }
42
+ }
43
+ return { isValid: false }
44
+ }
45
+ }
@@ -13,8 +13,14 @@ import Transaction, {
13
13
  export interface Route<InputType = any, OutputType = any> {
14
14
  path: string
15
15
  method: string
16
+ /* If you are here to know why implementing this method
17
+ does not auto infer the param type, check long discussion on TS
18
+ - https://github.com/Microsoft/TypeScript/issues/1373
19
+ - https://github.com/microsoft/TypeScript/issues/23911#issuecomment-1351020050 (proposed solution)
20
+ - https://github.com/microsoft/TypeScript/issues/10570
21
+ */
16
22
  handler: TransactionExecution<
17
- Transaction<InputType>,
23
+ Transaction<InputType, OutputType | ResponseErrorType>,
18
24
  OutputType | ResponseErrorType
19
25
  >
20
26
  inputSchema?: z.ZodObject<any>