@friggframework/core 2.0.0--canary.623.ee3bde8.0 → 2.0.0--canary.623.ce8e6ae.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.
@@ -11,10 +11,8 @@ class Requester extends Delegate {
11
11
  this.backOff = get(params, 'backOff', [1, 3, 10, 30, 60, 180]);
12
12
  this.isRefreshable = false;
13
13
  this.refreshCount = 0;
14
- // Independent from the `i` backoff-attempt counter passed through
15
- // _request's recursion a 429/5xx retry earlier in the same call
16
- // already advances `i`, and gating the 401 grace retry on `i === 0`
17
- // would skip it whenever a 401 follows any prior backoff response.
14
+ // Deliberately separate from `i` a 429/5xx retry must not consume
15
+ // the 401 grace retry budget below.
18
16
  this.authGraceRetryCount = 0;
19
17
  this.DLGT_INVALID_AUTH = 'INVALID_AUTH';
20
18
  this.delegateTypes.push(this.DLGT_INVALID_AUTH);
@@ -63,7 +61,7 @@ class Requester extends Delegate {
63
61
  return resp.text();
64
62
  };
65
63
 
66
- async _request(url, options, i = 0) {
64
+ async _request(url, options, attempt = 0) {
67
65
  let encodedUrl = encodeURI(url);
68
66
  if (options.query) {
69
67
  let queryBuild = '?';
@@ -121,11 +119,11 @@ class Requester extends Delegate {
121
119
  // stall at batch scale.
122
120
  const isTimeout =
123
121
  e?.name === 'AbortError' || e?.type === 'aborted';
124
- if (e?.code === 'ECONNRESET' && i < this.backOff.length) {
122
+ if (e?.code === 'ECONNRESET' && attempt < this.backOff.length) {
125
123
  clearRequestTimer();
126
- const delay = this.backOff[i] * 1000;
124
+ const delay = this.backOff[attempt] * 1000;
127
125
  await new Promise((resolve) => setTimeout(resolve, delay));
128
- return this._request(url, options, i + 1);
126
+ return this._request(url, options, attempt + 1);
129
127
  }
130
128
  const fetchError = await FetchError.create({
131
129
  resource: encodedUrl,
@@ -148,25 +146,20 @@ class Requester extends Delegate {
148
146
  const { status } = response;
149
147
 
150
148
  // If the status is retriable and there are back off requests left, retry the request
151
- if ((status === 429 || status >= 500) && i < this.backOff.length) {
149
+ if (
150
+ (status === 429 || status >= 500) &&
151
+ attempt < this.backOff.length
152
+ ) {
152
153
  clearRequestTimer();
153
- const delay = this.backOff[i] * 1000;
154
+ const delay = this.backOff[attempt] * 1000;
154
155
  await new Promise((resolve) => setTimeout(resolve, delay));
155
- return this._request(url, options, i + 1);
156
+ return this._request(url, options, attempt + 1);
156
157
  }
157
158
 
158
159
  if (status === 401) {
159
160
  if (!this.isRefreshable) {
160
- // A non-refreshable requester (ApiKeyRequester,
161
- // BasicAuthRequester) has no token to renew, but a single
162
- // 401 is not necessarily proof the credential itself is
163
- // bad — it may be a transient edge/gateway hiccup. Grant
164
- // one grace retry of the same request before concluding
165
- // the credential is truly invalid, mirroring the single
166
- // refresh attempt OAuth2Requester gets below. Gated on
167
- // authGraceRetryCount rather than `i` so an earlier
168
- // 429/5xx backoff on the same call doesn't consume the
169
- // grace retry before a 401 is even seen.
161
+ // One grace retry before invalidating — a single 401
162
+ // isn't proof the credential is bad.
170
163
  if (this.authGraceRetryCount === 0) {
171
164
  this.authGraceRetryCount++;
172
165
  clearRequestTimer();
@@ -174,7 +167,7 @@ class Requester extends Delegate {
174
167
  await new Promise((resolve) =>
175
168
  setTimeout(resolve, delay)
176
169
  );
177
- return this._request(url, options, i + 1);
170
+ return this._request(url, options, attempt + 1);
178
171
  }
179
172
 
180
173
  throw await this._invalidateAuth(
@@ -189,7 +182,7 @@ class Requester extends Delegate {
189
182
  const refreshSucceeded = await this.refreshAuth();
190
183
  if (refreshSucceeded) {
191
184
  clearRequestTimer();
192
- return this._request(url, options, i + 1);
185
+ return this._request(url, options, attempt + 1);
193
186
  }
194
187
 
195
188
  throw await this._invalidateAuth(
@@ -215,10 +208,9 @@ class Requester extends Delegate {
215
208
  );
216
209
  }
217
210
 
218
- // Successful response: reset the per-instance refresh/grace
219
- // budgets so a later 401 in the same Requester lifetime can
220
- // attempt refresh (or another grace retry) again instead of
221
- // silently falling through.
211
+ // Successful response: reset the per-instance refresh budget so
212
+ // a later 401 in the same Requester lifetime can attempt refresh
213
+ // again instead of silently falling through.
222
214
  this.refreshCount = 0;
223
215
  this.authGraceRetryCount = 0;
224
216
 
@@ -237,12 +229,6 @@ class Requester extends Delegate {
237
229
  }
238
230
  }
239
231
 
240
- // Builds a diagnostic FetchError from the failed 401 response, notifies
241
- // delegates with it attached (so the credential-invalidation chain can
242
- // log real detail instead of a bare "invalid credentials" with no
243
- // evidence), and returns the error for the caller to throw. Notifying
244
- // and throwing are split so notify() always fires even though `await`ing
245
- // it happens before the throw.
246
232
  async _invalidateAuth(encodedUrl, options, response) {
247
233
  const fetchError = await FetchError.create({
248
234
  resource: encodedUrl,
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.623.ee3bde8.0",
4
+ "version": "2.0.0--canary.623.ce8e6ae.0",
5
5
  "dependencies": {
6
6
  "@aws-sdk/client-apigatewaymanagementapi": "^3.588.0",
7
7
  "@aws-sdk/client-kms": "^3.588.0",
@@ -38,9 +38,9 @@
38
38
  }
39
39
  },
40
40
  "devDependencies": {
41
- "@friggframework/eslint-config": "2.0.0--canary.623.ee3bde8.0",
42
- "@friggframework/prettier-config": "2.0.0--canary.623.ee3bde8.0",
43
- "@friggframework/test": "2.0.0--canary.623.ee3bde8.0",
41
+ "@friggframework/eslint-config": "2.0.0--canary.623.ce8e6ae.0",
42
+ "@friggframework/prettier-config": "2.0.0--canary.623.ce8e6ae.0",
43
+ "@friggframework/test": "2.0.0--canary.623.ce8e6ae.0",
44
44
  "@prisma/client": "^6.19.3",
45
45
  "@types/lodash": "4.17.15",
46
46
  "@typescript-eslint/eslint-plugin": "^8.0.0",
@@ -80,5 +80,5 @@
80
80
  "publishConfig": {
81
81
  "access": "public"
82
82
  },
83
- "gitHead": "ee3bde8d1adc7e90a424a26429ce4b4d612ff52f"
83
+ "gitHead": "ce8e6ae7f60121290cc48fd3f36653fd18790204"
84
84
  }