@rdlabo/ionic-angular-kit 22.0.8 → 22.0.9

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/docs/auth-http.md CHANGED
@@ -92,6 +92,8 @@ export const appConfig: ApplicationConfig = {
92
92
 
93
93
  Automatic retry is limited to `GET`, `HEAD`, `OPTIONS`, or requests carrying an `Idempotency-Key`. Ordinary writes are never retried automatically. Retries cover transient statuses `0`, `408`, `429`, `502`, `503`, and `504`, and honor `Retry-After`.
94
94
 
95
+ For keyed writes, `isWriteOutcomeUnknown(error)` is true for a lost response, timeout, or server error, including when a later retry returns a different HTTP status. Reuse the original key and payload when retrying such a write.
96
+
95
97
  When offline support is enabled, register `offlineInterceptor` before `kitAuthInterceptor`. Local mode then prevents credential generation and network transport while allowing a matched read policy to serve the scoped replica.
96
98
 
97
99
  ### Request-owned error notifications
@@ -1,6 +1,6 @@
1
1
  import * as i0 from '@angular/core';
2
2
  import { InjectionToken, inject, Injectable, signal, computed, ErrorHandler, effect, untracked, makeEnvironmentProviders, provideAppInitializer } from '@angular/core';
3
- import { KitStorageService } from '@rdlabo/ionic-angular-kit';
3
+ import { KitStorageService, isWriteOutcomeUnknown } from '@rdlabo/ionic-angular-kit';
4
4
  import { toObservable } from '@angular/core/rxjs-interop';
5
5
  import { map as map$1, distinctUntilChanged } from 'rxjs/operators';
6
6
  import { HttpContextToken, HttpClient, HttpContext, HttpErrorResponse, HttpResponse } from '@angular/common/http';
@@ -997,6 +997,13 @@ function normalizeOfflineReplicaTransientWriteError(error) {
997
997
  return error;
998
998
  }
999
999
 
1000
+ /** Restore timeouts stored as permanent rejections by older versions of the outbox. */
1001
+ function recoverOfflineCommand(command) {
1002
+ return command.state === 'rejected' && command.lastErrorCode === '408'
1003
+ ? { ...command, state: 'retry_wait', retryAt: null, serverCommitUnknown: true }
1004
+ : command;
1005
+ }
1006
+
1000
1007
  /** Current durable storage schema used by both web and native repositories. */
1001
1008
  const OFFLINE_SCHEMA_VERSION = 2;
1002
1009
  const settledRepositoryOperation = async () => undefined;
@@ -1104,7 +1111,8 @@ class IonicOfflineRepository {
1104
1111
  async runReadSnapshot(read) {
1105
1112
  return this.#withCommittedRead(() => read(this.#reader()));
1106
1113
  }
1107
- #normalizeCommand(command) {
1114
+ #normalizeCommand(stored) {
1115
+ const command = recoverOfflineCommand(stored);
1108
1116
  if (command.serverCommitUnknown !== undefined)
1109
1117
  return command;
1110
1118
  const legacyAmbiguousFailure = command.attempts >= 2 && ['blocked_auth', 'conflict', 'rejected'].includes(command.state);
@@ -4456,7 +4464,7 @@ class OfflineSyncService {
4456
4464
  if (status === 409 || status === 412) {
4457
4465
  return { ...command, state: 'conflict', lastErrorCode: String(status), serverCommitUnknown };
4458
4466
  }
4459
- if (status >= 400 && status < 500 && status !== 429) {
4467
+ if (status >= 400 && status < 500 && status !== 408 && status !== 429) {
4460
4468
  return { ...command, state: 'rejected', lastErrorCode: String(status), serverCommitUnknown };
4461
4469
  }
4462
4470
  const retryAt = Date.now() + offlineRetryDelayMs(command.attempts, this.#retryRandom);
@@ -4504,7 +4512,7 @@ class OfflineSyncService {
4504
4512
  }
4505
4513
  #serverCommitCouldBeUnknown(error) {
4506
4514
  const status = this.#errorStatus(error);
4507
- return status === 0 || status === 429 || status >= 500;
4515
+ return status === 0 || status === 429 || isWriteOutcomeUnknown(error);
4508
4516
  }
4509
4517
  #reportError(error) {
4510
4518
  queueMicrotask(() => this.#dispatchError(error));
@@ -6862,7 +6870,7 @@ class SqliteOfflineRepository {
6862
6870
  return this.#number(rows[0]?.['data_version']);
6863
6871
  }
6864
6872
  #command(row) {
6865
- return {
6873
+ const command = {
6866
6874
  commandId: this.#string(row['command_id']),
6867
6875
  userId: parseOfflinePrincipalId(this.#string(row['user_id'])),
6868
6876
  scopeId: this.#string(row['scope_id']),
@@ -6895,6 +6903,7 @@ class SqliteOfflineRepository {
6895
6903
  ? {}
6896
6904
  : { reconciliationIdentity: this.#parse(row['reconciliation_identity_json']) }),
6897
6905
  };
6906
+ return recoverOfflineCommand(command);
6898
6907
  }
6899
6908
  #putCommand(databaseId, command) {
6900
6909
  return this.#execute(databaseId, `INSERT INTO offline_sync_commands