skir-client 1.0.0 → 1.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.
@@ -3106,6 +3106,59 @@ export interface RequestHandler<RequestMeta = ExpressRequest> {
3106
3106
  */
3107
3107
  handleRequest(reqBody: string, reqMeta: RequestMeta): Promise<RawResponse>;
3108
3108
  }
3109
+ /** Configuration options for a Skir service. */
3110
+ export interface ServiceOptions<RequestMeta = ExpressRequest> {
3111
+ /**
3112
+ * Whether to keep unrecognized values when deserializing requests.
3113
+ *
3114
+ * **WARNING:** Only enable this for data from trusted sources. Malicious
3115
+ * actors could inject fields with IDs not yet defined in your schema. If you
3116
+ * preserve this data and later define those IDs in a future schema version,
3117
+ * the injected data could be deserialized as valid fields, leading to
3118
+ * security vulnerabilities or data corruption.
3119
+ *
3120
+ * Defaults to `false`.
3121
+ */
3122
+ keepUnrecognizedValues: boolean;
3123
+
3124
+ /**
3125
+ * Predicate that determines whether the message of an unknown error (i.e. not
3126
+ * a `ServiceError`) should be sent to the client.
3127
+ *
3128
+ * By default, unknown errors are masked and the client receives a generic
3129
+ * 'server error' message with status 500. This is to prevent leaking
3130
+ * sensitive information to the client.
3131
+ *
3132
+ * You can enable this for debugging purposes or if you are sure that your
3133
+ * error messages are safe to expose.
3134
+ */
3135
+ canCopyUnknownErrorMessageToResponse: (reqMeta: RequestMeta) => boolean;
3136
+
3137
+ /**
3138
+ * Callback invoked whenever an error is thrown during method execution.
3139
+ *
3140
+ * Use this to log errors for monitoring, debugging, or alerting purposes.
3141
+ * The callback receives the error object, the method being executed, the
3142
+ * request that triggered the error, and the request metadata.
3143
+ *
3144
+ * Defaults to function which logs the method name and error message via
3145
+ * `console.error()`.
3146
+ */
3147
+ errorLogger: <Request>(
3148
+ throwable: any,
3149
+ method: Method<Request, unknown>,
3150
+ req: Request,
3151
+ reqMeta: RequestMeta,
3152
+ ) => void;
3153
+
3154
+ /**
3155
+ * URL to the JavaScript file for the Skir Studio app.
3156
+ *
3157
+ * Skir Studio is a web interface for exploring and testing your Skir service.
3158
+ * It is served when the service receives a request at '${serviceUrl}?studio'.
3159
+ */
3160
+ studioAppJsUrl: string;
3161
+ }
3109
3162
 
3110
3163
  /**
3111
3164
  * Implementation of a skir service.
@@ -3171,6 +3224,7 @@ export class Service<RequestMeta = ExpressRequest>
3171
3224
  canCopyUnknownErrorMessageToResponse:
3172
3225
  options?.canCopyUnknownErrorMessageToResponse ??
3173
3226
  DEFAULT_SERVICE_OPTIONS.canCopyUnknownErrorMessageToResponse,
3227
+ errorLogger: options?.errorLogger ?? DEFAULT_SERVICE_OPTIONS.errorLogger,
3174
3228
  studioAppJsUrl: new URL(
3175
3229
  options?.studioAppJsUrl ?? DEFAULT_SERVICE_OPTIONS.studioAppJsUrl,
3176
3230
  ).toString(),
@@ -3330,6 +3384,7 @@ export class Service<RequestMeta = ExpressRequest>
3330
3384
  try {
3331
3385
  res = await methodImpl.impl(req, reqMeta);
3332
3386
  } catch (e) {
3387
+ this.options.errorLogger(e, methodImpl.method, req, reqMeta);
3333
3388
  if (e instanceof ServiceError) {
3334
3389
  return e.toRawResponse();
3335
3390
  } else {
@@ -3409,44 +3464,12 @@ export class Service<RequestMeta = ExpressRequest>
3409
3464
  } = {};
3410
3465
  }
3411
3466
 
3412
- /** Configuration options for a Skir service. */
3413
- export interface ServiceOptions<RequestMeta = ExpressRequest> {
3414
- /**
3415
- * Whether to keep unrecognized values when deserializing requests.
3416
- *
3417
- * **WARNING:** Only enable this for data from trusted sources. Malicious
3418
- * actors could inject fields with IDs not yet defined in your schema. If you
3419
- * preserve this data and later define those IDs in a future schema version,
3420
- * the injected data could be deserialized as valid fields, leading to
3421
- * security vulnerabilities or data corruption.
3422
- *
3423
- * Defaults to `false`.
3424
- */
3425
- keepUnrecognizedValues: boolean;
3426
- /**
3427
- * Predicate that determines whether the message of an unknown error (i.e. not
3428
- * a `ServiceError`) should be sent to the client.
3429
- *
3430
- * By default, unknown errors are masked and the client receives a generic
3431
- * 'server error' message with status 500. This is to prevent leaking
3432
- * sensitive information to the client.
3433
- *
3434
- * You can enable this for debugging purposes or if you are sure that your
3435
- * error messages are safe to expose.
3436
- */
3437
- canCopyUnknownErrorMessageToResponse: (reqMeta: RequestMeta) => boolean;
3438
- /**
3439
- * URL to the JavaScript file for the Skir Studio app.
3440
- *
3441
- * Skir Studio is a web interface for exploring and testing your Skir service.
3442
- * It is served when the service receives a request at '${serviceUrl}?studio'.
3443
- */
3444
- studioAppJsUrl: string;
3445
- }
3446
-
3447
3467
  const DEFAULT_SERVICE_OPTIONS: ServiceOptions<unknown> = {
3448
3468
  keepUnrecognizedValues: false,
3449
3469
  canCopyUnknownErrorMessageToResponse: () => false,
3470
+ errorLogger: (error: unknown, method: Method<unknown, unknown>) => {
3471
+ console.error(`Error in method ${method.name}:`, error);
3472
+ },
3450
3473
  studioAppJsUrl:
3451
3474
  "https://cdn.jsdelivr.net/npm/skir-studio/dist/skir-studio-standalone.js",
3452
3475
  };