@teincfood/core 0.9.1 → 0.9.3

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/dist/index.d.ts CHANGED
@@ -141,7 +141,7 @@ export { getSyncJobsPendingCount, debugDumpSyncJobs, drainPending } from "./sync
141
141
  export { performFullSync } from "./sync/full-sync";
142
142
  export { stopHealthProbe } from "./sync/health-probe";
143
143
  export { notifyAuthChanged, subscribeAuth } from "./adapters/auth";
144
- export { isAuthenticated, hasActiveBusiness, canBusinessSync } from "./sync/sync-guard";
144
+ export { isAuthenticated, hasActiveBusiness, canBusinessSync, setOfflineSyncEnabled, isOfflineSyncEnabled } from "./sync/sync-guard";
145
145
  export { ACCESS_EXPIRED_CODE, SESSION_DEAD_CODES, SKIP_AUTH_RETRY, extractAuthFailure, isAccessExpired, isSessionDead, hasAuthRetrySkip, refreshSession, withAuthRetry, } from "./auth/session";
146
146
  export type { AuthFailure, SessionTokens } from "./auth/session";
147
147
  export { getCachedImagePath, ensureImageCacheDir, getCachedImageInfo, cacheRemoteImage, cacheImageBatch, clearImageCache, pruneImageCache, resolveImageSource, stableCacheUrl } from "./image-cache/service";
package/dist/index.js CHANGED
@@ -156,7 +156,7 @@ export { getSyncJobsPendingCount, debugDumpSyncJobs, drainPending } from "./sync
156
156
  export { performFullSync } from "./sync/full-sync";
157
157
  export { stopHealthProbe } from "./sync/health-probe";
158
158
  export { notifyAuthChanged, subscribeAuth } from "./adapters/auth";
159
- export { isAuthenticated, hasActiveBusiness, canBusinessSync } from "./sync/sync-guard";
159
+ export { isAuthenticated, hasActiveBusiness, canBusinessSync, setOfflineSyncEnabled, isOfflineSyncEnabled } from "./sync/sync-guard";
160
160
  // ── Session lifecycle (access-expired → refresh → refresh-expired → logout)
161
161
  export { ACCESS_EXPIRED_CODE, SESSION_DEAD_CODES, SKIP_AUTH_RETRY, extractAuthFailure, isAccessExpired, isSessionDead, hasAuthRetrySkip, refreshSession, withAuthRetry, } from "./auth/session";
162
162
  // ── Image cache (durable) ──
@@ -7,10 +7,13 @@
7
7
  * the user has logged in and a business is selected. User-scoped queries
8
8
  * (invitations, fleet) gate on auth only.
9
9
  */
10
+ export declare function setOfflineSyncEnabled(enabled: boolean): void;
11
+ export declare function isOfflineSyncEnabled(): boolean;
10
12
  export declare function isAuthenticated(): boolean;
11
13
  export declare function hasActiveBusiness(): boolean;
12
14
  /**
13
- * Business sync may run only when both authenticated and a business is selected.
15
+ * Business sync may run only when offline sync is enabled for the role,
16
+ * authenticated and a business is selected.
14
17
  * Pass an explicit `businessId` to test that specific id; otherwise reads
15
18
  * the active business store.
16
19
  */
@@ -9,6 +9,17 @@
9
9
  */
10
10
  import { getAuthToken } from "../adapters/auth";
11
11
  import { getActiveBusiness } from "../adapters/business";
12
+ // Offline machinery (reference sync, drains, pulls, leases) runs for the
13
+ // seller role only. Fleet managers and riders are fully online: the app
14
+ // disables this flag on role change, which funnels through canBusinessSync
15
+ // and stops every business sync path at once.
16
+ let offlineSyncEnabled = true;
17
+ export function setOfflineSyncEnabled(enabled) {
18
+ offlineSyncEnabled = enabled;
19
+ }
20
+ export function isOfflineSyncEnabled() {
21
+ return offlineSyncEnabled;
22
+ }
12
23
  export function isAuthenticated() {
13
24
  return !!getAuthToken();
14
25
  }
@@ -16,11 +27,14 @@ export function hasActiveBusiness() {
16
27
  return !!getActiveBusiness()?.id;
17
28
  }
18
29
  /**
19
- * Business sync may run only when both authenticated and a business is selected.
30
+ * Business sync may run only when offline sync is enabled for the role,
31
+ * authenticated and a business is selected.
20
32
  * Pass an explicit `businessId` to test that specific id; otherwise reads
21
33
  * the active business store.
22
34
  */
23
35
  export function canBusinessSync(businessId) {
36
+ if (!offlineSyncEnabled)
37
+ return false;
24
38
  const bid = businessId ?? getActiveBusiness()?.id;
25
39
  return !!bid && !!getAuthToken();
26
40
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teincfood/core",
3
- "version": "0.9.1",
3
+ "version": "0.9.3",
4
4
  "description": "TeincFood shared offline-first core — types, sync engine, local DB, reference data, and repositories for mobile + desktop",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -8,15 +8,21 @@
8
8
  "exports": {
9
9
  ".": {
10
10
  "types": "./dist/index.d.ts",
11
- "import": "./dist/index.js"
11
+ "react-native": "./dist/index.js",
12
+ "import": "./dist/index.js",
13
+ "default": "./dist/index.js"
12
14
  },
13
15
  "./dist/*.js": {
14
16
  "types": "./dist/*.d.ts",
15
- "import": "./dist/*.js"
17
+ "react-native": "./dist/*.js",
18
+ "import": "./dist/*.js",
19
+ "default": "./dist/*.js"
16
20
  },
17
21
  "./dist/*": {
18
22
  "types": "./dist/*.d.ts",
19
- "import": "./dist/*.js"
23
+ "react-native": "./dist/*.js",
24
+ "import": "./dist/*.js",
25
+ "default": "./dist/*.js"
20
26
  }
21
27
  },
22
28
  "files": [