Skip to content

feat: add standard offline sync runtime - #28

Merged
rdlabo merged 7 commits into
mainfrom
feat/offline-sync-standard
Jul 22, 2026
Merged

feat: add standard offline sync runtime#28
rdlabo merged 7 commits into
mainfrom
feat/offline-sync-standard

Conversation

@rdlabo

@rdlabo rdlabo commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add @rdlabo/ionic-angular-kit/offline secondary entry point
  • add user/group-scoped cache and durable aggregate-ordered outbox
  • isolate shared-device sessions by numeric user ID and authentication-provider subject
  • prevent stale flushes from writing after discard, logout, or session switch, and recover interrupted state transitions
  • report background persistence failures without replacing successful HTTP responses
  • use Ionic Storage on web and encrypted Capawesome SQLite on iOS/Android
  • keep URL, DTO, feature flags, and command execution in consuming applications

Compatibility

  • Angular and kit remain on version 21; no Angular 22 upgrade is included
  • primary kit entry point does not export or bundle the offline runtime
  • Capawesome SQLite is an optional peer and is injected only by native consumers
  • existing kit APIs are unchanged

Verification

  • kit production package build
  • kit 272 tests, including session races and Capawesome SQLite adapter contracts
  • offline ESLint
  • all other projects tested sequentially after full prebuild

@netlify

netlify Bot commented Jul 22, 2026

Copy link
Copy Markdown

Deploy Preview for rdlabo-ionic-angular-library ready!

Name Link
🔨 Latest commit be1f7ff
🔍 Latest deploy log https://app.netlify.com/projects/rdlabo-ionic-angular-library/deploys/6a60c8767afa830008e6222b
😎 Deploy Preview https://deploy-preview-28--rdlabo-ionic-angular-library.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@rdlabo
rdlabo marked this pull request as ready for review July 22, 2026 11:19
@rdlabo
rdlabo requested a review from Copilot July 22, 2026 11:22
devin-ai-integration[bot]

This comment was marked as resolved.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new optional @rdlabo/ionic-angular-kit/offline secondary entry point that provides a standard offline runtime (scoped cache + durable outbox + session boundary) without impacting existing consumers of the primary kit entry point.

Changes:

  • Introduces the /offline secondary entry point with repository abstractions (web: Ionic Storage; native: encrypted Capawesome SQLite) plus sync/coordinator/session services.
  • Adds an offline request-policy interceptor supporting cache fallback for transport failures and queued mutation responses.
  • Updates kit docs and build/test wiring to include the new offline entry point and its test suite.

Reviewed changes

Copilot reviewed 25 out of 26 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
projects/kit/tsconfig.spec.json Includes offline specs in kit test compilation.
projects/kit/src/public-api.ts Documents /offline as a separate secondary entry point.
projects/kit/README.md Adds consumer-facing setup/installation docs for the offline runtime.
projects/kit/package.json Adds optional peer dependency metadata for Capawesome SQLite.
projects/kit/offline/src/public-api.ts Exposes the offline runtime public surface.
projects/kit/offline/src/lib/sqlite-offline-repository.ts Implements encrypted native persistence via Capawesome SQLite.
projects/kit/offline/src/lib/sqlite-offline-repository.spec.ts Verifies SQLite adapter behaviors (transactions, key presence, sequencing).
projects/kit/offline/src/lib/offline.interceptor.ts Adds interceptor behavior for read caching and queued mutations.
projects/kit/offline/src/lib/offline.interceptor.spec.ts Tests interceptor behavior (bypass, cache fallback, persistence error reporting).
projects/kit/offline/src/lib/offline-sync.service.ts Implements aggregate-ordered outbox replay with retries and session guards.
projects/kit/offline/src/lib/offline-sync.service.spec.ts Tests sync ordering, hash stability, classification, and session/flush races.
projects/kit/offline/src/lib/offline-session.service.ts Adds shared-device session boundary + scope management.
projects/kit/offline/src/lib/offline-session.service.spec.ts Tests session activation and shared-device isolation semantics.
projects/kit/offline/src/lib/offline-request-policy.ts Defines DI-driven request policy resolution and bypass/header conventions.
projects/kit/offline/src/lib/offline-repository.ts Defines the repository contract and the Ionic Storage (web) implementation.
projects/kit/offline/src/lib/offline-repository.spec.ts Tests web repository scoping, ordering, ID allocation, and schema migration behavior.
projects/kit/offline/src/lib/offline-provider.ts Adds provideOffline(...) to wire the runtime via Angular DI.
projects/kit/offline/src/lib/offline-network.service.ts Adds offline/online/unverified network state tracking for runtime decisions.
projects/kit/offline/src/lib/offline-kit-options.ts Defines DI options for native encrypted persistence.
projects/kit/offline/src/lib/offline-error-reporter.ts Adds background persistence error reporting contract + default reporter.
projects/kit/offline/src/lib/offline-coordinator.service.ts Provides a high-level coordinator API for app integration (init, logout, flush).
projects/kit/offline/src/lib/offline-command-hooks.ts Adds optional product hooks for cache projection and command cleanup.
projects/kit/offline/src/lib/offline-command-executor.ts Defines the product adapter interface for executing offline commands.
projects/kit/offline/ng-package.json Declares the new ng-packagr secondary entry point.
package-lock.json Updates lockfile to reflect package output/versioning alignment.
angular.json Includes offline specs in Angular test configuration.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +6 to +7
import { OFFLINE_ERROR_REPORTER, type OfflineErrorReporter } from './offline-error-reporter';
import { isOfflineFallbackError } from './offline-network.service';
Comment on lines +15 to +34
export const offlineInterceptor: HttpInterceptorFn = (request, next) => {
if (request.context.get(OFFLINE_BYPASS)) return next(request);
const registry = inject(OfflineRequestPolicyRegistry);
const fallback = inject(OfflineRequestFallbackService);
const errorReporter = inject(OFFLINE_ERROR_REPORTER);
const plan = registry.resolve(request);
if (!plan) return next(request);
if (plan.kind === 'mutation') {
if (plan.enqueue) return enqueueMutation(plan.enqueue, request.urlWithParams);
if (!plan.storeFresh) return next(request);
return observeRemoteResponse(next(request), plan.storeFresh, errorReporter, request);
}
if (request.method !== 'GET') return next(request);
return observeRemoteResponse(
defer(() => next(request)),
plan.storeFresh,
errorReporter,
request,
).pipe(catchError((error: unknown) => fallback.handle(request, error, plan) ?? throwError(() => error)));
};
Comment thread projects/kit/README.md
Comment on lines +350 to +354
provideOffline({
// ...product policies and executor
sqlitePlugin: Sqlite,
encryptionKey: () => securePreferences.get({ key: 'offline-database-key' }).then(({ value }) => value),
});
Comment on lines +29 to +30
@Injectable({ providedIn: 'root' })
export class OfflineSyncService {
}

async #open(): Promise<void> {
if (!this.#sqlite) throw new Error('Native offline storage requires the Capawesome Sqlite plugin');
@rdlabo
rdlabo marked this pull request as draft July 22, 2026 11:30
@rdlabo
rdlabo marked this pull request as ready for review July 22, 2026 13:43
@rdlabo
rdlabo merged commit bb11465 into main Jul 22, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants