@friggframework/core 2.0.0--canary.743.265a5cd.0 → 2.0.0--canary.743.a254104.0

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/core/Worker.js CHANGED
@@ -217,21 +217,6 @@ class Worker {
217
217
  });
218
218
  }
219
219
 
220
- // A paced error carries the key's next slot. A message that was paced
221
- // before and is paced again comes back at a random point between the
222
- // earliest call time and that slot, so the messages that came in after
223
- // it do not keep it at the back of the backlog.
224
- _pacedRetryAt(error, slotAt, body) {
225
- const notBefore = validDate(error.notBefore);
226
- if (!notBefore || !(readDeferral(body).pacedDeferrals > 0)) {
227
- return slotAt;
228
- }
229
- const span = Math.max(0, slotAt.getTime() - notBefore.getTime());
230
- return new Date(
231
- notBefore.getTime() + Math.floor((this._random ?? Math.random)() * span)
232
- );
233
- }
234
-
235
220
  async defer(record, body, error, delivery) {
236
221
  const queueName = queueNameOf(record.eventSourceARN);
237
222
  if (!queueName || queueName.endsWith('.fifo')) {
@@ -245,9 +230,8 @@ class Worker {
245
230
  // The requester already spread a paced error over the key's slots.
246
231
  // An error from a module with no rate-limit policy keeps its exact
247
232
  // retryAt: no policy, no change (ADR-049 A.4).
248
- const retryAt = error.paced
249
- ? this._pacedRetryAt(error, earliest, body)
250
- : error.declaredPolicy !== true
233
+ const retryAt =
234
+ error.paced || error.declaredPolicy !== true
251
235
  ? earliest
252
236
  : jitteredRetryAt(
253
237
  earliest,
@@ -3,7 +3,6 @@ const {
3
3
  } = require('../requester/rate-limit/state/rate-limit-state-repository-interface');
4
4
  const {
5
5
  getEncryptedFields,
6
- getFieldsToEncryptOnWrite,
7
6
  } = require('../../database/encryption/encryption-schema-registry');
8
7
 
9
8
  // Entity.data holds the integration's own fields and, under STATE_FIELD, the
@@ -45,12 +44,14 @@ function dataSetPaths(fields) {
45
44
  /**
46
45
  * True when an update may merge Entity.data with a raw statement. A raw
47
46
  * statement skips the Prisma encryption extension, so it is used only when
48
- * the app encrypts no Entity field on write. Otherwise the update goes
47
+ * the app lists no Entity field for encryption (opted out or not). Otherwise the update goes
49
48
  * through the Prisma model, which encrypts, and the rate-limit state is
50
49
  * written back as it was read (the pacer's state is advisory and fails open).
51
50
  */
52
51
  function canMergeEntityDataRaw() {
53
- return getFieldsToEncryptOnWrite('Entity').length === 0;
52
+ // Every listed field, opted-out ones too: an opted-out field can still
53
+ // hold ciphertext in old rows, and only the Prisma model reads it.
54
+ return getEncryptedFields('Entity').length === 0;
54
55
  }
55
56
 
56
57
  /**
@@ -392,17 +392,12 @@ class RateLimitPacer {
392
392
  for (const bucket of buckets) bucket.take();
393
393
  if (waitMs === 0) return { granted: true, waitMs: 0 };
394
394
  // Callers that wait for the end of a block do not all call at that
395
- // moment: each one adds a random part of the block (up to 1 s, or one
396
- // interval of the key), inside the budget, so the calls of many
397
- // processes spread out.
395
+ // moment: each one adds a random part of the block (up to 1 s),
396
+ // inside the budget, so the calls of many processes spread out.
398
397
  const jitterMs =
399
398
  reason === 'blocked'
400
399
  ? Math.floor(
401
- this.random() *
402
- Math.max(
403
- Math.min(blockWaitMs, MAX_RELEASE_JITTER_MS),
404
- this.intervalMs({ scopeKey, policy }) ?? 0
405
- )
400
+ this.random() * Math.min(blockWaitMs, MAX_RELEASE_JITTER_MS)
406
401
  )
407
402
  : 0;
408
403
  return {
@@ -511,9 +506,9 @@ class RateLimitPacer {
511
506
  * takes no slot and comes back at a random point in the rest of the
512
507
  * range. The sequence moves back inside the range as time passes.
513
508
  * So a burst backlog stays in the delay tier, never spends receives, and
514
- * never writes a user message. (The queue worker moves a message that is
515
- * paced again to a random point before its slot, so it is not put behind
516
- * every newer message.)
509
+ * never writes a user message. Slots go in arrival order and are never
510
+ * given back, so under a long overload a message that is paced again
511
+ * waits behind newer ones; the deferral caps bound that wait.
517
512
  *
518
513
  * @returns {Promise<Date>}
519
514
  */
@@ -21,9 +21,10 @@ function toNumber(value) {
21
21
  return Number.isFinite(number) ? number : null;
22
22
  }
23
23
 
24
+ // An entity whose `data` is a string (an encrypted value) holds no state.
24
25
  const entityFilter = (entityId) =>
25
26
  typeof entityId === 'string' && OBJECT_ID.test(entityId)
26
- ? { _id: { $oid: entityId } }
27
+ ? { _id: { $oid: entityId }, data: { $not: { $type: 'string' } } }
27
28
  : undefined;
28
29
 
29
30
  /**
@@ -59,7 +59,8 @@ class RateLimitStateRepositoryPostgres extends RateLimitStateRepositoryInterface
59
59
  ))
60
60
  )
61
61
  )
62
- WHERE "id" = ${id}`;
62
+ WHERE "id" = ${id}
63
+ AND ("data" IS NULL OR jsonb_typeof("data") = 'object')`;
63
64
  }
64
65
 
65
66
  async reserveSlot(
@@ -91,6 +92,7 @@ class RateLimitStateRepositoryPostgres extends RateLimitStateRepositoryInterface
91
92
  )
92
93
  )
93
94
  WHERE "id" = ${id}
95
+ AND ("data" IS NULL OR jsonb_typeof("data") = 'object')
94
96
  AND GREATEST(
95
97
  COALESCE(("data" -> ${STATE_FIELD}::text -> ${member}::text
96
98
  ->> 'nextSlotMs')::bigint, 0),
@@ -101,9 +103,11 @@ class RateLimitStateRepositoryPostgres extends RateLimitStateRepositoryInterface
101
103
  if (rows.length > 0) {
102
104
  return new Date(Number(rows[0].nextSlotMs) - Number(step));
103
105
  }
104
- // No row: the entity is gone, or every slot up to notAfter is taken.
106
+ // No row: the entity is gone, its data is not a JSON object (an
107
+ // encrypted value), or every slot up to notAfter is taken.
105
108
  const exists = await this.prisma.$queryRaw`
106
- SELECT 1 AS "found" FROM "Entity" WHERE "id" = ${id}`;
109
+ SELECT 1 AS "found" FROM "Entity" WHERE "id" = ${id}
110
+ AND ("data" IS NULL OR jsonb_typeof("data") = 'object')`;
107
111
  return exists.length > 0 ? SLOTS_FULL : null;
108
112
  }
109
113
  }
@@ -653,8 +653,6 @@ class Requester extends Delegate {
653
653
  error.statusCode = 429;
654
654
  error.preempted = true;
655
655
  error.paced = true;
656
- // The earliest time a call can go; retryAt is the key's slot.
657
- error.notBefore = new Date(now + gate.waitMs);
658
656
  error.message = `${error.message} paced: not sent`;
659
657
  this._logPaced(gate, scopeKey, error);
660
658
  throw error;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@friggframework/core",
3
3
  "prettier": "@friggframework/prettier-config",
4
- "version": "2.0.0--canary.743.265a5cd.0",
4
+ "version": "2.0.0--canary.743.a254104.0",
5
5
  "dependencies": {
6
6
  "@aws-sdk/client-apigatewaymanagementapi": "^3.588.0",
7
7
  "@aws-sdk/client-kms": "^3.588.0",
@@ -11,7 +11,7 @@
11
11
  "@aws-sdk/client-sqs": "^3.588.0",
12
12
  "@aws-sdk/client-ssm": "^3.588.0",
13
13
  "@aws-sdk/s3-request-presigner": "^3.588.0",
14
- "@friggframework/schemas": "2.0.0--canary.743.265a5cd.0",
14
+ "@friggframework/schemas": "2.0.0--canary.743.a254104.0",
15
15
  "@hapi/boom": "^10.0.1",
16
16
  "@opentelemetry/api": "^1.9.1",
17
17
  "@opentelemetry/context-async-hooks": "^2.9.0",
@@ -49,9 +49,9 @@
49
49
  }
50
50
  },
51
51
  "devDependencies": {
52
- "@friggframework/eslint-config": "2.0.0--canary.743.265a5cd.0",
53
- "@friggframework/prettier-config": "2.0.0--canary.743.265a5cd.0",
54
- "@friggframework/test": "2.0.0--canary.743.265a5cd.0",
52
+ "@friggframework/eslint-config": "2.0.0--canary.743.a254104.0",
53
+ "@friggframework/prettier-config": "2.0.0--canary.743.a254104.0",
54
+ "@friggframework/test": "2.0.0--canary.743.a254104.0",
55
55
  "@prisma/client": "^6.19.3",
56
56
  "@types/lodash": "4.17.15",
57
57
  "@typescript-eslint/eslint-plugin": "^8.0.0",
@@ -93,5 +93,5 @@
93
93
  "publishConfig": {
94
94
  "access": "public"
95
95
  },
96
- "gitHead": "265a5cd5f39515f47164aec0b99fed86048b59d9"
96
+ "gitHead": "a25410415a2aed83688bd93a995f1185ee722501"
97
97
  }