monorise 2.0.0-dev.6 → 2.0.0-dev.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.
@@ -625,12 +625,7 @@ var Entity = class _Entity extends Item {
625
625
  };
626
626
  new AsyncLocalStorage();
627
627
  createFactory();
628
-
629
- // helpers/event.ts
630
628
  new EventBridgeClient();
631
-
632
- // middlewares/general-error-handler.ts
633
- createFactory();
634
629
  new AthenaClient();
635
630
  new DynamoDBClient();
636
631
  new FirehoseClient();
@@ -5120,7 +5115,7 @@ type StandardErrorCode = typeof StandardErrorCode[keyof typeof StandardErrorCode
5120
5115
  type AppHandleArgs = {
5121
5116
  routes?: (container: DependencyContainer) => Hono | Hono;
5122
5117
  };
5123
- declare const appHandler: (container: DependencyContainer) => ({ routes }: AppHandleArgs) => <L extends hono_aws_lambda.LambdaEvent>(event: L, lambdaContext?: hono_aws_lambda.LambdaContext) => Promise<hono_aws_lambda.APIGatewayProxyResult & (L extends {
5118
+ declare const appHandler: (container: DependencyContainer) => (args: AppHandleArgs) => <L extends hono_aws_lambda.LambdaEvent>(event: L, lambdaContext?: hono_aws_lambda.LambdaContext) => Promise<hono_aws_lambda.APIGatewayProxyResult & (L extends {
5124
5119
  multiValueHeaders: Record<string, string[]>;
5125
5120
  } ? {
5126
5121
  headers?: undefined;
@@ -3212,8 +3212,8 @@ var createApiKeyAuth = (fingerprints, policies = {}) => {
3212
3212
  if (!fingerprint || !policy) {
3213
3213
  c.status(httpStatus4.UNAUTHORIZED);
3214
3214
  return c.json({
3215
- status: httpStatus4.UNAUTHORIZED,
3216
- message: httpStatus4["401_MESSAGE"]
3215
+ code: "UNAUTHORIZED",
3216
+ message: "Missing or unknown API key"
3217
3217
  });
3218
3218
  }
3219
3219
  c.set("apiKey", __spreadProps(__spreadValues({}, principalFor(policy)), { fingerprint }));
@@ -3246,7 +3246,7 @@ var apiKeyAuth = ({
3246
3246
  };
3247
3247
 
3248
3248
  // middlewares/general-error-handler.ts
3249
- import { createFactory as createFactory2 } from "hono/factory";
3249
+ import { HTTPException } from "hono/http-exception";
3250
3250
 
3251
3251
  // helpers/dependencies.ts
3252
3252
  import { nanoid } from "nanoid";
@@ -3256,82 +3256,6 @@ import {
3256
3256
  EventBridgeClient,
3257
3257
  PutEventsCommand
3258
3258
  } from "@aws-sdk/client-eventbridge";
3259
-
3260
- // types/event.ts
3261
- var SOURCE = {
3262
- CORE: "core-service",
3263
- GENERAL: "general"
3264
- };
3265
- var EVENT = {
3266
- CORE: {
3267
- LOGIN_EMAIL_REQUESTED: {
3268
- Source: SOURCE.CORE,
3269
- DetailType: "login-email-requested"
3270
- },
3271
- /*
3272
- * Entity
3273
- */
3274
- ENTITY_CREATED: {
3275
- Source: SOURCE.CORE,
3276
- DetailType: "entity-created"
3277
- },
3278
- ENTITY_UPSERTED: {
3279
- Source: SOURCE.CORE,
3280
- DetailType: "entity-upserted"
3281
- },
3282
- ENTITY_UPDATED: {
3283
- Source: SOURCE.CORE,
3284
- DetailType: "entity-updated"
3285
- },
3286
- ENTITY_DELETED: {
3287
- Source: SOURCE.CORE,
3288
- DetailType: "entity-deleted"
3289
- },
3290
- ENTITY_MUTUAL_TO_CREATE: {
3291
- Source: SOURCE.CORE,
3292
- DetailType: "entity-mutual-to-create"
3293
- },
3294
- ENTITY_MUTUAL_TO_UPDATE: {
3295
- Source: SOURCE.CORE,
3296
- DetailType: "entity-mutual-to-update"
3297
- },
3298
- ENTITY_MUTUAL_PROCESSED: {
3299
- Source: SOURCE.CORE,
3300
- DetailType: "entity-mutual-processed"
3301
- },
3302
- CREATE_ENTITY: {
3303
- Source: SOURCE.CORE,
3304
- DetailType: "create-entity"
3305
- },
3306
- /*
3307
- * Mutual
3308
- */
3309
- MUTUAL_CREATED: (byEntityType, entityType) => ({
3310
- Source: SOURCE.CORE,
3311
- DetailType: `mutual-created:${byEntityType}:${entityType}`
3312
- }),
3313
- MUTUAL_UPDATED: (byEntityType, entityType) => ({
3314
- Source: SOURCE.CORE,
3315
- DetailType: `mutual-updated:${byEntityType}:${entityType}`
3316
- }),
3317
- MUTUAL_DELETED: (byEntityType, entityType) => ({
3318
- Source: SOURCE.CORE,
3319
- DetailType: `mutual-deleted:${byEntityType}:${entityType}`
3320
- }),
3321
- PREJOIN_RELATIONSHIP_SYNC: {
3322
- Source: SOURCE.CORE,
3323
- DetailType: "prejoin-relationship-sync"
3324
- }
3325
- },
3326
- GENERAL: {
3327
- ENDPOINT_ERROR: {
3328
- Source: SOURCE.GENERAL,
3329
- DetailType: "endpoint-error"
3330
- }
3331
- }
3332
- };
3333
-
3334
- // helpers/event.ts
3335
3259
  var eventBridge = new EventBridgeClient();
3336
3260
  function parseSQSBusEvent(evRecordBody) {
3337
3261
  const body = JSON.parse(evRecordBody);
@@ -3360,90 +3284,42 @@ function publishEvent(_0) {
3360
3284
  yield eventBridge.send(new PutEventsCommand(params));
3361
3285
  });
3362
3286
  }
3363
- function publishErrorEvent(_0) {
3364
- return __async(this, arguments, function* ({
3365
- id,
3366
- serviceName,
3367
- method,
3368
- path,
3369
- body,
3370
- error
3371
- }) {
3372
- yield publishEvent({
3373
- event: EVENT.GENERAL.ENDPOINT_ERROR,
3374
- payload: __spreadProps(__spreadValues({
3375
- id,
3376
- serviceName,
3377
- method,
3378
- path
3379
- }, body ? { requestBody: body } : {}), {
3380
- error: {
3381
- name: error.name,
3382
- message: error.message,
3383
- // @ts-ignore
3384
- cause: error.cause,
3385
- stack: error.stack
3386
- }
3387
- })
3388
- });
3389
- });
3390
- }
3391
3287
 
3392
3288
  // helpers/dependencies.ts
3393
3289
  var getDependencies = () => {
3394
3290
  return {
3395
3291
  nanoid,
3396
- publishEvent,
3397
- publishErrorEvent
3292
+ publishEvent
3398
3293
  };
3399
3294
  };
3400
3295
 
3401
3296
  // middlewares/general-error-handler.ts
3402
- var factory2 = createFactory2();
3403
- var generalErrorHandler = (dependencies = getDependencies()) => factory2.createMiddleware((c) => __async(null, null, function* () {
3297
+ var generalErrorHandler = (dependencies = getDependencies()) => (err, c) => {
3404
3298
  var _a, _b, _c, _d, _e;
3405
- if (c.error) {
3406
- const { nanoid: nanoid2, publishErrorEvent: publishErrorEvent2 } = dependencies;
3407
- const errorId = nanoid2();
3408
- const body = yield c.req.json();
3409
- yield publishErrorEvent2({
3410
- serviceName: "monorise-core",
3411
- method: c.req.method,
3412
- path: c.req.path,
3413
- id: errorId,
3414
- body,
3415
- error: c.error
3416
- });
3417
- const error = c.error;
3418
- console.warn("[MONORISE_DEBUG] INTERNAL_SERVER_EXCEPTION:", {
3419
- errorId,
3420
- method: c.req.method,
3421
- path: c.req.path,
3422
- apiKeyPolicy: (_a = c.get("apiKey")) == null ? void 0 : _a.policy,
3423
- errorName: error == null ? void 0 : error.name,
3424
- errorMessage: error == null ? void 0 : error.message,
3425
- errorCode: error == null ? void 0 : error.code,
3426
- errorStack: error == null ? void 0 : error.stack,
3427
- errorConstructor: (_b = error == null ? void 0 : error.constructor) == null ? void 0 : _b.name,
3428
- hasLastError: !!(error == null ? void 0 : error.lastError),
3429
- lastErrorName: (_d = (_c = error == null ? void 0 : error.lastError) == null ? void 0 : _c.constructor) == null ? void 0 : _d.name,
3430
- lastErrorMessage: (_e = error == null ? void 0 : error.lastError) == null ? void 0 : _e.message,
3431
- context: error == null ? void 0 : error.context
3432
- });
3433
- c.status(500);
3434
- c.json({
3435
- code: "INTERNAL_SERVER_EXCEPTION",
3436
- id: errorId
3437
- });
3438
- throw new Error(
3439
- `INTERNAL_SERVER_EXCEPTION: ${errorId}: ${c.req.method} ${c.req.path}: ${c.error}`
3440
- );
3441
- }
3442
- }));
3299
+ if (err instanceof HTTPException) return err.getResponse();
3300
+ const errorId = dependencies.nanoid();
3301
+ const error = err;
3302
+ console.warn("[MONORISE_DEBUG] INTERNAL_SERVER_EXCEPTION:", {
3303
+ errorId,
3304
+ method: c.req.method,
3305
+ path: c.req.path,
3306
+ apiKeyPolicy: (_a = c.get("apiKey")) == null ? void 0 : _a.policy,
3307
+ errorName: error == null ? void 0 : error.name,
3308
+ errorMessage: error == null ? void 0 : error.message,
3309
+ errorCode: error == null ? void 0 : error.code,
3310
+ errorStack: error == null ? void 0 : error.stack,
3311
+ errorConstructor: (_b = error == null ? void 0 : error.constructor) == null ? void 0 : _b.name,
3312
+ hasLastError: !!(error == null ? void 0 : error.lastError),
3313
+ lastErrorName: (_d = (_c = error == null ? void 0 : error.lastError) == null ? void 0 : _c.constructor) == null ? void 0 : _d.name,
3314
+ lastErrorMessage: (_e = error == null ? void 0 : error.lastError) == null ? void 0 : _e.message,
3315
+ context: error == null ? void 0 : error.context
3316
+ });
3317
+ return c.json({ code: "INTERNAL_SERVER_EXCEPTION", id: errorId }, 500);
3318
+ };
3443
3319
  var general_error_handler_default = generalErrorHandler;
3444
3320
 
3445
3321
  // handles/app.ts
3446
- var appHandler = (container) => ({ routes }) => {
3322
+ var createCoreApp = (container, { routes } = {}) => {
3447
3323
  const app = new Hono2().basePath("/core");
3448
3324
  app.use(secureHeaders());
3449
3325
  app.use(
@@ -3468,9 +3344,19 @@ var appHandler = (container) => ({ routes }) => {
3468
3344
  }
3469
3345
  }
3470
3346
  app.route("/", setupCommonRoutes(container));
3471
- app.use(general_error_handler_default());
3472
- return handle(app);
3347
+ app.notFound(
3348
+ (c) => c.json(
3349
+ {
3350
+ code: "NOT_FOUND",
3351
+ message: `No route for ${c.req.method} ${c.req.path}`
3352
+ },
3353
+ 404
3354
+ )
3355
+ );
3356
+ app.onError(general_error_handler_default());
3357
+ return app;
3473
3358
  };
3359
+ var appHandler = (container) => (args) => handle(createCoreApp(container, args));
3474
3360
 
3475
3361
  // handles/analytics-query.ts
3476
3362
  import {
@@ -3531,7 +3417,7 @@ var analyticsQueryHandler = () => {
3531
3417
  app.use("*", (c, next) => __async(null, null, function* () {
3532
3418
  const key = c.req.header("x-api-key");
3533
3419
  if (!key || !apiKeys().includes(key)) {
3534
- return c.json({ status: httpStatus5.UNAUTHORIZED, message: httpStatus5["401_MESSAGE"] }, httpStatus5.UNAUTHORIZED);
3420
+ return c.json({ code: "UNAUTHORIZED", message: "Missing or unknown API key" }, httpStatus5.UNAUTHORIZED);
3535
3421
  }
3536
3422
  return next();
3537
3423
  }));
@@ -8338,6 +8224,73 @@ var coerce = {
8338
8224
  };
8339
8225
  var NEVER = INVALID;
8340
8226
 
8227
+ // types/event.ts
8228
+ var SOURCE = {
8229
+ CORE: "core-service"
8230
+ };
8231
+ var EVENT = {
8232
+ CORE: {
8233
+ LOGIN_EMAIL_REQUESTED: {
8234
+ Source: SOURCE.CORE,
8235
+ DetailType: "login-email-requested"
8236
+ },
8237
+ /*
8238
+ * Entity
8239
+ */
8240
+ ENTITY_CREATED: {
8241
+ Source: SOURCE.CORE,
8242
+ DetailType: "entity-created"
8243
+ },
8244
+ ENTITY_UPSERTED: {
8245
+ Source: SOURCE.CORE,
8246
+ DetailType: "entity-upserted"
8247
+ },
8248
+ ENTITY_UPDATED: {
8249
+ Source: SOURCE.CORE,
8250
+ DetailType: "entity-updated"
8251
+ },
8252
+ ENTITY_DELETED: {
8253
+ Source: SOURCE.CORE,
8254
+ DetailType: "entity-deleted"
8255
+ },
8256
+ ENTITY_MUTUAL_TO_CREATE: {
8257
+ Source: SOURCE.CORE,
8258
+ DetailType: "entity-mutual-to-create"
8259
+ },
8260
+ ENTITY_MUTUAL_TO_UPDATE: {
8261
+ Source: SOURCE.CORE,
8262
+ DetailType: "entity-mutual-to-update"
8263
+ },
8264
+ ENTITY_MUTUAL_PROCESSED: {
8265
+ Source: SOURCE.CORE,
8266
+ DetailType: "entity-mutual-processed"
8267
+ },
8268
+ CREATE_ENTITY: {
8269
+ Source: SOURCE.CORE,
8270
+ DetailType: "create-entity"
8271
+ },
8272
+ /*
8273
+ * Mutual
8274
+ */
8275
+ MUTUAL_CREATED: (byEntityType, entityType) => ({
8276
+ Source: SOURCE.CORE,
8277
+ DetailType: `mutual-created:${byEntityType}:${entityType}`
8278
+ }),
8279
+ MUTUAL_UPDATED: (byEntityType, entityType) => ({
8280
+ Source: SOURCE.CORE,
8281
+ DetailType: `mutual-updated:${byEntityType}:${entityType}`
8282
+ }),
8283
+ MUTUAL_DELETED: (byEntityType, entityType) => ({
8284
+ Source: SOURCE.CORE,
8285
+ DetailType: `mutual-deleted:${byEntityType}:${entityType}`
8286
+ }),
8287
+ PREJOIN_RELATIONSHIP_SYNC: {
8288
+ Source: SOURCE.CORE,
8289
+ DetailType: "prejoin-relationship-sync"
8290
+ }
8291
+ }
8292
+ };
8293
+
8341
8294
  // services/mutual.service.ts
8342
8295
  function resolveAsEntity(mutualConfig, callOptions = {}) {
8343
8296
  var _a, _b;