@rdlabo/ionic-angular-kit 21.5.14 → 21.5.15

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.
@@ -2074,6 +2074,7 @@ class OfflineOutboxCapacityError extends Error {
2074
2074
  }
2075
2075
  const MAX_PARALLEL_AGGREGATES = 3;
2076
2076
  const MAX_BACKOFF_MS = 60 * 60 * 1000;
2077
+ const POST_SEND_PULL_RETRY_MS = 1_000;
2077
2078
  const DEFAULT_MAX_OUTBOX_COMMANDS_PER_USER = 1_000;
2078
2079
  const DEFAULT_MAX_OUTBOX_BYTES_PER_USER = 10 * 1024 * 1024;
2079
2080
  /** Maintains the optimistic local replica and synchronizes its durable outbox. */
@@ -2366,7 +2367,7 @@ class OfflineSyncService {
2366
2367
  if (options.flush !== false && this.#network.connected())
2367
2368
  this.#flushInBackground();
2368
2369
  }
2369
- /** Clears a retry backoff selected explicitly by the user and sends the durable command now. */
2370
+ /** Clears a retry backoff/auth block selected explicitly by the user and sends the durable command now. */
2370
2371
  async retryNow(commandId) {
2371
2372
  await this.initialize();
2372
2373
  this.#invalidateFlush();
@@ -2379,8 +2380,8 @@ class OfflineSyncService {
2379
2380
  const current = (await this.#readKnownCommands()).find((item) => item.commandId === commandId);
2380
2381
  if (!current)
2381
2382
  return false;
2382
- if (current.state !== 'retry_wait') {
2383
- throw new Error(`Offline command ${commandId} is not waiting for retry.`);
2383
+ if (current.state !== 'retry_wait' && current.state !== 'blocked_auth') {
2384
+ throw new Error(`Offline command ${commandId} is not waiting for retry or reauthentication.`);
2384
2385
  }
2385
2386
  await repository.putCommand({ ...current, state: 'pending', retryAt: null, lastErrorCode: null });
2386
2387
  return true;
@@ -2427,6 +2428,7 @@ class OfflineSyncService {
2427
2428
  return;
2428
2429
  await this.#pull.pull(scope);
2429
2430
  }
2431
+ const dirtyScopes = new Map();
2430
2432
  while (this.#network.connected() && this.#isCurrent(generation)) {
2431
2433
  const groups = this.#eligibleAggregateGroups(await this.#readKnownCommands());
2432
2434
  if (!this.#isCurrent(generation))
@@ -2438,12 +2440,33 @@ class OfflineSyncService {
2438
2440
  while (cursor < groups.length) {
2439
2441
  const group = groups[cursor++];
2440
2442
  if (group && this.#isCurrent(generation))
2441
- await this.#sendAggregate(group, generation);
2443
+ await this.#sendAggregate(group, generation, dirtyScopes);
2442
2444
  }
2443
2445
  });
2444
2446
  await Promise.all(workers);
2445
2447
  }
2448
+ const postPullFailures = [];
2449
+ for (const scope of dirtyScopes.values()) {
2450
+ if (!this.#isCurrent(generation) || !this.#network.connected())
2451
+ break;
2452
+ try {
2453
+ // A command response may contain only the aggregate's base row. Pull
2454
+ // once per dirty scope so sibling-table journal entries are visible
2455
+ // before the completed Outbox state is exposed to product UI.
2456
+ await this.#pull.pull(scope);
2457
+ }
2458
+ catch (error) {
2459
+ postPullFailures.push(error);
2460
+ }
2461
+ }
2446
2462
  await this.#refreshState(generation);
2463
+ if (postPullFailures.length > 0 && this.#isCurrent(generation)) {
2464
+ // The server command is already committed and acknowledged locally, so
2465
+ // never resend it. Retry only the idempotent scope pull and surface the
2466
+ // failure to explicit flush callers/ErrorHandler.
2467
+ this.#scheduleRetry(Date.now() + POST_SEND_PULL_RETRY_MS);
2468
+ throw postPullFailures[0];
2469
+ }
2447
2470
  }
2448
2471
  #eligibleAggregateGroups(commands) {
2449
2472
  const now = Date.now();
@@ -2459,7 +2482,7 @@ class OfflineSyncService {
2459
2482
  return head?.state === 'pending' || (head?.state === 'retry_wait' && (head.retryAt ?? 0) <= now);
2460
2483
  });
2461
2484
  }
2462
- async #sendAggregate(commands, generation) {
2485
+ async #sendAggregate(commands, generation, dirtyScopes) {
2463
2486
  for (const command of commands) {
2464
2487
  if (!this.#isCurrent(generation))
2465
2488
  return;
@@ -2504,6 +2527,10 @@ class OfflineSyncService {
2504
2527
  if (!this.#isCurrent(generation))
2505
2528
  return;
2506
2529
  await this.#completeCommand(commands, sending, result, generation);
2530
+ if (this.#isCurrent(generation)) {
2531
+ const scope = { userId: sending.userId, scopeId: sending.scopeId };
2532
+ dirtyScopes.set(this.#scopeKey(scope), scope);
2533
+ }
2507
2534
  }
2508
2535
  }
2509
2536
  async #normalizeEnqueueRequest(scope, request, commandIdentity) {