@remit/backend 0.0.37 → 0.0.39

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remit/backend",
3
- "version": "0.0.37",
3
+ "version": "0.0.39",
4
4
  "description": "Remit Mail Inspector API backend",
5
5
  "license": "MIT",
6
6
  "author": "",
@@ -1,6 +1,6 @@
1
1
  import assert from "node:assert/strict";
2
2
  import { describe, it } from "node:test";
3
- import type { UpdateFilterInput } from "@remit/data-ports";
3
+ import type { UpdateFilterInput as UpdateFilterRequestBody } from "@remit/api-openapi-types";
4
4
  import { FilterScope, FilterState } from "@remit/domain-enums";
5
5
  import {
6
6
  pickFilterUpdate,
@@ -35,7 +35,7 @@ describe("pickFilterUpdate", () => {
35
35
  ruleChangedAt: 999,
36
36
  filterId: "sneaky",
37
37
  };
38
- const patch = pickFilterUpdate(raw as Partial<UpdateFilterInput>);
38
+ const patch = pickFilterUpdate(raw as Partial<UpdateFilterRequestBody>);
39
39
  assert.deepEqual(patch, { name: "Receipts" });
40
40
  });
41
41
  });
@@ -1,6 +1,7 @@
1
1
  import type {
2
2
  CreateFilterInput,
3
3
  FilterResponse,
4
+ UpdateFilterInput as UpdateFilterRequestBody,
4
5
  } from "@remit/api-openapi-types";
5
6
  import type { FilterItem, UpdateFilterInput } from "@remit/data-ports";
6
7
  import { BadRequestError } from "@remit/data-ports/errors";
@@ -93,19 +94,9 @@ export const deriveFilterTtl = (
93
94
  * dropped. `scope`/`expiresAt` land here as the caller sent them; a patch that
94
95
  * touches either still needs `resolveFilterScopeExpiry` to merge them against
95
96
  * the stored row and derive `ttl`/`state` before this reaches the repo.
96
- *
97
- * Typed against the internal `@remit/data-ports` `UpdateFilterInput`, not the
98
- * generated `@remit/api-openapi-types` one: that package publishes separately
99
- * from this repo, so a PR that both widens the TypeSpec model and reads the
100
- * new field in the same change would typecheck in-tree (fresh local codegen)
101
- * but fail `check-consumer-typecheck`/`release:dry-run`, which resolve
102
- * generated `@remit/*` packages off the registry, not the local `build/`
103
- * output. The data-ports shape carries every field this reads regardless —
104
- * it derives from the full `Filter` row, which has never gated `scope` or
105
- * `expiresAt` behind an API-visibility distinction.
106
97
  */
107
98
  export const pickFilterUpdate = (
108
- body: Partial<UpdateFilterInput>,
99
+ body: Partial<UpdateFilterRequestBody>,
109
100
  ): Partial<UpdateFilterInput> => {
110
101
  const patch: Partial<UpdateFilterInput> = {};
111
102
  if (Object.hasOwn(body, "name")) patch.name = body.name;
@@ -368,7 +359,7 @@ export const FilterDetailOperations: Record<
368
359
  assertAccountOwnership(account, accountConfigId, "act");
369
360
 
370
361
  const { filter } = client;
371
- const patch = pickFilterUpdate(body as Partial<UpdateFilterInput>);
362
+ const patch = pickFilterUpdate(body as Partial<UpdateFilterRequestBody>);
372
363
  const touchesScopeOrExpiry =
373
364
  Object.hasOwn(patch, "scope") || Object.hasOwn(patch, "expiresAt");
374
365
  const resolvedPatch: Partial<UpdateFilterInput> = touchesScopeOrExpiry
package/src/index.ts CHANGED
@@ -2,7 +2,7 @@ import { existsSync, readFileSync } from "node:fs";
2
2
  import { dirname, join } from "node:path";
3
3
  import { fileURLToPath } from "node:url";
4
4
  import { inspect } from "node:util";
5
- import { logger, withTelemetry } from "@remit/logger-lambda";
5
+ import { logger, withLogContext, withTelemetry } from "@remit/logger-lambda";
6
6
  import type { APIGatewayProxyEvent, Context } from "aws-lambda";
7
7
  import {
8
8
  type Document,
@@ -141,30 +141,36 @@ const readOriginHeader = (
141
141
  return undefined;
142
142
  };
143
143
 
144
- const rawHandler = async (event: APIGatewayProxyEvent, context: Context) => {
145
- logger.setBindings({
146
- requestId: context.awsRequestId,
147
- path: event.path,
148
- method: event.httpMethod,
149
- });
150
-
151
- logger.debug(
152
- { method: event.httpMethod, path: event.path },
153
- "Request received",
154
- );
155
-
156
- const origin = readOriginHeader(event.headers);
157
-
158
- if (usesBetterAuthJwt()) {
159
- const denied = await authenticatePostgresRequest(event);
160
- if (denied) return denied;
161
- }
162
-
163
- return runWithRequestContext({ origin }, () =>
164
- api
165
- .handleRequest(normalizeRequest(event), event, context)
166
- .catch(handleError),
144
+ // A scope, not `logger.setBindings`: this process serves requests concurrently,
145
+ // and bindings on the shared logger belong to whichever request wrote them last,
146
+ // so a line gets attributed to the wrong request. The scope follows the request
147
+ // through its own async continuations and nothing else.
148
+ const rawHandler = async (event: APIGatewayProxyEvent, context: Context) =>
149
+ withLogContext(
150
+ {
151
+ requestId: context.awsRequestId,
152
+ path: event.path,
153
+ method: event.httpMethod,
154
+ },
155
+ async () => {
156
+ logger.debug(
157
+ { method: event.httpMethod, path: event.path },
158
+ "Request received",
159
+ );
160
+
161
+ const origin = readOriginHeader(event.headers);
162
+
163
+ if (usesBetterAuthJwt()) {
164
+ const denied = await authenticatePostgresRequest(event);
165
+ if (denied) return denied;
166
+ }
167
+
168
+ return runWithRequestContext({ origin }, () =>
169
+ api
170
+ .handleRequest(normalizeRequest(event), event, context)
171
+ .catch(handleError),
172
+ );
173
+ },
167
174
  );
168
- };
169
175
 
170
176
  export const handler = withTelemetry(rawHandler);
@@ -28,10 +28,7 @@ const build = (): BuildFilterAnchor => {
28
28
  const embedder = buildEmbeddingServiceFromEnv();
29
29
  const store = buildVectorStoreFromEnv(embedder.dimensions);
30
30
  return (accountConfigId, anchorMessageId) =>
31
- buildMessageAnchor(
32
- { store, embedder },
33
- { accountConfigId, anchorMessageId },
34
- );
31
+ buildMessageAnchor({ store }, { accountConfigId, anchorMessageId });
35
32
  };
36
33
 
37
34
  export const buildFilterAnchor: BuildFilterAnchor = (
@@ -341,10 +341,7 @@ const buildSemanticFromEnv = (): OrganizeSemanticDeps => {
341
341
  const store = buildVectorStoreFromEnv(embedder.dimensions);
342
342
  cachedSemantic = {
343
343
  buildAnchor: (accountConfigId, anchorMessageId) =>
344
- buildMessageAnchor(
345
- { store, embedder },
346
- { accountConfigId, anchorMessageId },
347
- ),
344
+ buildMessageAnchor({ store }, { accountConfigId, anchorMessageId }),
348
345
  vectorStore: store,
349
346
  };
350
347
  return cachedSemantic;