@proteinjs/service 1.0.30 → 1.0.32

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/CHANGELOG.md CHANGED
@@ -3,6 +3,17 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.0.32](https://github.com/proteinjs/service/compare/@proteinjs/service@1.0.31...@proteinjs/service@1.0.32) (2024-08-30)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * avoid logging twice for service errors ([5f5e593](https://github.com/proteinjs/service/commit/5f5e59377fbd81d90d4607bd6e56aa2865c7e38d))
12
+
13
+
14
+
15
+
16
+
6
17
  ## [1.0.28](https://github.com/proteinjs/service/compare/@proteinjs/service@1.0.27...@proteinjs/service@1.0.28) (2024-08-16)
7
18
 
8
19
 
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Brent Bahry
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.
@@ -22,7 +22,7 @@ require("@proteinjs/server-api");
22
22
  require("@proteinjs/user-auth");
23
23
  require("@proteinjs/util");
24
24
  /** Generate Source Graph */
25
- var sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"@proteinjs/service/Service\",\"value\":{\"packageName\":\"@proteinjs/service\",\"name\":\"Service\",\"filePath\":\"/Users/veronica/Repositories/n3xa-meta-repo/packages/proteinjs/packages/service/packages/service/src/Service.ts\",\"qualifiedName\":\"@proteinjs/service/Service\",\"properties\":[{\"name\":\"serviceMetadata\",\"type\":{\"packageName\":\"@proteinjs/service\",\"name\":\"{\\n auth?: {\\n /** If true, the user does not need to be logged in or have any roles to call this service. If blank, defaults to false. */\\n public?: boolean;\\n /** If true, the user does not need to have any roles to call this service, but must be logged in. If blank, defaults to false. */\\n allUsers?: boolean;\\n /** The user must be logged in and have these roles to call this service. If blank, defaults to requiring the 'admin' role. */\\n roles?: string[];\\n /**\\n * Custom auth function. If provided, all other auth properties are ignored.\\n * @param methodName the name of the service method to be executed\\n * @param args the args[] that will be passed into the method\\n * @return true if the user can access the service method\\n */\\n canAccess?: (methodName: string, args: any[]) => boolean;\\n };\\n /** Don't await the service's execution, return a response to the client immediately */\\n doNotAwait?: boolean;\\n }\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/service/{\\n auth?: {\\n /** If true, the user does not need to be logged in or have any roles to call this service. If blank, defaults to false. */\\n public?: boolean;\\n /** If true, the user does not need to have any roles to call this service, but must be logged in. If blank, defaults to false. */\\n allUsers?: boolean;\\n /** The user must be logged in and have these roles to call this service. If blank, defaults to requiring the 'admin' role. */\\n roles?: string[];\\n /**\\n * Custom auth function. If provided, all other auth properties are ignored.\\n * @param methodName the name of the service method to be executed\\n * @param args the args[] that will be passed into the method\\n * @return true if the user can access the service method\\n */\\n canAccess?: (methodName: string, args: any[]) => boolean;\\n };\\n /** Don't await the service's execution, return a response to the client immediately */\\n doNotAwait?: boolean;\\n }\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":true,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[],\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/reflection\",\"name\":\"Loadable\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/reflection/Loadable\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"sourceType\":3}},{\"v\":\"@proteinjs/reflection/Loadable\"},{\"v\":\"@proteinjs/service/ServiceRouter\",\"value\":{\"packageName\":\"@proteinjs/service\",\"name\":\"ServiceRouter\",\"filePath\":\"/Users/veronica/Repositories/n3xa-meta-repo/packages/proteinjs/packages/service/packages/service/src/ServiceRouter.ts\",\"qualifiedName\":\"@proteinjs/service/ServiceRouter\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[{\"name\":\"logger\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\"},{\"name\":\"serviceExecutorMap\",\"type\":{\"packageName\":\"@proteinjs/service\",\"name\":\"{ [path: string]: ServiceExecutor } | undefined\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/service/{ [path: string]: ServiceExecutor } | undefined\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\"},{\"name\":\"path\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"method\",\"type\":{\"packageName\":\"\",\"name\":\"'post'\",\"filePath\":null,\"qualifiedName\":\"/'post'\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[{\"name\":\"getServiceExecutorMap\",\"returnType\":null,\"isAsync\":false,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\",\"parameters\":[]},{\"name\":\"onRequest\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<any>\",\"filePath\":null,\"qualifiedName\":\"/Promise<any>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":true,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"request\",\"type\":{\"packageName\":\"\",\"name\":\"any\",\"filePath\":null,\"qualifiedName\":\"/any\",\"typeParameters\":null,\"directParents\":null}},{\"name\":\"response\",\"type\":{\"packageName\":\"\",\"name\":\"any\",\"filePath\":null,\"qualifiedName\":\"/any\",\"typeParameters\":null,\"directParents\":null}}]}],\"typeParameters\":[],\"directParentInterfaces\":[{\"packageName\":\"@proteinjs/server-api\",\"name\":\"Route\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/server-api/Route\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"directParentClasses\":[],\"sourceType\":2}},{\"v\":\"@proteinjs/server-api/Route\"}],\"edges\":[{\"v\":\"@proteinjs/service/Service\",\"w\":\"@proteinjs/reflection/Loadable\",\"value\":\"extends interface\"},{\"v\":\"@proteinjs/service/ServiceRouter\",\"w\":\"@proteinjs/server-api/Route\",\"value\":\"implements interface\"}]}";
25
+ var sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"@proteinjs/service/Service\",\"value\":{\"packageName\":\"@proteinjs/service\",\"name\":\"Service\",\"filePath\":\"/home/runner/work/service/service/packages/service/src/Service.ts\",\"qualifiedName\":\"@proteinjs/service/Service\",\"properties\":[{\"name\":\"serviceMetadata\",\"type\":{\"packageName\":\"@proteinjs/service\",\"name\":\"{\\n auth?: {\\n /** If true, the user does not need to be logged in or have any roles to call this service. If blank, defaults to false. */\\n public?: boolean;\\n /** If true, the user does not need to have any roles to call this service, but must be logged in. If blank, defaults to false. */\\n allUsers?: boolean;\\n /** The user must be logged in and have these roles to call this service. If blank, defaults to requiring the 'admin' role. */\\n roles?: string[];\\n /**\\n * Custom auth function. If provided, all other auth properties are ignored.\\n * @param methodName the name of the service method to be executed\\n * @param args the args[] that will be passed into the method\\n * @return true if the user can access the service method\\n */\\n canAccess?: (methodName: string, args: any[]) => boolean;\\n };\\n /** Don't await the service's execution, return a response to the client immediately */\\n doNotAwait?: boolean;\\n }\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/service/{\\n auth?: {\\n /** If true, the user does not need to be logged in or have any roles to call this service. If blank, defaults to false. */\\n public?: boolean;\\n /** If true, the user does not need to have any roles to call this service, but must be logged in. If blank, defaults to false. */\\n allUsers?: boolean;\\n /** The user must be logged in and have these roles to call this service. If blank, defaults to requiring the 'admin' role. */\\n roles?: string[];\\n /**\\n * Custom auth function. If provided, all other auth properties are ignored.\\n * @param methodName the name of the service method to be executed\\n * @param args the args[] that will be passed into the method\\n * @return true if the user can access the service method\\n */\\n canAccess?: (methodName: string, args: any[]) => boolean;\\n };\\n /** Don't await the service's execution, return a response to the client immediately */\\n doNotAwait?: boolean;\\n }\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":true,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[],\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/reflection\",\"name\":\"Loadable\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/reflection/Loadable\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"sourceType\":3}},{\"v\":\"@proteinjs/reflection/Loadable\"},{\"v\":\"/Error\"},{\"v\":\"@proteinjs/service/ServiceRouter\",\"value\":{\"packageName\":\"@proteinjs/service\",\"name\":\"ServiceRouter\",\"filePath\":\"/home/runner/work/service/service/packages/service/src/ServiceRouter.ts\",\"qualifiedName\":\"@proteinjs/service/ServiceRouter\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[{\"name\":\"logger\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\"},{\"name\":\"serviceExecutorMap\",\"type\":{\"packageName\":\"@proteinjs/service\",\"name\":\"{ [path: string]: ServiceExecutor } | undefined\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/service/{ [path: string]: ServiceExecutor } | undefined\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\"},{\"name\":\"path\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"method\",\"type\":{\"packageName\":\"\",\"name\":\"'post'\",\"filePath\":null,\"qualifiedName\":\"/'post'\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[{\"name\":\"getServiceExecutorMap\",\"returnType\":null,\"isAsync\":false,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\",\"parameters\":[]},{\"name\":\"onRequest\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<any>\",\"filePath\":null,\"qualifiedName\":\"/Promise<any>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":true,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"request\",\"type\":{\"packageName\":\"\",\"name\":\"any\",\"filePath\":null,\"qualifiedName\":\"/any\",\"typeParameters\":null,\"directParents\":null}},{\"name\":\"response\",\"type\":{\"packageName\":\"\",\"name\":\"any\",\"filePath\":null,\"qualifiedName\":\"/any\",\"typeParameters\":null,\"directParents\":null}}]}],\"typeParameters\":[],\"directParentInterfaces\":[{\"packageName\":\"@proteinjs/server-api\",\"name\":\"Route\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/server-api/Route\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"directParentClasses\":[],\"sourceType\":2}},{\"v\":\"@proteinjs/server-api/Route\"}],\"edges\":[{\"v\":\"@proteinjs/service/Service\",\"w\":\"@proteinjs/reflection/Loadable\",\"value\":\"extends interface\"},{\"v\":\"@proteinjs/service/ServiceRouter\",\"w\":\"@proteinjs/server-api/Route\",\"value\":\"implements interface\"}]}";
26
26
  /** Generate Source Links */
27
27
  var ServiceRouter_1 = require("../src/ServiceRouter");
28
28
  var sourceLinks = {
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;;;;;AAEpC,6BAA2B;AAC3B,iCAA+B;AAC/B,iCAA+B;AAC/B,iCAA+B;AAC/B,gCAA8B;AAC9B,2BAAyB;AAGzB,4BAA4B;AAE5B,IAAM,WAAW,GAAG,ooLAAooL,CAAC;AAGzpL,4BAA4B;AAE5B,sDAAqD;AAErD,IAAM,WAAW,GAAG;IACnB,kCAAkC,EAAE,6BAAa;CACjD,CAAC;AAGF,kCAAkC;AAElC,oDAAyD;AACzD,6BAAgB,CAAC,KAAK,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AAGjD,2CAAyB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../generated/index.ts"],"names":[],"mappings":";AAAA,oCAAoC;;;;;;;;;;;;;;;;AAEpC,6BAA2B;AAC3B,iCAA+B;AAC/B,iCAA+B;AAC/B,iCAA+B;AAC/B,gCAA8B;AAC9B,2BAAyB;AAGzB,4BAA4B;AAE5B,IAAM,WAAW,GAAG,2jLAA2jL,CAAC;AAGhlL,4BAA4B;AAE5B,sDAAqD;AAErD,IAAM,WAAW,GAAG;IACnB,kCAAkC,EAAE,6BAAa;CACjD,CAAC;AAGF,kCAAkC;AAElC,oDAAyD;AACzD,6BAAgB,CAAC,KAAK,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC;AAGjD,2CAAyB"}
@@ -1,5 +1,8 @@
1
1
  import { Interface, Method } from '@proteinjs/reflection';
2
2
  import { Service } from './Service';
3
+ export declare class ServiceError extends Error {
4
+ constructor(message: string);
5
+ }
3
6
  export declare class ServiceExecutor {
4
7
  service: Service;
5
8
  private _interface;
@@ -1 +1 @@
1
- {"version":3,"file":"ServiceExecutor.d.ts","sourceRoot":"","sources":["../../src/ServiceExecutor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAOpC,qBAAa,eAAe;IAKjB,OAAO,EAAE,OAAO;IACvB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,MAAM;IANhB,OAAO,CAAC,MAAM,CAAS;IAChB,gBAAgB,EAAE,GAAG,CAAC;IAC7B,OAAO,CAAC,iBAAiB,CAAS;gBAEzB,OAAO,EAAE,OAAO,EACf,UAAU,EAAE,SAAS,EACrB,MAAM,EAAE,MAAM;IAMlB,OAAO,CAAC,WAAW,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IA4C7C,OAAO,CAAC,sBAAsB;CAG/B"}
1
+ {"version":3,"file":"ServiceExecutor.d.ts","sourceRoot":"","sources":["../../src/ServiceExecutor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAOpC,qBAAa,YAAa,SAAQ,KAAK;gBACzB,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,eAAe;IAKjB,OAAO,EAAE,OAAO;IACvB,OAAO,CAAC,UAAU;IAClB,OAAO,CAAC,MAAM;IANhB,OAAO,CAAC,MAAM,CAAS;IAChB,gBAAgB,EAAE,GAAG,CAAC;IAC7B,OAAO,CAAC,iBAAiB,CAAS;gBAEzB,OAAO,EAAE,OAAO,EACf,UAAU,EAAE,SAAS,EACrB,MAAM,EAAE,MAAM;IAMlB,OAAO,CAAC,WAAW,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IA4C7C,OAAO,CAAC,sBAAsB;CAG/B"}
@@ -1,4 +1,19 @@
1
1
  "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
2
17
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
18
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
19
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -36,12 +51,22 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
36
51
  }
37
52
  };
38
53
  Object.defineProperty(exports, "__esModule", { value: true });
39
- exports.ServiceExecutor = void 0;
54
+ exports.ServiceExecutor = exports.ServiceError = void 0;
40
55
  var logger_1 = require("@proteinjs/logger");
41
56
  var serializer_1 = require("@proteinjs/serializer");
42
57
  var ServiceAuth_1 = require("./ServiceAuth");
43
58
  var isVoidReturnType_1 = require("./isVoidReturnType");
44
59
  var server_api_1 = require("@proteinjs/server-api");
60
+ var ServiceError = /** @class */ (function (_super) {
61
+ __extends(ServiceError, _super);
62
+ function ServiceError(message) {
63
+ var _this = _super.call(this, message) || this;
64
+ _this.name = 'ServiceError';
65
+ return _this;
66
+ }
67
+ return ServiceError;
68
+ }(Error));
69
+ exports.ServiceError = ServiceError;
45
70
  var ServiceExecutor = /** @class */ (function () {
46
71
  function ServiceExecutor(service, _interface, method) {
47
72
  this.service = service;
@@ -84,7 +109,7 @@ var ServiceExecutor = /** @class */ (function () {
84
109
  error: error_1,
85
110
  obj: { functionName: this.serviceMethodName, args: deserializedArgs },
86
111
  });
87
- throw error_1;
112
+ throw new ServiceError('Service failed');
88
113
  case 6:
89
114
  if ((0, isVoidReturnType_1.isVoidReturnType)(this.method)) {
90
115
  if (this.shouldLogArgsAndReturn()) {
@@ -1 +1 @@
1
- {"version":3,"file":"ServiceExecutor.js","sourceRoot":"","sources":["../../src/ServiceExecutor.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,4CAA2C;AAC3C,oDAAmD;AACnD,6CAA4C;AAC5C,uDAAsD;AACtD,oDAAgD;AAEhD;IAIE,yBACS,OAAgB,EACf,UAAqB,EACrB,MAAc;QAFf,YAAO,GAAP,OAAO,CAAS;QACf,eAAU,GAAV,UAAU,CAAW;QACrB,WAAM,GAAN,MAAM,CAAQ;QAEtB,IAAI,CAAC,iBAAiB,GAAG,UAAG,UAAU,CAAC,IAAI,cAAI,MAAM,CAAC,IAAI,CAAE,CAAC;QAC7D,IAAI,CAAC,MAAM,GAAG,IAAI,eAAM,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,iBAAiB,EAAE,CAAC,CAAC;IAC7D,CAAC;IAEK,iCAAO,GAAb,UAAc,WAAgB;;;;;;;wBACtB,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;wBAC3D,gBAAgB,GAAG,uBAAU,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;wBAC7D,IAAI,IAAI,CAAC,sBAAsB,EAAE,EAAE;4BACjC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,EAAE,EAAE,YAAY,EAAE,IAAI,CAAC,iBAAiB,EAAE,IAAI,EAAE,gBAAgB,EAAE,E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B;oCAC3B,GAAG,EAAE,EAAE,YAAY,EAAE,IAAI,CAAC,iBAAiB,EAAE,MAAM,EAAE,MAAM,EAAE;iCAC9D,CAAC,CAAC;6BACJ;4BACD,sBAAO,SAAS,EAAC;yBAClB;wBAEK,gBAAgB,GAAG,uBAAU,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;wBACvD,IAAI,IAAI,CAAC,sBAAsB,EAAE,EAAE;4BACjC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,GAAG,EAAE,EAAE,YAAY,EAAE,IAAI,CAAC,iBAAiB,EAAE,MAAM,EAAE,OAAO,EAAE,EAAE,CAAC,CAAC;yBAC5G;wBACD,sBAAO,gBAAgB,EAAC;;;;KACzB;IAEO,gDAAsB,GAA9B;QACE,OAAO,CAAC,oBAAO,CAAC,KAAK,EAAE,IAAI,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC;IAC/D,CAAC;IACH,sBAAC;AAAD,CAAC,AA5DD,IA4DC;AA5DY,0CAAe"}
@@ -1 +1 @@
1
- {"version":3,"file":"ServiceRouter.d.ts","sourceRoot":"","sources":["../../src/ServiceRouter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAO9C,qBAAa,aAAc,YAAW,KAAK;IACzC,OAAO,CAAC,MAAM,CAA+C;IAC7D,OAAO,CAAC,kBAAkB,CAAkD;IAC5E,IAAI,SAAe;IACnB,MAAM,EAAE,MAAM,CAAU;IAExB,OAAO,CAAC,qBAAqB;IAqBvB,SAAS,CAAC,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;CAiB3D"}
1
+ {"version":3,"file":"ServiceRouter.d.ts","sourceRoot":"","sources":["../../src/ServiceRouter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAa9C,qBAAa,aAAc,YAAW,KAAK;IACzC,OAAO,CAAC,MAAM,CAA+C;IAC7D,OAAO,CAAC,kBAAkB,CAAkD;IAC5E,IAAI,SAAe;IACnB,MAAM,EAAE,MAAM,CAAU;IAExB,OAAO,CAAC,qBAAqB;IAqBvB,SAAS,CAAC,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;CAqB3D"}
@@ -41,6 +41,9 @@ var reflection_1 = require("@proteinjs/reflection");
41
41
  var ServiceExecutor_1 = require("./ServiceExecutor");
42
42
  var util_1 = require("@proteinjs/util");
43
43
  var logger_1 = require("@proteinjs/logger");
44
+ function isServiceError(error) {
45
+ return (typeof error === 'object' && error !== null && 'name' in error && error.name === 'ServiceError');
46
+ }
44
47
  var ServiceRouter = /** @class */ (function () {
45
48
  function ServiceRouter() {
46
49
  this.logger = new logger_1.Logger({ name: this.constructor.name });
@@ -69,7 +72,7 @@ var ServiceRouter = /** @class */ (function () {
69
72
  };
70
73
  ServiceRouter.prototype.onRequest = function (request, response) {
71
74
  return __awaiter(this, void 0, void 0, function () {
72
- var serviceExecutor, error, serializedReturn, error_1;
75
+ var serviceExecutor, error, serializedReturn, error_1, errorMessage;
73
76
  return __generator(this, function (_a) {
74
77
  switch (_a.label) {
75
78
  case 0:
@@ -90,8 +93,12 @@ var ServiceRouter = /** @class */ (function () {
90
93
  return [3 /*break*/, 4];
91
94
  case 3:
92
95
  error_1 = _a.sent();
93
- this.logger.error({ error: error_1 });
94
- response.send({ error: error_1.message });
96
+ errorMessage = error_1.message;
97
+ if (!isServiceError(error_1)) {
98
+ this.logger.error({ error: error_1 });
99
+ errorMessage = 'Internal server error';
100
+ }
101
+ response.send({ error: errorMessage });
95
102
  return [3 /*break*/, 4];
96
103
  case 4: return [2 /*return*/];
97
104
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ServiceRouter.js","sourceRoot":"","sources":["../../src/ServiceRouter.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;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,QAAa;;;;;;wBACnC,eAAe,GAAG,IAAI,CAAC,qBAAqB,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;wBACnE,IAAI,CAAC,eAAe,EAAE;4BACd,KAAK,GAAG,gDAAyC,OAAO,CAAC,IAAI,CAAE,CAAC;4BACtE,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,CAAC;4BACtC,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,OAAA,EAAE,CAAC,CAAC;4BACzB,sBAAO;yBACR;;;;wBAG0B,qBAAM,eAAe,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,EAAA;;wBAA9D,gBAAgB,GAAG,SAA2C;wBACpE,QAAQ,CAAC,IAAI,CAAC,EAAE,gBAAgB,kBAAA,EAAE,CAAC,CAAC;;;;wBAEhC,YAAY,GAAG,OAAK,CAAC,OAAO,CAAC;wBACjC,IAAI,CAAC,cAAc,CAAC,OAAK,CAAC,EAAE;4BAC1B,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,SAAA,EAAE,CAAC,CAAC;4BAC7B,YAAY,GAAG,uBAAuB,CAAC;yBACxC;wBACD,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC,CAAC;;;;;;KAE1C;IACH,oBAAC;AAAD,CAAC,AAhDD,IAgDC;AAhDY,sCAAa"}
@@ -7,25 +7,22 @@ import '@proteinjs/server-api';
7
7
  import '@proteinjs/user-auth';
8
8
  import '@proteinjs/util';
9
9
 
10
-
11
10
  /** Generate Source Graph */
12
11
 
13
- const sourceGraph = "{\"options\":{\"directed\":true,\"multigraph\":false,\"compound\":false},\"nodes\":[{\"v\":\"@proteinjs/service/Service\",\"value\":{\"packageName\":\"@proteinjs/service\",\"name\":\"Service\",\"filePath\":\"/Users/veronica/Repositories/n3xa-meta-repo/packages/proteinjs/packages/service/packages/service/src/Service.ts\",\"qualifiedName\":\"@proteinjs/service/Service\",\"properties\":[{\"name\":\"serviceMetadata\",\"type\":{\"packageName\":\"@proteinjs/service\",\"name\":\"{\\n auth?: {\\n /** If true, the user does not need to be logged in or have any roles to call this service. If blank, defaults to false. */\\n public?: boolean;\\n /** If true, the user does not need to have any roles to call this service, but must be logged in. If blank, defaults to false. */\\n allUsers?: boolean;\\n /** The user must be logged in and have these roles to call this service. If blank, defaults to requiring the 'admin' role. */\\n roles?: string[];\\n /**\\n * Custom auth function. If provided, all other auth properties are ignored.\\n * @param methodName the name of the service method to be executed\\n * @param args the args[] that will be passed into the method\\n * @return true if the user can access the service method\\n */\\n canAccess?: (methodName: string, args: any[]) => boolean;\\n };\\n /** Don't await the service's execution, return a response to the client immediately */\\n doNotAwait?: boolean;\\n }\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/service/{\\n auth?: {\\n /** If true, the user does not need to be logged in or have any roles to call this service. If blank, defaults to false. */\\n public?: boolean;\\n /** If true, the user does not need to have any roles to call this service, but must be logged in. If blank, defaults to false. */\\n allUsers?: boolean;\\n /** The user must be logged in and have these roles to call this service. If blank, defaults to requiring the 'admin' role. */\\n roles?: string[];\\n /**\\n * Custom auth function. If provided, all other auth properties are ignored.\\n * @param methodName the name of the service method to be executed\\n * @param args the args[] that will be passed into the method\\n * @return true if the user can access the service method\\n */\\n canAccess?: (methodName: string, args: any[]) => boolean;\\n };\\n /** Don't await the service's execution, return a response to the client immediately */\\n doNotAwait?: boolean;\\n }\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":true,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[],\"typeParameters\":[],\"directParents\":[{\"packageName\":\"@proteinjs/reflection\",\"name\":\"Loadable\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/reflection/Loadable\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"sourceType\":3}},{\"v\":\"@proteinjs/reflection/Loadable\"},{\"v\":\"@proteinjs/service/ServiceRouter\",\"value\":{\"packageName\":\"@proteinjs/service\",\"name\":\"ServiceRouter\",\"filePath\":\"/Users/veronica/Repositories/n3xa-meta-repo/packages/proteinjs/packages/service/packages/service/src/ServiceRouter.ts\",\"qualifiedName\":\"@proteinjs/service/ServiceRouter\",\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"properties\":[{\"name\":\"logger\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\"},{\"name\":\"serviceExecutorMap\",\"type\":{\"packageName\":\"@proteinjs/service\",\"name\":\"{ [path: string]: ServiceExecutor } | undefined\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/service/{ [path: string]: ServiceExecutor } | undefined\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\"},{\"name\":\"path\",\"type\":null,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"},{\"name\":\"method\",\"type\":{\"packageName\":\"\",\"name\":\"'post'\",\"filePath\":null,\"qualifiedName\":\"/'post'\",\"typeParameters\":null,\"directParents\":null},\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\"}],\"methods\":[{\"name\":\"getServiceExecutorMap\",\"returnType\":null,\"isAsync\":false,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"private\",\"parameters\":[]},{\"name\":\"onRequest\",\"returnType\":{\"packageName\":\"\",\"name\":\"Promise<any>\",\"filePath\":null,\"qualifiedName\":\"/Promise<any>\",\"typeParameters\":null,\"directParents\":null},\"isAsync\":true,\"isOptional\":false,\"isAbstract\":false,\"isStatic\":false,\"visibility\":\"public\",\"parameters\":[{\"name\":\"request\",\"type\":{\"packageName\":\"\",\"name\":\"any\",\"filePath\":null,\"qualifiedName\":\"/any\",\"typeParameters\":null,\"directParents\":null}},{\"name\":\"response\",\"type\":{\"packageName\":\"\",\"name\":\"any\",\"filePath\":null,\"qualifiedName\":\"/any\",\"typeParameters\":null,\"directParents\":null}}]}],\"typeParameters\":[],\"directParentInterfaces\":[{\"packageName\":\"@proteinjs/server-api\",\"name\":\"Route\",\"filePath\":null,\"qualifiedName\":\"@proteinjs/server-api/Route\",\"properties\":[],\"methods\":[],\"typeParameters\":[],\"directParents\":[]}],\"directParentClasses\":[],\"sourceType\":2}},{\"v\":\"@proteinjs/server-api/Route\"}],\"edges\":[{\"v\":\"@proteinjs/service/Service\",\"w\":\"@proteinjs/reflection/Loadable\",\"value\":\"extends interface\"},{\"v\":\"@proteinjs/service/ServiceRouter\",\"w\":\"@proteinjs/server-api/Route\",\"value\":\"implements interface\"}]}";
14
-
12
+ const sourceGraph =
13
+ '{"options":{"directed":true,"multigraph":false,"compound":false},"nodes":[{"v":"@proteinjs/service/Service","value":{"packageName":"@proteinjs/service","name":"Service","filePath":"/home/runner/work/service/service/packages/service/src/Service.ts","qualifiedName":"@proteinjs/service/Service","properties":[{"name":"serviceMetadata","type":{"packageName":"@proteinjs/service","name":"{\\n auth?: {\\n /** If true, the user does not need to be logged in or have any roles to call this service. If blank, defaults to false. */\\n public?: boolean;\\n /** If true, the user does not need to have any roles to call this service, but must be logged in. If blank, defaults to false. */\\n allUsers?: boolean;\\n /** The user must be logged in and have these roles to call this service. If blank, defaults to requiring the \'admin\' role. */\\n roles?: string[];\\n /**\\n * Custom auth function. If provided, all other auth properties are ignored.\\n * @param methodName the name of the service method to be executed\\n * @param args the args[] that will be passed into the method\\n * @return true if the user can access the service method\\n */\\n canAccess?: (methodName: string, args: any[]) => boolean;\\n };\\n /** Don\'t await the service\'s execution, return a response to the client immediately */\\n doNotAwait?: boolean;\\n }","filePath":null,"qualifiedName":"@proteinjs/service/{\\n auth?: {\\n /** If true, the user does not need to be logged in or have any roles to call this service. If blank, defaults to false. */\\n public?: boolean;\\n /** If true, the user does not need to have any roles to call this service, but must be logged in. If blank, defaults to false. */\\n allUsers?: boolean;\\n /** The user must be logged in and have these roles to call this service. If blank, defaults to requiring the \'admin\' role. */\\n roles?: string[];\\n /**\\n * Custom auth function. If provided, all other auth properties are ignored.\\n * @param methodName the name of the service method to be executed\\n * @param args the args[] that will be passed into the method\\n * @return true if the user can access the service method\\n */\\n canAccess?: (methodName: string, args: any[]) => boolean;\\n };\\n /** Don\'t await the service\'s execution, return a response to the client immediately */\\n doNotAwait?: boolean;\\n }","typeParameters":null,"directParents":null},"isOptional":true,"isAbstract":false,"isStatic":false,"visibility":"public"}],"methods":[],"typeParameters":[],"directParents":[{"packageName":"@proteinjs/reflection","name":"Loadable","filePath":null,"qualifiedName":"@proteinjs/reflection/Loadable","properties":[],"methods":[],"typeParameters":[],"directParents":[]}],"sourceType":3}},{"v":"@proteinjs/reflection/Loadable"},{"v":"/Error"},{"v":"@proteinjs/service/ServiceRouter","value":{"packageName":"@proteinjs/service","name":"ServiceRouter","filePath":"/home/runner/work/service/service/packages/service/src/ServiceRouter.ts","qualifiedName":"@proteinjs/service/ServiceRouter","isAbstract":false,"isStatic":false,"visibility":"public","properties":[{"name":"logger","type":null,"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"private"},{"name":"serviceExecutorMap","type":{"packageName":"@proteinjs/service","name":"{ [path: string]: ServiceExecutor } | undefined","filePath":null,"qualifiedName":"@proteinjs/service/{ [path: string]: ServiceExecutor } | undefined","typeParameters":null,"directParents":null},"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"private"},{"name":"path","type":null,"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"public"},{"name":"method","type":{"packageName":"","name":"\'post\'","filePath":null,"qualifiedName":"/\'post\'","typeParameters":null,"directParents":null},"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"public"}],"methods":[{"name":"getServiceExecutorMap","returnType":null,"isAsync":false,"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"private","parameters":[]},{"name":"onRequest","returnType":{"packageName":"","name":"Promise<any>","filePath":null,"qualifiedName":"/Promise<any>","typeParameters":null,"directParents":null},"isAsync":true,"isOptional":false,"isAbstract":false,"isStatic":false,"visibility":"public","parameters":[{"name":"request","type":{"packageName":"","name":"any","filePath":null,"qualifiedName":"/any","typeParameters":null,"directParents":null}},{"name":"response","type":{"packageName":"","name":"any","filePath":null,"qualifiedName":"/any","typeParameters":null,"directParents":null}}]}],"typeParameters":[],"directParentInterfaces":[{"packageName":"@proteinjs/server-api","name":"Route","filePath":null,"qualifiedName":"@proteinjs/server-api/Route","properties":[],"methods":[],"typeParameters":[],"directParents":[]}],"directParentClasses":[],"sourceType":2}},{"v":"@proteinjs/server-api/Route"}],"edges":[{"v":"@proteinjs/service/Service","w":"@proteinjs/reflection/Loadable","value":"extends interface"},{"v":"@proteinjs/service/ServiceRouter","w":"@proteinjs/server-api/Route","value":"implements interface"}]}';
15
14
 
16
15
  /** Generate Source Links */
17
16
 
18
17
  import { ServiceRouter } from '../src/ServiceRouter';
19
18
 
20
19
  const sourceLinks = {
21
- '@proteinjs/service/ServiceRouter': ServiceRouter,
20
+ '@proteinjs/service/ServiceRouter': ServiceRouter,
22
21
  };
23
22
 
24
-
25
23
  /** Load Source Graph and Links */
26
24
 
27
25
  import { SourceRepository } from '@proteinjs/reflection';
28
26
  SourceRepository.merge(sourceGraph, sourceLinks);
29
27
 
30
-
31
- export * from '../index';
28
+ export * from '../index';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@proteinjs/service",
3
- "version": "1.0.30",
3
+ "version": "1.0.32",
4
4
  "description": "Service api",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -21,7 +21,7 @@
21
21
  "watch": "reflection-watch"
22
22
  },
23
23
  "dependencies": {
24
- "@proteinjs/logger": "1.0.5",
24
+ "@proteinjs/logger": "1.0.6",
25
25
  "@proteinjs/reflection": "1.1.9",
26
26
  "@proteinjs/serializer": "1.0.15",
27
27
  "@proteinjs/server-api": "1.5.0",
@@ -42,5 +42,6 @@
42
42
  "typescript": "5.2.2"
43
43
  },
44
44
  "main": "./dist/generated/index.js",
45
- "types": "./dist/generated/index.d.ts"
46
- }
45
+ "types": "./dist/generated/index.d.ts",
46
+ "gitHead": "634f90f0f01748585e2f6c8be36c4d832d1fe604"
47
+ }
@@ -6,6 +6,13 @@ import { ServiceAuth } from './ServiceAuth';
6
6
  import { isVoidReturnType } from './isVoidReturnType';
7
7
  import { EnvInfo } from '@proteinjs/server-api';
8
8
 
9
+ export class ServiceError extends Error {
10
+ constructor(message: string) {
11
+ super(message);
12
+ this.name = 'ServiceError';
13
+ }
14
+ }
15
+
9
16
  export class ServiceExecutor {
10
17
  private logger: Logger;
11
18
  public deserializedArgs: any;
@@ -43,7 +50,7 @@ export class ServiceExecutor {
43
50
  error,
44
51
  obj: { functionName: this.serviceMethodName, args: deserializedArgs },
45
52
  });
46
- throw error;
53
+ throw new ServiceError('Service failed');
47
54
  }
48
55
 
49
56
  if (isVoidReturnType(this.method)) {
@@ -1,10 +1,16 @@
1
1
  import { Route } from '@proteinjs/server-api';
2
2
  import { Service } from './Service';
3
3
  import { Interface, SourceRepository } from '@proteinjs/reflection';
4
- import { ServiceExecutor } from './ServiceExecutor';
4
+ import { ServiceError, ServiceExecutor } from './ServiceExecutor';
5
5
  import { isInstanceOf } from '@proteinjs/util';
6
6
  import { Logger } from '@proteinjs/logger';
7
7
 
8
+ function isServiceError(error: unknown): error is ServiceError {
9
+ return (
10
+ typeof error === 'object' && error !== null && 'name' in error && (error as ServiceError).name === 'ServiceError'
11
+ );
12
+ }
13
+
8
14
  export class ServiceRouter implements Route {
9
15
  private logger = new Logger({ name: this.constructor.name });
10
16
  private serviceExecutorMap: { [path: string]: ServiceExecutor } | undefined;
@@ -45,8 +51,12 @@ export class ServiceRouter implements Route {
45
51
  const serializedReturn = await serviceExecutor.execute(request.body);
46
52
  response.send({ serializedReturn });
47
53
  } catch (error: any) {
48
- this.logger.error({ error });
49
- response.send({ error: error.message });
54
+ let errorMessage = error.message;
55
+ if (!isServiceError(error)) {
56
+ this.logger.error({ error });
57
+ errorMessage = 'Internal server error';
58
+ }
59
+ response.send({ error: errorMessage });
50
60
  }
51
61
  }
52
62
  }