@carlonicora/nextjs-jsonapi 6.12.2 → 6.13.1

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.
Files changed (256) hide show
  1. package/dist/{ApiData-DPKNfY-9.d.mts → ApiData-Be8yxCOX.d.mts} +2 -0
  2. package/dist/{ApiData-DPKNfY-9.d.ts → ApiData-Be8yxCOX.d.ts} +2 -0
  3. package/dist/{BlockNoteEditor-7M5QW2YQ.js → BlockNoteEditor-UBVEUFNR.js} +34 -22
  4. package/dist/BlockNoteEditor-UBVEUFNR.js.map +1 -0
  5. package/dist/{BlockNoteEditor-75ED2CN2.mjs → BlockNoteEditor-VXMDSQAA.mjs} +20 -8
  6. package/dist/BlockNoteEditor-VXMDSQAA.mjs.map +1 -0
  7. package/dist/{BlockNoteViewer-WGCDB7IJ.js → BlockNoteViewer-2XYASA5Y.js} +8 -5
  8. package/dist/BlockNoteViewer-2XYASA5Y.js.map +1 -0
  9. package/dist/{BlockNoteViewer-MTGS6YJV.mjs → BlockNoteViewer-NBW2H6LC.mjs} +7 -4
  10. package/dist/{BlockNoteViewer-MTGS6YJV.mjs.map → BlockNoteViewer-NBW2H6LC.mjs.map} +1 -1
  11. package/dist/{JsonApiRequest-A66XK5WT.mjs → JsonApiRequest-F6TMJ42G.mjs} +2 -2
  12. package/dist/JsonApiRequest-WISJZSDE.js +26 -0
  13. package/dist/{JsonApiRequest-FZGPLNUF.js.map → JsonApiRequest-WISJZSDE.js.map} +1 -1
  14. package/dist/billing/index.js +499 -494
  15. package/dist/billing/index.js.map +1 -1
  16. package/dist/billing/index.mjs +13 -8
  17. package/dist/billing/index.mjs.map +1 -1
  18. package/dist/chunk-27LQDGNP.mjs +317 -0
  19. package/dist/chunk-27LQDGNP.mjs.map +1 -0
  20. package/dist/{chunk-KSYQEKJX.js → chunk-2SV4SS6N.js} +14 -14
  21. package/dist/{chunk-KSYQEKJX.js.map → chunk-2SV4SS6N.js.map} +1 -1
  22. package/dist/{chunk-4FNGWALA.mjs → chunk-47BBY5KA.mjs} +6 -4
  23. package/dist/{chunk-4FNGWALA.mjs.map → chunk-47BBY5KA.mjs.map} +1 -1
  24. package/dist/chunk-6JUCIWDC.mjs +570 -0
  25. package/dist/chunk-6JUCIWDC.mjs.map +1 -0
  26. package/dist/chunk-7DBJTNSU.mjs +1049 -0
  27. package/dist/chunk-7DBJTNSU.mjs.map +1 -0
  28. package/dist/chunk-7JZHPMGW.mjs +704 -0
  29. package/dist/chunk-7JZHPMGW.mjs.map +1 -0
  30. package/dist/{chunk-L6PYFQTO.js → chunk-7ZHTPFFT.js} +16 -14
  31. package/dist/chunk-7ZHTPFFT.js.map +1 -0
  32. package/dist/chunk-B6JGKDP2.js +214 -0
  33. package/dist/chunk-B6JGKDP2.js.map +1 -0
  34. package/dist/{chunk-3YW35YHQ.mjs → chunk-BH6JWIKI.mjs} +5 -5
  35. package/dist/chunk-BZ5J2FIV.js +570 -0
  36. package/dist/chunk-BZ5J2FIV.js.map +1 -0
  37. package/dist/{chunk-V5MI7RNB.mjs → chunk-DGWOVYEC.mjs} +2 -2
  38. package/dist/chunk-DOCIFE6A.mjs +212 -0
  39. package/dist/chunk-DOCIFE6A.mjs.map +1 -0
  40. package/dist/chunk-GB6DBFYY.js +25 -0
  41. package/dist/chunk-GB6DBFYY.js.map +1 -0
  42. package/dist/{chunk-EWCY6QJA.mjs → chunk-JJMMT24D.mjs} +37 -3
  43. package/dist/chunk-JJMMT24D.mjs.map +1 -0
  44. package/dist/{chunk-JTPRJNT2.js → chunk-KMW7UNL2.js} +38 -3
  45. package/dist/chunk-KMW7UNL2.js.map +1 -0
  46. package/dist/chunk-MHB36MYE.js +317 -0
  47. package/dist/chunk-MHB36MYE.js.map +1 -0
  48. package/dist/{chunk-FF4EIQ6H.js → chunk-MOGEGWXW.js} +1039 -1680
  49. package/dist/chunk-MOGEGWXW.js.map +1 -0
  50. package/dist/{chunk-RXQYEEKZ.mjs → chunk-N4RZZKL5.mjs} +58 -25
  51. package/dist/chunk-N4RZZKL5.mjs.map +1 -0
  52. package/dist/{chunk-AA52ORW2.mjs → chunk-P445QGOC.mjs} +61 -702
  53. package/dist/chunk-P445QGOC.mjs.map +1 -0
  54. package/dist/chunk-PV4Z5W6V.js +212 -0
  55. package/dist/chunk-PV4Z5W6V.js.map +1 -0
  56. package/dist/chunk-PXDUJ47N.js +1049 -0
  57. package/dist/chunk-PXDUJ47N.js.map +1 -0
  58. package/dist/{chunk-V3YDVJ63.js → chunk-PYRZCKC2.js} +1209 -1176
  59. package/dist/chunk-PYRZCKC2.js.map +1 -0
  60. package/dist/{chunk-GHE4VT2R.js → chunk-QKNGZDSQ.js} +2 -2
  61. package/dist/{chunk-GHE4VT2R.js.map → chunk-QKNGZDSQ.js.map} +1 -1
  62. package/dist/chunk-W62MHDWM.js +704 -0
  63. package/dist/chunk-W62MHDWM.js.map +1 -0
  64. package/dist/chunk-XXP3TQHF.mjs +25 -0
  65. package/dist/chunk-XXP3TQHF.mjs.map +1 -0
  66. package/dist/chunk-YRKIFYOE.mjs +214 -0
  67. package/dist/chunk-YRKIFYOE.mjs.map +1 -0
  68. package/dist/{chunk-O3PDL2CV.js → chunk-Z4POQWFG.js} +40 -6
  69. package/dist/chunk-Z4POQWFG.js.map +1 -0
  70. package/dist/{chunk-PI56A4DG.mjs → chunk-ZLTOUZN2.mjs} +37 -2
  71. package/dist/chunk-ZLTOUZN2.mjs.map +1 -0
  72. package/dist/client/index.d.mts +2 -2
  73. package/dist/client/index.d.ts +2 -2
  74. package/dist/client/index.js +14 -9
  75. package/dist/client/index.js.map +1 -1
  76. package/dist/client/index.mjs +24 -19
  77. package/dist/components/index.d.mts +7 -1
  78. package/dist/components/index.d.ts +7 -1
  79. package/dist/components/index.js +11 -7
  80. package/dist/components/index.js.map +1 -1
  81. package/dist/components/index.mjs +10 -6
  82. package/dist/contexts/index.d.mts +1 -1
  83. package/dist/contexts/index.d.ts +1 -1
  84. package/dist/contexts/index.js +11 -7
  85. package/dist/contexts/index.js.map +1 -1
  86. package/dist/contexts/index.mjs +10 -6
  87. package/dist/core/index.d.mts +128 -2
  88. package/dist/core/index.d.ts +128 -2
  89. package/dist/core/index.js +17 -4
  90. package/dist/core/index.js.map +1 -1
  91. package/dist/core/index.mjs +22 -9
  92. package/dist/email-automations/index.js +101 -96
  93. package/dist/email-automations/index.js.map +1 -1
  94. package/dist/email-automations/index.mjs +13 -8
  95. package/dist/email-automations/index.mjs.map +1 -1
  96. package/dist/features/analytics/index.js +128 -123
  97. package/dist/features/analytics/index.js.map +1 -1
  98. package/dist/features/analytics/index.mjs +13 -8
  99. package/dist/features/analytics/index.mjs.map +1 -1
  100. package/dist/features/analytics/server.js +11 -8
  101. package/dist/features/analytics/server.js.map +1 -1
  102. package/dist/features/analytics/server.mjs +9 -6
  103. package/dist/features/analytics/server.mjs.map +1 -1
  104. package/dist/features/blog/index.js +158 -153
  105. package/dist/features/blog/index.js.map +1 -1
  106. package/dist/features/blog/index.mjs +14 -9
  107. package/dist/features/blog/index.mjs.map +1 -1
  108. package/dist/features/blog/server.js +30 -26
  109. package/dist/features/blog/server.js.map +1 -1
  110. package/dist/features/blog/server.mjs +10 -6
  111. package/dist/features/blog/server.mjs.map +1 -1
  112. package/dist/features/help/index.js +44 -40
  113. package/dist/features/help/index.js.map +1 -1
  114. package/dist/features/help/index.mjs +10 -6
  115. package/dist/features/help/index.mjs.map +1 -1
  116. package/dist/features/tokenusage/index.js +134 -129
  117. package/dist/features/tokenusage/index.js.map +1 -1
  118. package/dist/features/tokenusage/index.mjs +13 -8
  119. package/dist/features/tokenusage/index.mjs.map +1 -1
  120. package/dist/index.d.mts +2 -2
  121. package/dist/index.d.ts +2 -2
  122. package/dist/index.js +18 -5
  123. package/dist/index.js.map +1 -1
  124. package/dist/index.mjs +24 -11
  125. package/dist/lifecycle-4GUOTB46.js +23 -0
  126. package/dist/lifecycle-4GUOTB46.js.map +1 -0
  127. package/dist/lifecycle-LKGPRBS7.mjs +23 -0
  128. package/dist/local-transport-7H3SPZSA.js +15 -0
  129. package/dist/local-transport-7H3SPZSA.js.map +1 -0
  130. package/dist/local-transport-QYFKA6AN.mjs +15 -0
  131. package/dist/local-transport-QYFKA6AN.mjs.map +1 -0
  132. package/dist/offline/index.d.mts +607 -0
  133. package/dist/offline/index.d.ts +607 -0
  134. package/dist/offline/index.js +1052 -0
  135. package/dist/offline/index.js.map +1 -0
  136. package/dist/offline/index.mjs +1052 -0
  137. package/dist/offline/index.mjs.map +1 -0
  138. package/dist/offline/sqlite/device-worker.mjs +62 -0
  139. package/dist/offline/sqlite/index.mjs +17392 -0
  140. package/dist/offline/sqlite/sqlite3-opfs-async-proxy.js +881 -0
  141. package/dist/offline/sqlite/sqlite3.wasm +0 -0
  142. package/dist/request-KTBV6HHH.js +10 -0
  143. package/dist/request-KTBV6HHH.js.map +1 -0
  144. package/dist/request-SQOUNWZ4.mjs +10 -0
  145. package/dist/request-SQOUNWZ4.mjs.map +1 -0
  146. package/dist/server/cachedGet.d.mts +1 -1
  147. package/dist/server/cachedGet.d.ts +1 -1
  148. package/dist/server/cachedGet.stub.d.mts +1 -1
  149. package/dist/server/cachedGet.stub.d.ts +1 -1
  150. package/dist/server/index.d.mts +28 -2
  151. package/dist/server/index.d.ts +28 -2
  152. package/dist/server/index.js +18 -8
  153. package/dist/server/index.js.map +1 -1
  154. package/dist/server/index.mjs +18 -8
  155. package/dist/{useSocket-IRHtk2xc.d.ts → useSocket-Bo9M0t0J.d.ts} +3 -1
  156. package/dist/{useSocket-C8fqU4od.d.mts → useSocket-J5qanQPN.d.mts} +3 -1
  157. package/dist/write-through-FDQ7N4YI.js +15 -0
  158. package/dist/write-through-FDQ7N4YI.js.map +1 -0
  159. package/dist/write-through-R25VQMH6.mjs +15 -0
  160. package/dist/write-through-R25VQMH6.mjs.map +1 -0
  161. package/package.json +7 -1
  162. package/pwa/sw.js +277 -26
  163. package/src/client/request.ts +37 -0
  164. package/src/components/editors/BlockNoteEditor.tsx +14 -0
  165. package/src/components/editors/__tests__/BlockNoteEditor.empty-change.spec.tsx +205 -0
  166. package/src/contexts/SocketContext.tsx +7 -1
  167. package/src/contexts/__tests__/SocketContext.session.spec.tsx +52 -5
  168. package/src/core/factories/RehydrationFactory.ts +28 -8
  169. package/src/core/factories/__tests__/RehydrationFactory.spec.ts +33 -0
  170. package/src/core/index.ts +3 -0
  171. package/src/core/interfaces/ApiData.ts +2 -0
  172. package/src/core/registry/ModuleRegistry.ts +3 -0
  173. package/src/features/auth/components/forms/Logout.tsx +8 -1
  174. package/src/features/auth/components/forms/__tests__/Logout.spec.tsx +62 -0
  175. package/src/features/onboarding/contexts/OnboardingContext.spec.tsx +42 -1
  176. package/src/features/onboarding/contexts/OnboardingContext.tsx +11 -1
  177. package/src/hooks/__tests__/useSocket.pause.spec.ts +39 -0
  178. package/src/hooks/useSocket.ts +20 -1
  179. package/src/offline/__tests__/answer-builders.spec.ts +176 -0
  180. package/src/offline/__tests__/device-switch.spec.ts +179 -0
  181. package/src/offline/__tests__/generic-answers.spec.ts +380 -0
  182. package/src/offline/__tests__/local-transport.spec.ts +150 -0
  183. package/src/offline/__tests__/logout.spec.ts +122 -0
  184. package/src/offline/__tests__/offline-fixtures.ts +89 -0
  185. package/src/offline/__tests__/router.spec.ts +56 -0
  186. package/src/offline/__tests__/state.spec.ts +62 -0
  187. package/src/offline/__tests__/write-through.spec.ts +137 -0
  188. package/src/offline/config.ts +229 -0
  189. package/src/offline/configure.ts +14 -0
  190. package/src/offline/device-switch.ts +75 -0
  191. package/src/offline/generic-answers.ts +706 -0
  192. package/src/offline/index.ts +67 -0
  193. package/src/offline/local-transport.ts +189 -0
  194. package/src/offline/logout.ts +41 -0
  195. package/src/offline/router.ts +41 -0
  196. package/src/offline/server/__tests__/build-offline-manifest.spec.ts +76 -0
  197. package/src/offline/server/build-offline-manifest.ts +49 -0
  198. package/src/offline/state-hooks.ts +10 -0
  199. package/src/offline/state.ts +143 -0
  200. package/src/offline/store/DeviceStore.ts +112 -0
  201. package/src/offline/store/__tests__/device-store-lifecycle.spec.ts +343 -0
  202. package/src/offline/store/__tests__/shared-database.spec.ts +151 -0
  203. package/src/offline/store/__tests__/sql-device-store.spec.ts +399 -0
  204. package/src/offline/store/lifecycle.ts +315 -0
  205. package/src/offline/store/schema.ts +101 -0
  206. package/src/offline/store/shared-database.ts +321 -0
  207. package/src/offline/store/sql-device-store.ts +469 -0
  208. package/src/offline/store/worker-client.ts +71 -0
  209. package/src/offline/store/worker.ts +87 -0
  210. package/src/offline/sync/__tests__/conflicts.spec.ts +185 -0
  211. package/src/offline/sync/__tests__/queue-drain.spec.ts +364 -0
  212. package/src/offline/sync/__tests__/runtime.spec.ts +337 -0
  213. package/src/offline/sync/__tests__/sync-fixtures.ts +103 -0
  214. package/src/offline/sync/__tests__/sync-root.spec.ts +727 -0
  215. package/src/offline/sync/artwork-cache.ts +67 -0
  216. package/src/offline/sync/conflicts.ts +211 -0
  217. package/src/offline/sync/counts.ts +39 -0
  218. package/src/offline/sync/drain-queue.ts +246 -0
  219. package/src/offline/sync/known-roots.ts +37 -0
  220. package/src/offline/sync/models/OfflineChangeSet.ts +34 -0
  221. package/src/offline/sync/models/OfflineChangeSetInterface.ts +54 -0
  222. package/src/offline/sync/models/RootSync.ts +68 -0
  223. package/src/offline/sync/models/RootSyncInterface.ts +20 -0
  224. package/src/offline/sync/models/__tests__/OfflineChangeSet.spec.ts +47 -0
  225. package/src/offline/sync/models/__tests__/RootSync.spec.ts +54 -0
  226. package/src/offline/sync/models/index.ts +5 -0
  227. package/src/offline/sync/models/offline.modules.ts +14 -0
  228. package/src/offline/sync/runtime.ts +226 -0
  229. package/src/offline/sync/session-refresh.ts +32 -0
  230. package/src/offline/sync/sync-root.ts +336 -0
  231. package/src/offline/sync/waiting.ts +40 -0
  232. package/src/offline/types.ts +115 -0
  233. package/src/offline/write-through.ts +189 -0
  234. package/src/pwa/__tests__/sw.spec.ts +358 -1
  235. package/src/server/index.ts +5 -0
  236. package/src/unified/__tests__/JsonApiRequest.offline.spec.ts +243 -0
  237. package/dist/BlockNoteEditor-75ED2CN2.mjs.map +0 -1
  238. package/dist/BlockNoteEditor-7M5QW2YQ.js.map +0 -1
  239. package/dist/BlockNoteViewer-WGCDB7IJ.js.map +0 -1
  240. package/dist/JsonApiRequest-FZGPLNUF.js +0 -26
  241. package/dist/chunk-AA52ORW2.mjs.map +0 -1
  242. package/dist/chunk-EWCY6QJA.mjs.map +0 -1
  243. package/dist/chunk-FF4EIQ6H.js.map +0 -1
  244. package/dist/chunk-JTPRJNT2.js.map +0 -1
  245. package/dist/chunk-L6PYFQTO.js.map +0 -1
  246. package/dist/chunk-O3PDL2CV.js.map +0 -1
  247. package/dist/chunk-PI56A4DG.mjs.map +0 -1
  248. package/dist/chunk-RXQYEEKZ.mjs.map +0 -1
  249. package/dist/chunk-V3YDVJ63.js.map +0 -1
  250. package/dist/request-5RLK2AM3.mjs +0 -9
  251. package/dist/request-EUGTI3BE.js +0 -9
  252. package/dist/request-EUGTI3BE.js.map +0 -1
  253. /package/dist/{JsonApiRequest-A66XK5WT.mjs.map → JsonApiRequest-F6TMJ42G.mjs.map} +0 -0
  254. /package/dist/{chunk-3YW35YHQ.mjs.map → chunk-BH6JWIKI.mjs.map} +0 -0
  255. /package/dist/{chunk-V5MI7RNB.mjs.map → chunk-DGWOVYEC.mjs.map} +0 -0
  256. /package/dist/{request-5RLK2AM3.mjs.map → lifecycle-LKGPRBS7.mjs.map} +0 -0
@@ -0,0 +1,1052 @@
1
+ "use client";
2
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+ var _chunkB6JGKDP2js = require('../chunk-B6JGKDP2.js');
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+ var _chunkPXDUJ47Njs = require('../chunk-PXDUJ47N.js');
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+ var _chunkW62MHDWMjs = require('../chunk-W62MHDWM.js');
44
+
45
+
46
+
47
+ var _chunkGB6DBFYYjs = require('../chunk-GB6DBFYY.js');
48
+
49
+
50
+
51
+
52
+
53
+
54
+ var _chunkBZ5J2FIVjs = require('../chunk-BZ5J2FIV.js');
55
+ require('../chunk-PV4Z5W6V.js');
56
+
57
+
58
+ var _chunkKMW7UNL2js = require('../chunk-KMW7UNL2.js');
59
+
60
+
61
+
62
+
63
+
64
+
65
+
66
+
67
+
68
+
69
+
70
+
71
+
72
+
73
+
74
+
75
+
76
+
77
+
78
+
79
+
80
+
81
+
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+ var _chunkMHB36MYEjs = require('../chunk-MHB36MYE.js');
90
+
91
+
92
+
93
+
94
+ var _chunkQKNGZDSQjs = require('../chunk-QKNGZDSQ.js');
95
+
96
+
97
+ var _chunkLXKSUWAVjs = require('../chunk-LXKSUWAV.js');
98
+
99
+
100
+ var _chunk7QVYU63Ejs = require('../chunk-7QVYU63E.js');
101
+
102
+ // src/offline/configure.ts
103
+ function configureOffline2(config) {
104
+ _chunkMHB36MYEjs.setDefaultDeviceStoreOpener.call(void 0,
105
+ (userId) => Promise.resolve().then(() => _interopRequireWildcard(require("../lifecycle-4GUOTB46.js"))).then((lifecycle) => lifecycle.openDeviceStore(userId))
106
+ );
107
+ _chunkMHB36MYEjs.configureOffline.call(void 0, config);
108
+ }
109
+ _chunk7QVYU63Ejs.__name.call(void 0, configureOffline2, "configureOffline");
110
+
111
+ // src/offline/sync/session-refresh.ts
112
+ var _cookiesnext = require('cookies-next');
113
+ function currentLocale() {
114
+ if (typeof window === "undefined") return _chunkBZ5J2FIVjs.getI18nDefaultLocale.call(void 0, );
115
+ const first = window.location.pathname.split("/").filter(Boolean)[0];
116
+ return first && _chunkBZ5J2FIVjs.getI18nSupportedLocales.call(void 0, ).includes(first) ? first : _chunkBZ5J2FIVjs.getI18nDefaultLocale.call(void 0, );
117
+ }
118
+ _chunk7QVYU63Ejs.__name.call(void 0, currentLocale, "currentLocale");
119
+ async function refreshSession() {
120
+ try {
121
+ await fetch(_chunkMHB36MYEjs.getOfflineConfig.call(void 0, ).shellPath(currentLocale()), { cache: "no-store", credentials: "same-origin" });
122
+ } catch (e) {
123
+ return "unreachable";
124
+ }
125
+ const token = await _cookiesnext.getCookie.call(void 0, "token");
126
+ return token ? "ok" : "expired";
127
+ }
128
+ _chunk7QVYU63Ejs.__name.call(void 0, refreshSession, "refreshSession");
129
+
130
+ // src/offline/sync/sync-root.ts
131
+ var SyncInterruptedError = class extends Error {
132
+ static {
133
+ _chunk7QVYU63Ejs.__name.call(void 0, this, "SyncInterruptedError");
134
+ }
135
+ };
136
+ function assertStillOnline() {
137
+ if (!_chunkMHB36MYEjs.canReachApi.call(void 0, )) throw new SyncInterruptedError("The connection dropped during the sync");
138
+ }
139
+ _chunk7QVYU63Ejs.__name.call(void 0, assertStillOnline, "assertStillOnline");
140
+ var isSkippable = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, (status) => status === 403 || status === 404, "isSkippable");
141
+ async function fetchResources(module, endpoint, skipped, included) {
142
+ const response = await _chunkQKNGZDSQjs.JsonApiGet.call(void 0, { classKey: module, endpoint, language: currentLocale() });
143
+ assertStillOnline();
144
+ if (!response.ok) {
145
+ if (isSkippable(response.response)) {
146
+ skipped.push(endpoint);
147
+ return [];
148
+ }
149
+ throw new Error(`[offline] GET ${endpoint} answered ${response.response}`);
150
+ }
151
+ included.push(..._nullishCoalesce(_optionalChain([response, 'access', _ => _.raw, 'optionalAccess', _2 => _2.included]), () => ( [])));
152
+ const data = _optionalChain([response, 'access', _3 => _3.raw, 'optionalAccess', _4 => _4.data]);
153
+ if (!data) return [];
154
+ return Array.isArray(data) ? data : [data];
155
+ }
156
+ _chunk7QVYU63Ejs.__name.call(void 0, fetchResources, "fetchResources");
157
+ async function imagesOfRoot(store, rootId) {
158
+ const images = [];
159
+ for (const typeConfig of _chunkMHB36MYEjs.getOfflineConfig.call(void 0, ).types) {
160
+ for (const record of await store.listRecords({ type: typeConfig.module.name, rootId })) {
161
+ const url = _chunkPXDUJ47Njs.imageUrlOf.call(void 0, record.resource);
162
+ if (url) images.push({ type: record.type, id: record.id, url });
163
+ }
164
+ }
165
+ return images;
166
+ }
167
+ _chunk7QVYU63Ejs.__name.call(void 0, imagesOfRoot, "imagesOfRoot");
168
+ async function removeRootIfIdle(store, rootId) {
169
+ if ((await store.queue()).some((entry) => entry.rootId === rootId)) return;
170
+ const images = await imagesOfRoot(store, rootId);
171
+ await store.removeRoot(rootId);
172
+ for (const image of images) {
173
+ if (!await store.getRecord(image.type, image.id)) await _chunkPXDUJ47Njs.removeArtworkImage.call(void 0, image.url);
174
+ }
175
+ }
176
+ _chunk7QVYU63Ejs.__name.call(void 0, removeRootIfIdle, "removeRootIfIdle");
177
+ async function syncRoot(rootId) {
178
+ const config = _chunkMHB36MYEjs.getOfflineConfig.call(void 0, );
179
+ const store = await _chunkMHB36MYEjs.getOfflineStore.call(void 0, );
180
+ const previous = await store.getSyncState(rootId);
181
+ const syncEndpoint = new (0, _chunkBZ5J2FIVjs.EndpointCreator)({
182
+ endpoint: config.rootModule,
183
+ id: rootId,
184
+ childEndpoint: _chunkBZ5J2FIVjs.ROOT_SYNC_ENDPOINT
185
+ }).generate();
186
+ const syncResponse = await _chunkQKNGZDSQjs.JsonApiGet.call(void 0, {
187
+ classKey: _chunkBZ5J2FIVjs.Modules.RootSync,
188
+ endpoint: syncEndpoint,
189
+ language: currentLocale()
190
+ });
191
+ assertStillOnline();
192
+ if (!syncResponse.ok) {
193
+ if (isSkippable(syncResponse.response)) {
194
+ await removeRootIfIdle(store, rootId);
195
+ return;
196
+ }
197
+ throw new Error(`[offline] GET ${syncEndpoint} answered ${syncResponse.response}`);
198
+ }
199
+ const sync = syncResponse.data;
200
+ if (sync.locked) {
201
+ await store.setSyncState(rootId, {
202
+ serverTime: previous.serverTime,
203
+ locked: true,
204
+ lockedFrom: _nullishCoalesce(sync.lockedFrom, () => ( null))
205
+ });
206
+ await _chunkB6JGKDP2js.refreshLockedRoots.call(void 0, );
207
+ return;
208
+ }
209
+ const typeNames = new Set(config.types.map((typeConfig) => typeConfig.module.name));
210
+ const entries = sync.entries.filter((entry) => typeNames.has(entry.type));
211
+ const entryUpdatedAt = new Map(entries.map((entry) => [_chunkB6JGKDP2js.recordKeyOf.call(void 0, entry.type, entry.id), entry.updatedAt]));
212
+ const since = previous.serverTime;
213
+ const inWindow = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, (entry) => !since || entry.updatedAt.getTime() > since.getTime(), "inWindow");
214
+ const stored = /* @__PURE__ */ new Map();
215
+ for (const typeConfig of config.types) {
216
+ for (const record of await store.listRecords({ type: typeConfig.module.name, rootId })) {
217
+ stored.set(_chunkB6JGKDP2js.recordKeyOf.call(void 0, record.type, record.id), record);
218
+ }
219
+ }
220
+ const previouslySkipped = new Map(
221
+ (await store.skippedRecords(rootId)).map((record) => [_chunkB6JGKDP2js.recordKeyOf.call(void 0, record.type, record.id), record.updatedAt])
222
+ );
223
+ const isStale = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, (entry) => {
224
+ const key = _chunkB6JGKDP2js.recordKeyOf.call(void 0, entry.type, entry.id);
225
+ const record = stored.get(key);
226
+ if (record && record.updatedAt !== null) return false;
227
+ const skippedAt = previouslySkipped.get(key);
228
+ return !skippedAt || entry.updatedAt.getTime() > skippedAt.getTime();
229
+ }, "isStale");
230
+ const changed = entries.filter((entry) => inWindow(entry) || isStale(entry));
231
+ const skipped = [];
232
+ const fetched = [];
233
+ const included = [];
234
+ for (const typeConfig of config.types) {
235
+ const changedOfType = changed.filter((entry) => entry.type === typeConfig.module.name);
236
+ if (changedOfType.length === 0) continue;
237
+ if (typeConfig.fetch === "root-list") {
238
+ const endpoint = new (0, _chunkBZ5J2FIVjs.EndpointCreator)({
239
+ endpoint: config.rootModule,
240
+ id: rootId,
241
+ childEndpoint: typeConfig.module
242
+ }).addAdditionalParam("fetchAll", "true");
243
+ if (since && changedOfType.every(inWindow)) endpoint.addAdditionalParam("updatedSince", since.toISOString());
244
+ fetched.push(...await fetchResources(typeConfig.module, endpoint.generate(), skipped, included));
245
+ } else if (typeConfig.fetch === "linked-list") {
246
+ if (!typeConfig.linkedList) throw new Error(`[offline] ${typeConfig.module.name}: linked-list needs linkedList`);
247
+ const { linkKind, endpoint } = typeConfig.linkedList;
248
+ const changedIds = new Set(changedOfType.map((entry) => entry.id));
249
+ const targets = /* @__PURE__ */ new Map();
250
+ for (const link of sync.links) {
251
+ if (link.kind !== linkKind || link.fromType !== typeConfig.module.name || !changedIds.has(link.fromId))
252
+ continue;
253
+ targets.set(_chunkB6JGKDP2js.recordKeyOf.call(void 0, link.toType, link.toId), { type: link.toType, id: link.toId });
254
+ }
255
+ for (const target of targets.values()) {
256
+ const resources = await fetchResources(typeConfig.module, endpoint(rootId, target), skipped, included);
257
+ fetched.push(
258
+ ...resources.filter((resource) => _optionalChain([resource, 'optionalAccess', _5 => _5.type]) === typeConfig.module.name && changedIds.has(resource.id))
259
+ );
260
+ }
261
+ } else {
262
+ for (const entry of changedOfType) {
263
+ const endpoint = new (0, _chunkBZ5J2FIVjs.EndpointCreator)({ endpoint: typeConfig.module, id: entry.id }).generate();
264
+ fetched.push(...await fetchResources(typeConfig.module, endpoint, skipped, included));
265
+ }
266
+ }
267
+ }
268
+ const fetchedKeys = new Set(fetched.map((resource) => _chunkB6JGKDP2js.recordKeyOf.call(void 0, _optionalChain([resource, 'optionalAccess', _6 => _6.type]), _optionalChain([resource, 'optionalAccess', _7 => _7.id]))));
269
+ const previousImageUrls = /* @__PURE__ */ new Map();
270
+ const removedImageUrls = [];
271
+ await store.transaction(async (tx) => {
272
+ const waiting = _chunkB6JGKDP2js.waitingRecordKeys.call(void 0, await tx.queue(), typeNames);
273
+ for (const typeConfig of config.types) {
274
+ for (const record of await tx.listRecords({ type: typeConfig.module.name, rootId })) {
275
+ const key = _chunkB6JGKDP2js.recordKeyOf.call(void 0, record.type, record.id);
276
+ if (waiting.has(key)) {
277
+ if (record.updatedAt !== null) await tx.putRecord({ ...record, updatedAt: null });
278
+ continue;
279
+ }
280
+ if (entryUpdatedAt.has(key)) continue;
281
+ await tx.removeRecordFromRoot(record.type, record.id, rootId);
282
+ const url = _chunkPXDUJ47Njs.imageUrlOf.call(void 0, record.resource);
283
+ if (url && !await tx.getRecord(record.type, record.id)) removedImageUrls.push(url);
284
+ }
285
+ }
286
+ for (const resource of fetched) {
287
+ const key = _chunkB6JGKDP2js.recordKeyOf.call(void 0, _optionalChain([resource, 'optionalAccess', _8 => _8.type]), _optionalChain([resource, 'optionalAccess', _9 => _9.id]));
288
+ if (!entryUpdatedAt.has(key)) continue;
289
+ if (waiting.has(key)) continue;
290
+ const existing = await tx.getRecord(resource.type, resource.id);
291
+ const previousUrl = _chunkPXDUJ47Njs.imageUrlOf.call(void 0, _optionalChain([existing, 'optionalAccess', _10 => _10.resource]));
292
+ if (previousUrl) previousImageUrls.set(key, previousUrl);
293
+ await tx.putRecord({
294
+ type: resource.type,
295
+ id: resource.id,
296
+ rootId,
297
+ resource,
298
+ updatedAt: _nullishCoalesce(entryUpdatedAt.get(key), () => ( null)),
299
+ base: null,
300
+ localOnly: false
301
+ });
302
+ }
303
+ for (const resource of included) {
304
+ if (!_optionalChain([resource, 'optionalAccess', _11 => _11.type]) || !_optionalChain([resource, 'optionalAccess', _12 => _12.id]) || typeNames.has(resource.type)) continue;
305
+ await tx.putRecord({
306
+ type: resource.type,
307
+ id: resource.id,
308
+ rootId,
309
+ resource,
310
+ updatedAt: null,
311
+ base: null,
312
+ localOnly: false
313
+ });
314
+ }
315
+ const skippedRecords = [];
316
+ const changedKeys = new Set(changed.map((entry) => _chunkB6JGKDP2js.recordKeyOf.call(void 0, entry.type, entry.id)));
317
+ for (const entry of entries) {
318
+ const key = _chunkB6JGKDP2js.recordKeyOf.call(void 0, entry.type, entry.id);
319
+ if (waiting.has(key) || fetchedKeys.has(key)) continue;
320
+ if (changedKeys.has(key)) skippedRecords.push({ type: entry.type, id: entry.id, updatedAt: entry.updatedAt });
321
+ else {
322
+ const skippedAt = previouslySkipped.get(key);
323
+ if (skippedAt) skippedRecords.push({ type: entry.type, id: entry.id, updatedAt: skippedAt });
324
+ }
325
+ }
326
+ await tx.setSkippedRecords(rootId, skippedRecords);
327
+ await tx.replaceRootLinks(rootId, sync.links);
328
+ await tx.setSyncState(rootId, {
329
+ serverTime: sync.serverTime,
330
+ locked: false,
331
+ lockedFrom: _nullishCoalesce(sync.lockedFrom, () => ( null))
332
+ });
333
+ });
334
+ if (skipped.length > 0) {
335
+ console.warn(`[offline] root record ${rootId}: skipped records the GM cannot read:`, skipped.join(", "));
336
+ }
337
+ for (const url of removedImageUrls) await _chunkPXDUJ47Njs.removeArtworkImage.call(void 0, url);
338
+ for (const typeConfig of config.types) {
339
+ for (const record of await store.listRecords({ type: typeConfig.module.name, rootId })) {
340
+ const url = _chunkPXDUJ47Njs.imageUrlOf.call(void 0, record.resource);
341
+ if (url) await _chunkPXDUJ47Njs.cacheArtworkImage.call(void 0, url, previousImageUrls.get(_chunkB6JGKDP2js.recordKeyOf.call(void 0, record.type, record.id)));
342
+ }
343
+ }
344
+ await _chunkB6JGKDP2js.refreshLockedRoots.call(void 0, );
345
+ }
346
+ _chunk7QVYU63Ejs.__name.call(void 0, syncRoot, "syncRoot");
347
+ async function syncAll() {
348
+ if (!_chunkMHB36MYEjs.isOfflineConfigured.call(void 0, )) return;
349
+ const config = _chunkMHB36MYEjs.getOfflineConfig.call(void 0, );
350
+ if (!config.getUserId() || !_chunkMHB36MYEjs.canReachApi.call(void 0, )) return;
351
+ let roots;
352
+ try {
353
+ roots = await config.listSyncRoots();
354
+ } catch (error) {
355
+ console.warn("[offline] could not list the root records to sync", error);
356
+ return;
357
+ }
358
+ if (!_chunkMHB36MYEjs.canReachApi.call(void 0, )) return;
359
+ _chunkB6JGKDP2js.rememberSyncRoots.call(void 0, roots);
360
+ const total = roots.length;
361
+ _chunkMHB36MYEjs.setOfflineState.call(void 0, { syncProgress: { done: 0, total } });
362
+ try {
363
+ let done = 0;
364
+ for (const rootId of roots) {
365
+ try {
366
+ await syncRoot(rootId);
367
+ } catch (error) {
368
+ console.warn(`[offline] sync of root record ${rootId} failed`, error);
369
+ if (!_chunkMHB36MYEjs.canReachApi.call(void 0, )) return;
370
+ } finally {
371
+ done += 1;
372
+ _chunkMHB36MYEjs.setOfflineState.call(void 0, { syncProgress: { done, total } });
373
+ }
374
+ }
375
+ const finishedAt = Date.now();
376
+ const userId = config.getUserId();
377
+ if (userId) _chunkMHB36MYEjs.writeOfflineLastSync.call(void 0, userId, finishedAt);
378
+ _chunkMHB36MYEjs.setOfflineState.call(void 0, { lastSyncedAt: finishedAt, rootCount: total });
379
+ const store = await _chunkMHB36MYEjs.getOfflineStore.call(void 0, );
380
+ const rootSet = new Set(roots);
381
+ for (const rootId of await _chunkB6JGKDP2js.knownRootIds.call(void 0, store)) {
382
+ if (!rootSet.has(rootId)) await removeRootIfIdle(store, rootId);
383
+ }
384
+ await _chunkB6JGKDP2js.refreshLockedRoots.call(void 0, );
385
+ } finally {
386
+ _chunkMHB36MYEjs.setOfflineState.call(void 0, { syncProgress: null });
387
+ }
388
+ }
389
+ _chunk7QVYU63Ejs.__name.call(void 0, syncAll, "syncAll");
390
+
391
+ // src/offline/sync/counts.ts
392
+ var _react = require('react');
393
+ var EMPTY = [];
394
+ var _conflicts = EMPTY;
395
+ var _listeners = /* @__PURE__ */ new Set();
396
+ function subscribe(listener) {
397
+ _listeners.add(listener);
398
+ return () => {
399
+ _listeners.delete(listener);
400
+ };
401
+ }
402
+ _chunk7QVYU63Ejs.__name.call(void 0, subscribe, "subscribe");
403
+ async function refreshOfflineCounts(store) {
404
+ if (!store) {
405
+ if (!_chunkMHB36MYEjs.isOfflineConfigured.call(void 0, ) || !_chunkMHB36MYEjs.getOfflineConfig.call(void 0, ).getUserId()) return;
406
+ store = await _chunkMHB36MYEjs.getOfflineStore.call(void 0, );
407
+ }
408
+ const entries = await store.queue();
409
+ _conflicts = await store.conflicts();
410
+ for (const listener of [..._listeners]) listener();
411
+ _chunkMHB36MYEjs.setOfflineState.call(void 0, {
412
+ pending: entries.filter((entry) => entry.status !== "conflict").length,
413
+ conflicts: _conflicts.length
414
+ });
415
+ }
416
+ _chunk7QVYU63Ejs.__name.call(void 0, refreshOfflineCounts, "refreshOfflineCounts");
417
+ function useConflicts() {
418
+ return _react.useSyncExternalStore.call(void 0,
419
+ subscribe,
420
+ () => _conflicts,
421
+ () => EMPTY
422
+ );
423
+ }
424
+ _chunk7QVYU63Ejs.__name.call(void 0, useConflicts, "useConflicts");
425
+
426
+ // src/offline/sync/drain-queue.ts
427
+ var syncedTypeNames = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, () => new Set(_chunkMHB36MYEjs.getOfflineConfig.call(void 0, ).types.map((typeConfig) => typeConfig.module.name)), "syncedTypeNames");
428
+ function withoutServerOwnedFields(body) {
429
+ const data = _optionalChain([body, 'optionalAccess', _13 => _13.data]);
430
+ if (!data) return body;
431
+ const owned = new Map(
432
+ _chunkMHB36MYEjs.getOfflineConfig.call(void 0, ).types.map((typeConfig) => [typeConfig.module.name, typeConfig.serverOwnedFields])
433
+ );
434
+ const strip = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, (resource) => {
435
+ const fields = _nullishCoalesce(owned.get(_optionalChain([resource, 'optionalAccess', _14 => _14.type])), () => ( []));
436
+ if (!_optionalChain([resource, 'optionalAccess', _15 => _15.attributes]) || fields.length === 0) return resource;
437
+ const attributes = { ...resource.attributes };
438
+ for (const field of fields) delete attributes[field];
439
+ return { ...resource, attributes };
440
+ }, "strip");
441
+ return { ...body, data: Array.isArray(data) ? data.map(strip) : strip(data) };
442
+ }
443
+ _chunk7QVYU63Ejs.__name.call(void 0, withoutServerOwnedFields, "withoutServerOwnedFields");
444
+ function toChange(entry) {
445
+ const change = { seq: entry.seq, method: entry.method, path: entry.path };
446
+ if (entry.body !== void 0) change.body = withoutServerOwnedFields(entry.body);
447
+ if (entry.recordType) change.recordType = entry.recordType;
448
+ if (entry.recordId) change.recordId = entry.recordId;
449
+ change.base = _nullishCoalesce(entry.base, () => ( null));
450
+ if (entry.resolution) change.resolution = entry.resolution;
451
+ return change;
452
+ }
453
+ _chunk7QVYU63Ejs.__name.call(void 0, toChange, "toChange");
454
+ function mergedResource(current, merged) {
455
+ if (!merged || !_optionalChain([current, 'optionalAccess', _16 => _16.type])) return void 0;
456
+ return { ...current, attributes: { ..._nullishCoalesce(current.attributes, () => ( {})), ...merged } };
457
+ }
458
+ _chunk7QVYU63Ejs.__name.call(void 0, mergedResource, "mergedResource");
459
+ function newPackageId() {
460
+ return globalThis.crypto.randomUUID();
461
+ }
462
+ _chunk7QVYU63Ejs.__name.call(void 0, newPackageId, "newPackageId");
463
+ function packageIdFor(entries) {
464
+ return _nullishCoalesce(_optionalChain([entries, 'access', _17 => _17.find, 'call', _18 => _18((entry) => entry.packageId), 'optionalAccess', _19 => _19.packageId]), () => ( newPackageId()));
465
+ }
466
+ _chunk7QVYU63Ejs.__name.call(void 0, packageIdFor, "packageIdFor");
467
+ async function entriesToSend(store) {
468
+ const all = await store.queue();
469
+ const typeNames = syncedTypeNames();
470
+ const blocked = _chunkB6JGKDP2js.waitingRecordKeys.call(void 0,
471
+ all.filter((entry) => entry.status === "conflict"),
472
+ typeNames
473
+ );
474
+ const lockedIds = new Set(_chunkMHB36MYEjs.getOfflineState.call(void 0, ).lockedRootIds);
475
+ const lockedByRoot = /* @__PURE__ */ new Map();
476
+ const now = /* @__PURE__ */ new Date();
477
+ const result = [];
478
+ for (const entry of all) {
479
+ if (entry.status !== "pending" && entry.status !== "sending") continue;
480
+ if (_chunkB6JGKDP2js.recordKeysOfEntry.call(void 0, entry, typeNames).some((key) => blocked.has(key))) continue;
481
+ if (!lockedByRoot.has(entry.rootId)) {
482
+ lockedByRoot.set(
483
+ entry.rootId,
484
+ lockedIds.has(entry.rootId) || _chunkPXDUJ47Njs.isRootLocked.call(void 0, await store.getSyncState(entry.rootId), now)
485
+ );
486
+ }
487
+ if (lockedByRoot.get(entry.rootId)) continue;
488
+ result.push(entry);
489
+ }
490
+ return result.sort((a, b) => a.seq - b.seq);
491
+ }
492
+ _chunk7QVYU63Ejs.__name.call(void 0, entriesToSend, "entriesToSend");
493
+ async function applyResult(store, entry, result) {
494
+ if (result.status === "applied") {
495
+ await store.removeQueueEntry(entry.seq);
496
+ const typeNames = syncedTypeNames();
497
+ const stillWaiting = _chunkB6JGKDP2js.waitingRecordKeys.call(void 0, await store.queue(), typeNames);
498
+ for (const key of _chunkB6JGKDP2js.recordKeysOfEntry.call(void 0, entry, typeNames)) {
499
+ if (stillWaiting.has(key)) continue;
500
+ const separator = key.indexOf(":");
501
+ const record = await store.getRecord(key.slice(0, separator), key.slice(separator + 1));
502
+ if (record && (record.base !== null || record.localOnly)) {
503
+ await store.putRecord({ ...record, base: null, localOnly: false });
504
+ }
505
+ }
506
+ if (result.response) {
507
+ await _chunkB6JGKDP2js.writeThrough.call(void 0,
508
+ { method: entry.method, url: entry.path },
509
+ { ok: true, status: 200, statusText: "OK", data: result.response }
510
+ );
511
+ } else if (entry.method === "DELETE") {
512
+ await _chunkB6JGKDP2js.writeThrough.call(void 0,
513
+ { method: entry.method, url: entry.path },
514
+ { ok: true, status: 204, statusText: "OK", data: void 0 }
515
+ );
516
+ }
517
+ return "applied";
518
+ }
519
+ if (result.status === "conflict" || result.status === "could-not-apply") {
520
+ await store.addConflict({
521
+ queueSeq: entry.seq,
522
+ kind: result.status === "could-not-apply" ? "could-not-apply" : _nullishCoalesce(result.conflict, () => ( "fields")),
523
+ recordType: entry.recordType,
524
+ recordId: entry.recordId,
525
+ mine: _nullishCoalesce(entry.body, () => ( null)),
526
+ theirs: _nullishCoalesce(result.current, () => ( null)),
527
+ base: _nullishCoalesce(entry.base, () => ( null)),
528
+ merged: mergedResource(result.current, result.merged),
529
+ fields: _nullishCoalesce(result.conflictFields, () => ( [])),
530
+ blocks: result.conflictBlocks,
531
+ reason: result.detail
532
+ });
533
+ await store.setQueueStatus(entry.seq, "conflict");
534
+ return "conflict";
535
+ }
536
+ await store.setQueueStatus(entry.seq, "pending");
537
+ return "pending";
538
+ }
539
+ _chunk7QVYU63Ejs.__name.call(void 0, applyResult, "applyResult");
540
+ async function drain() {
541
+ const outcome = { applied: 0, conflicts: 0, stoppedForLogin: false };
542
+ if (!_chunkMHB36MYEjs.isOfflineConfigured.call(void 0, ) || !_chunkMHB36MYEjs.getOfflineConfig.call(void 0, ).getUserId()) return outcome;
543
+ const store = await _chunkMHB36MYEjs.getOfflineStore.call(void 0, );
544
+ const entries = await entriesToSend(store);
545
+ if (entries.length === 0) return outcome;
546
+ const session = await refreshSession();
547
+ if (session === "unreachable") return outcome;
548
+ if (session === "expired") return { ...outcome, stoppedForLogin: true };
549
+ _chunkMHB36MYEjs.setOfflineState.call(void 0, { draining: true });
550
+ const handled = /* @__PURE__ */ new Set();
551
+ try {
552
+ const packageId = packageIdFor(entries);
553
+ await store.setQueuePackage(
554
+ entries.map((entry) => entry.seq),
555
+ packageId
556
+ );
557
+ for (const entry of entries) await store.setQueueStatus(entry.seq, "sending");
558
+ const endpoint = new (0, _chunkBZ5J2FIVjs.EndpointCreator)({ endpoint: _chunkBZ5J2FIVjs.Modules.OfflineChangeSet }).generate();
559
+ const release = _chunkMHB36MYEjs.allowWhileReconnecting.call(void 0, _chunkQKNGZDSQjs.buildUrl.call(void 0, endpoint));
560
+ let response;
561
+ try {
562
+ response = await _chunkQKNGZDSQjs.JsonApiPost.call(void 0, {
563
+ classKey: _chunkBZ5J2FIVjs.Modules.OfflineChangeSet,
564
+ endpoint,
565
+ body: { id: packageId, changes: entries.map(toChange) },
566
+ language: currentLocale()
567
+ });
568
+ } finally {
569
+ release();
570
+ }
571
+ if (!response.ok) {
572
+ if (response.response === 401) outcome.stoppedForLogin = true;
573
+ return outcome;
574
+ }
575
+ await store.setQueuePackage(
576
+ entries.map((entry) => entry.seq),
577
+ null
578
+ );
579
+ const results = new Map(response.data.results.map((result) => [result.seq, result]));
580
+ for (const entry of entries) {
581
+ const result = results.get(entry.seq);
582
+ const status = result ? await applyResult(store, entry, result) : "pending";
583
+ if (!result) await store.setQueueStatus(entry.seq, "pending");
584
+ handled.add(entry.seq);
585
+ if (status === "applied") outcome.applied++;
586
+ if (status === "conflict") outcome.conflicts++;
587
+ }
588
+ return outcome;
589
+ } catch (error) {
590
+ console.error("[offline] sending the waiting changes failed", error);
591
+ return outcome;
592
+ } finally {
593
+ for (const entry of entries) {
594
+ if (!handled.has(entry.seq)) await store.setQueueStatus(entry.seq, "pending");
595
+ }
596
+ _chunkMHB36MYEjs.setOfflineState.call(void 0, { draining: false });
597
+ await refreshOfflineCounts(store);
598
+ }
599
+ }
600
+ _chunk7QVYU63Ejs.__name.call(void 0, drain, "drain");
601
+ var _inFlight;
602
+ function drainQueue() {
603
+ if (!_inFlight) {
604
+ _inFlight = drain().finally(() => {
605
+ _inFlight = void 0;
606
+ });
607
+ }
608
+ return _inFlight;
609
+ }
610
+ _chunk7QVYU63Ejs.__name.call(void 0, drainQueue, "drainQueue");
611
+
612
+ // src/offline/sync/conflicts.ts
613
+ function updatedAtOf(resource) {
614
+ const value = _optionalChain([resource, 'optionalAccess', _20 => _20.attributes, 'optionalAccess', _21 => _21.updatedAt]);
615
+ if (!value) return null;
616
+ const date = new Date(value);
617
+ return Number.isNaN(date.getTime()) ? null : date;
618
+ }
619
+ _chunk7QVYU63Ejs.__name.call(void 0, updatedAtOf, "updatedAtOf");
620
+ async function applyChoicesToRecord(store, conflict, choices, mergedBody) {
621
+ if (!conflict.recordType || !conflict.recordId) return;
622
+ const record = await store.getRecord(conflict.recordType, conflict.recordId);
623
+ if (!record) return;
624
+ const attributes = { ..._nullishCoalesce(_optionalChain([record, 'access', _22 => _22.resource, 'optionalAccess', _23 => _23.attributes]), () => ( {})) };
625
+ const relationships = { ..._nullishCoalesce(_optionalChain([record, 'access', _24 => _24.resource, 'optionalAccess', _25 => _25.relationships]), () => ( {})) };
626
+ for (const [field, choice] of Object.entries(choices)) {
627
+ const source = choice === "theirs" ? conflict.theirs : choice === "merged" ? _optionalChain([mergedBody, 'optionalAccess', _26 => _26.data]) : void 0;
628
+ if (!source) continue;
629
+ if (source.attributes && field in source.attributes) attributes[field] = source.attributes[field];
630
+ else if (source.relationships && field in source.relationships) relationships[field] = source.relationships[field];
631
+ }
632
+ await store.putRecord({ ...record, resource: { ...record.resource, attributes, relationships } });
633
+ }
634
+ _chunk7QVYU63Ejs.__name.call(void 0, applyChoicesToRecord, "applyChoicesToRecord");
635
+ async function rootIdOf(store, conflict, entry) {
636
+ if (entry) return entry.rootId;
637
+ if (conflict.recordType && conflict.recordId) {
638
+ const record = await store.getRecord(conflict.recordType, conflict.recordId);
639
+ if (record) return record.rootId;
640
+ }
641
+ throw new Error(`[offline] conflict ${conflict.id} belongs to no root record on this device`);
642
+ }
643
+ _chunk7QVYU63Ejs.__name.call(void 0, rootIdOf, "rootIdOf");
644
+ function collectionPath(recordType) {
645
+ const module = _optionalChain([_chunkMHB36MYEjs.getOfflineConfig.call(void 0, ), 'access', _27 => _27.types, 'access', _28 => _28.find, 'call', _29 => _29((typeConfig) => typeConfig.module.name === recordType), 'optionalAccess', _30 => _30.module]);
646
+ return new (0, _chunkBZ5J2FIVjs.EndpointCreator)({ endpoint: _nullishCoalesce(module, () => ( recordType)) }).generate();
647
+ }
648
+ _chunk7QVYU63Ejs.__name.call(void 0, collectionPath, "collectionPath");
649
+ async function requeueOriginal(store, conflict, entry, fallbackMethod, resolution) {
650
+ const method = _nullishCoalesce(_optionalChain([entry, 'optionalAccess', _31 => _31.method]), () => ( fallbackMethod));
651
+ const body = method === "DELETE" ? void 0 : _nullishCoalesce(_nullishCoalesce(_optionalChain([entry, 'optionalAccess', _32 => _32.body]), () => ( conflict.mine)), () => ( void 0));
652
+ await store.enqueue({
653
+ rootId: await rootIdOf(store, conflict, entry),
654
+ method,
655
+ path: _nullishCoalesce(_optionalChain([entry, 'optionalAccess', _33 => _33.path]), () => ( new (0, _chunkBZ5J2FIVjs.EndpointCreator)({ endpoint: collectionPath(conflict.recordType), id: conflict.recordId }).generate())),
656
+ ...body !== void 0 ? { body } : {},
657
+ recordType: _nullishCoalesce(_optionalChain([entry, 'optionalAccess', _34 => _34.recordType]), () => ( conflict.recordType)),
658
+ recordId: _nullishCoalesce(_optionalChain([entry, 'optionalAccess', _35 => _35.recordId]), () => ( conflict.recordId)),
659
+ base: entry ? entry.base : _nullishCoalesce(conflict.base, () => ( null)),
660
+ // QueueEntry["resolution"] is the store's copy of OfflineChange["resolution"].
661
+ resolution
662
+ });
663
+ if (entry) await store.removeQueueEntry(entry.seq);
664
+ }
665
+ _chunk7QVYU63Ejs.__name.call(void 0, requeueOriginal, "requeueOriginal");
666
+ async function resolve(store, conflict, choice) {
667
+ const entry = (await store.queue()).find((candidate) => candidate.seq === conflict.queueSeq);
668
+ const dropEntry = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, async () => {
669
+ if (entry) await store.removeQueueEntry(entry.seq);
670
+ }, "dropEntry");
671
+ switch (choice.kind) {
672
+ case "mine":
673
+ case "fields": {
674
+ if (choice.kind === "fields" && Object.values(choice.choices).every((value) => value === "theirs")) {
675
+ return resolve(store, conflict, { kind: "theirs" });
676
+ }
677
+ const resolution = choice.kind === "mine" ? { kind: "mine" } : {
678
+ kind: "merged",
679
+ choices: choice.choices,
680
+ ...choice.mergedBody !== void 0 ? { mergedBody: choice.mergedBody } : {}
681
+ };
682
+ await requeueOriginal(store, conflict, entry, "PATCH", resolution);
683
+ if (choice.kind === "fields") await applyChoicesToRecord(store, conflict, choice.choices, choice.mergedBody);
684
+ break;
685
+ }
686
+ case "theirs": {
687
+ await dropEntry();
688
+ if (conflict.recordType && conflict.recordId) {
689
+ if (conflict.theirs) {
690
+ await store.putRecord({
691
+ type: conflict.recordType,
692
+ id: conflict.recordId,
693
+ rootId: await rootIdOf(store, conflict, entry),
694
+ resource: conflict.theirs,
695
+ updatedAt: updatedAtOf(conflict.theirs),
696
+ base: null,
697
+ localOnly: false
698
+ });
699
+ } else {
700
+ await store.deleteRecord(conflict.recordType, conflict.recordId);
701
+ }
702
+ }
703
+ break;
704
+ }
705
+ case "restore": {
706
+ if (!conflict.recordType) throw new Error(`[offline] conflict ${conflict.id} has no record to restore`);
707
+ const body = _nullishCoalesce(conflict.mine, () => ( _optionalChain([entry, 'optionalAccess', _36 => _36.body])));
708
+ const rootId = await rootIdOf(store, conflict, entry);
709
+ await store.enqueue({
710
+ rootId,
711
+ method: "POST",
712
+ path: collectionPath(conflict.recordType),
713
+ body,
714
+ recordType: conflict.recordType,
715
+ recordId: conflict.recordId,
716
+ base: null
717
+ });
718
+ await dropEntry();
719
+ if (conflict.recordId) {
720
+ const record = await store.getRecord(conflict.recordType, conflict.recordId);
721
+ if (record) await store.putRecord({ ...record, base: null, localOnly: true });
722
+ else if (_optionalChain([body, 'optionalAccess', _37 => _37.data]))
723
+ await store.putRecord({
724
+ type: conflict.recordType,
725
+ id: conflict.recordId,
726
+ rootId,
727
+ resource: body.data,
728
+ updatedAt: null,
729
+ base: null,
730
+ localOnly: true
731
+ });
732
+ }
733
+ break;
734
+ }
735
+ case "accept-deletion": {
736
+ await dropEntry();
737
+ if (conflict.recordType && conflict.recordId) await store.deleteRecord(conflict.recordType, conflict.recordId);
738
+ break;
739
+ }
740
+ case "delete-anyway": {
741
+ await requeueOriginal(store, conflict, entry, "DELETE", { kind: "mine" });
742
+ break;
743
+ }
744
+ case "retry": {
745
+ if (entry) await store.setQueueStatus(entry.seq, "pending");
746
+ break;
747
+ }
748
+ case "discard": {
749
+ await dropEntry();
750
+ break;
751
+ }
752
+ }
753
+ await store.removeConflict(conflict.id);
754
+ }
755
+ _chunk7QVYU63Ejs.__name.call(void 0, resolve, "resolve");
756
+ async function resolveConflict(id, choice) {
757
+ const store = await _chunkMHB36MYEjs.getOfflineStore.call(void 0, );
758
+ const conflict = (await store.conflicts()).find((candidate) => candidate.id === id);
759
+ if (!conflict) throw new Error(`[offline] no conflict ${id}`);
760
+ await store.transaction((tx) => resolve(tx, conflict, choice));
761
+ await refreshOfflineCounts(store);
762
+ if (_chunkMHB36MYEjs.getOfflineState.call(void 0, ).online) {
763
+ drainQueue().catch((error) => console.warn("[offline] sending the resolved change failed", error));
764
+ }
765
+ }
766
+ _chunk7QVYU63Ejs.__name.call(void 0, resolveConflict, "resolveConflict");
767
+
768
+ // src/offline/sync/runtime.ts
769
+
770
+ var LOCK_CHECK_INTERVAL_MS = 6e4;
771
+ var PROBE_INTERVAL_MS = 3e4;
772
+ async function probeApi() {
773
+ const config = _chunkMHB36MYEjs.getOfflineConfig.call(void 0, );
774
+ const store = await _chunkMHB36MYEjs.getOfflineStore.call(void 0, );
775
+ const [rootId] = await _chunkB6JGKDP2js.knownRootIds.call(void 0, store);
776
+ const endpoint = rootId ? new (0, _chunkBZ5J2FIVjs.EndpointCreator)({ endpoint: config.rootModule, id: rootId, childEndpoint: _chunkBZ5J2FIVjs.ROOT_SYNC_ENDPOINT }) : new (0, _chunkBZ5J2FIVjs.EndpointCreator)({ endpoint: config.rootModule }).addAdditionalParam("page[size]", "1");
777
+ const response = await _chunkKMW7UNL2js.directFetch.call(void 0, {
778
+ method: "GET",
779
+ url: _chunkQKNGZDSQjs.buildUrl.call(void 0, endpoint.generate()),
780
+ token: await _chunkLXKSUWAVjs.getClientToken.call(void 0, ),
781
+ language: currentLocale(),
782
+ additionalHeaders: { [_chunkMHB36MYEjs.OFFLINE_REPLAY_HEADER]: "1" }
783
+ });
784
+ return !response.networkError;
785
+ }
786
+ _chunk7QVYU63Ejs.__name.call(void 0, probeApi, "probeApi");
787
+ var LOGIN_RELOAD_KEY = "nja-offline-login-reload";
788
+ var _reloadedForSignIn;
789
+ async function signInFingerprint() {
790
+ const token = await _cookiesnext.getCookie.call(void 0, "token");
791
+ if (!token) return "none";
792
+ let hash = 5381;
793
+ for (const char of String(token)) hash = (hash * 33 ^ char.charCodeAt(0)) >>> 0;
794
+ return hash.toString(36);
795
+ }
796
+ _chunk7QVYU63Ejs.__name.call(void 0, signInFingerprint, "signInFingerprint");
797
+ var readReloadMarker = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, () => {
798
+ try {
799
+ return window.sessionStorage.getItem(LOGIN_RELOAD_KEY);
800
+ } catch (e2) {
801
+ return null;
802
+ }
803
+ }, "readReloadMarker");
804
+ var writeReloadMarker = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, (value) => {
805
+ try {
806
+ if (value === null) window.sessionStorage.removeItem(LOGIN_RELOAD_KEY);
807
+ else window.sessionStorage.setItem(LOGIN_RELOAD_KEY, value);
808
+ } catch (e3) {
809
+ }
810
+ }, "writeReloadMarker");
811
+ async function signInExpired() {
812
+ const signIn = await signInFingerprint();
813
+ if (_reloadedForSignIn === signIn || readReloadMarker() === signIn) {
814
+ console.warn("[offline] the sign-in expired; log in again to send the waiting changes");
815
+ return;
816
+ }
817
+ _reloadedForSignIn = signIn;
818
+ writeReloadMarker(signIn);
819
+ try {
820
+ window.location.reload();
821
+ } catch (error) {
822
+ console.warn("[offline] the sign-in expired; log in again to send the waiting changes", error);
823
+ }
824
+ }
825
+ _chunk7QVYU63Ejs.__name.call(void 0, signInExpired, "signInExpired");
826
+ var warnUnlessUnavailable = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, (message) => (error) => {
827
+ if (!(error instanceof _chunkMHB36MYEjs.OfflineUnavailableError)) console.warn(message, error);
828
+ }, "warnUnlessUnavailable");
829
+ var _runningRuntimes = /* @__PURE__ */ new Set();
830
+ function stopOfflineRuntime() {
831
+ for (const stop of [..._runningRuntimes]) stop();
832
+ }
833
+ _chunk7QVYU63Ejs.__name.call(void 0, stopOfflineRuntime, "stopOfflineRuntime");
834
+ function startOfflineRuntime() {
835
+ _chunkMHB36MYEjs.refreshOfflineDeviceState.call(void 0, );
836
+ if (!_chunkMHB36MYEjs.isOfflineConfigured.call(void 0, )) return () => {
837
+ };
838
+ const config = _chunkMHB36MYEjs.getOfflineConfig.call(void 0, );
839
+ let running;
840
+ let goingOnlineAfterSync = false;
841
+ const run = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, (reconnect) => {
842
+ if (!running) {
843
+ running = (async () => {
844
+ let succeeded = false;
845
+ if (reconnect) _chunkMHB36MYEjs.setReconnecting.call(void 0, true);
846
+ try {
847
+ const drained = await drainQueue();
848
+ if (drained.stoppedForLogin) {
849
+ await signInExpired();
850
+ return;
851
+ }
852
+ writeReloadMarker(null);
853
+ if (reconnect ? !_chunkMHB36MYEjs.isReconnecting.call(void 0, ) : !_chunkMHB36MYEjs.getOfflineState.call(void 0, ).online) return;
854
+ await syncAll();
855
+ succeeded = reconnect && _chunkMHB36MYEjs.isReconnecting.call(void 0, );
856
+ } catch (error) {
857
+ warnUnlessUnavailable("[offline] background sync failed")(error);
858
+ } finally {
859
+ if (reconnect) _chunkMHB36MYEjs.setReconnecting.call(void 0, false);
860
+ running = void 0;
861
+ if (succeeded) {
862
+ goingOnlineAfterSync = true;
863
+ _chunkMHB36MYEjs.setOfflineState.call(void 0, { online: true });
864
+ goingOnlineAfterSync = false;
865
+ if (_chunkMHB36MYEjs.getOfflineState.call(void 0, ).pending > 0) {
866
+ drainQueue().catch(warnUnlessUnavailable("[offline] sending the waiting changes failed"));
867
+ }
868
+ }
869
+ }
870
+ })();
871
+ }
872
+ return running;
873
+ }, "run");
874
+ const runOnline = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, () => run(false), "runOnline");
875
+ let probing = false;
876
+ const probe = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, async () => {
877
+ if (probing || running || _chunkMHB36MYEjs.getOfflineState.call(void 0, ).online) return;
878
+ if (typeof navigator !== "undefined" && navigator.onLine === false) return;
879
+ probing = true;
880
+ try {
881
+ if (await probeApi()) await run(true);
882
+ } catch (error) {
883
+ warnUnlessUnavailable("[offline] probing the API failed")(error);
884
+ } finally {
885
+ probing = false;
886
+ }
887
+ }, "probe");
888
+ const onBrowserOnline = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, () => void probe(), "onBrowserOnline");
889
+ if (typeof window !== "undefined") window.addEventListener("online", onBrowserOnline);
890
+ let wasOnline = _chunkMHB36MYEjs.getOfflineState.call(void 0, ).online;
891
+ const unsubscribe = _chunkMHB36MYEjs.subscribeOfflineState.call(void 0, (state) => {
892
+ if (!state.available) {
893
+ stop();
894
+ return;
895
+ }
896
+ if (state.online && !wasOnline && !goingOnlineAfterSync) void runOnline();
897
+ wasOnline = state.online;
898
+ });
899
+ void _chunkB6JGKDP2js.refreshLockedRoots.call(void 0, ).catch(warnUnlessUnavailable("[offline] lock check failed"));
900
+ void refreshOfflineCounts().catch(warnUnlessUnavailable("[offline] reading the queue failed"));
901
+ if (_chunkMHB36MYEjs.getOfflineState.call(void 0, ).online) void runOnline();
902
+ const syncTimer = setInterval(() => {
903
+ if (_chunkMHB36MYEjs.getOfflineState.call(void 0, ).online) void runOnline();
904
+ }, config.syncIntervalMs);
905
+ const probeTimer = setInterval(() => void probe(), PROBE_INTERVAL_MS);
906
+ const lockTimer = setInterval(() => {
907
+ void _chunkB6JGKDP2js.refreshLockedRoots.call(void 0, ).catch(warnUnlessUnavailable("[offline] lock check failed"));
908
+ }, LOCK_CHECK_INTERVAL_MS);
909
+ const stop = /* @__PURE__ */ _chunk7QVYU63Ejs.__name.call(void 0, () => {
910
+ _runningRuntimes.delete(stop);
911
+ clearInterval(syncTimer);
912
+ clearInterval(probeTimer);
913
+ clearInterval(lockTimer);
914
+ if (typeof window !== "undefined") window.removeEventListener("online", onBrowserOnline);
915
+ unsubscribe();
916
+ }, "stop");
917
+ _runningRuntimes.add(stop);
918
+ return stop;
919
+ }
920
+ _chunk7QVYU63Ejs.__name.call(void 0, startOfflineRuntime, "startOfflineRuntime");
921
+
922
+ // src/offline/logout.ts
923
+ async function prepareOfflineLogout() {
924
+ if (!_chunkMHB36MYEjs.isOfflineConfigured.call(void 0, )) return { pending: 0 };
925
+ if (!_chunkMHB36MYEjs.getOfflineConfig.call(void 0, ).getUserId()) return { pending: 0 };
926
+ const store = await _chunkMHB36MYEjs.getOfflineStore.call(void 0, );
927
+ const entries = await store.queue();
928
+ return { pending: entries.length };
929
+ }
930
+ _chunk7QVYU63Ejs.__name.call(void 0, prepareOfflineLogout, "prepareOfflineLogout");
931
+ async function finishOfflineLogout(userId) {
932
+ stopOfflineRuntime();
933
+ _chunkMHB36MYEjs.blockOfflineStore.call(void 0, userId);
934
+ const { deleteDeviceStore: deleteDeviceStore2 } = await Promise.resolve().then(() => _interopRequireWildcard(require("../lifecycle-4GUOTB46.js")));
935
+ await deleteDeviceStore2(userId);
936
+ await _chunkPXDUJ47Njs.deleteImagesCaches.call(void 0, );
937
+ _chunkMHB36MYEjs.setOfflineEnabledOnDevice.call(void 0, userId, false);
938
+ _chunkMHB36MYEjs.writeOfflineLastSync.call(void 0, userId, null);
939
+ _chunkMHB36MYEjs.setOfflineState.call(void 0, { enabled: false, syncProgress: null, lastSyncedAt: null, rootCount: null });
940
+ }
941
+ _chunk7QVYU63Ejs.__name.call(void 0, finishOfflineLogout, "finishOfflineLogout");
942
+
943
+ // src/offline/device-switch.ts
944
+ function signedInUserId() {
945
+ const userId = _chunkMHB36MYEjs.getOfflineConfig.call(void 0, ).getUserId();
946
+ if (!userId) throw new Error("No signed-in user");
947
+ return userId;
948
+ }
949
+ _chunk7QVYU63Ejs.__name.call(void 0, signedInUserId, "signedInUserId");
950
+ async function turnOnOffline() {
951
+ const userId = signedInUserId();
952
+ _chunkMHB36MYEjs.setOfflineEnabledOnDevice.call(void 0, userId, true);
953
+ _chunkMHB36MYEjs.setOfflineState.call(void 0, { enabled: true });
954
+ try {
955
+ await _optionalChain([navigator, 'access', _38 => _38.storage, 'optionalAccess', _39 => _39.persist, 'optionalCall', _40 => _40()]);
956
+ } catch (e4) {
957
+ }
958
+ }
959
+ _chunk7QVYU63Ejs.__name.call(void 0, turnOnOffline, "turnOnOffline");
960
+ async function turnOffOffline() {
961
+ const userId = signedInUserId();
962
+ if (_chunkMHB36MYEjs.isOfflineAvailable.call(void 0, )) {
963
+ let pending = 0;
964
+ try {
965
+ const store = await _chunkMHB36MYEjs.getOfflineStore.call(void 0, );
966
+ pending = (await store.queue()).length;
967
+ } catch (e5) {
968
+ const { hasUnsentChanges: hasUnsentChanges2 } = await Promise.resolve().then(() => _interopRequireWildcard(require("../lifecycle-4GUOTB46.js")));
969
+ if (await hasUnsentChanges2(userId).catch(() => false)) pending = 1;
970
+ }
971
+ if (pending > 0) return { turnedOff: false, pending };
972
+ }
973
+ _chunkMHB36MYEjs.setOfflineEnabledOnDevice.call(void 0, userId, false);
974
+ if (_chunkMHB36MYEjs.isOfflineAvailable.call(void 0, )) {
975
+ stopOfflineRuntime();
976
+ try {
977
+ const { deleteDeviceStore: deleteDeviceStore2 } = await Promise.resolve().then(() => _interopRequireWildcard(require("../lifecycle-4GUOTB46.js")));
978
+ await deleteDeviceStore2(userId);
979
+ await _chunkPXDUJ47Njs.deleteImagesCaches.call(void 0, );
980
+ } catch (error) {
981
+ console.warn("[offline] the device copy could not be deleted", error);
982
+ }
983
+ _chunkMHB36MYEjs.forgetOfflineStore.call(void 0, userId);
984
+ }
985
+ _chunkMHB36MYEjs.writeOfflineLastSync.call(void 0, userId, null);
986
+ _chunkMHB36MYEjs.setOfflineState.call(void 0, { enabled: false, syncProgress: null, lastSyncedAt: null, rootCount: null });
987
+ return { turnedOff: true };
988
+ }
989
+ _chunk7QVYU63Ejs.__name.call(void 0, turnOffOffline, "turnOffOffline");
990
+
991
+
992
+
993
+
994
+
995
+
996
+
997
+
998
+
999
+
1000
+
1001
+
1002
+
1003
+
1004
+
1005
+
1006
+
1007
+
1008
+
1009
+
1010
+
1011
+
1012
+
1013
+
1014
+
1015
+
1016
+
1017
+
1018
+
1019
+
1020
+
1021
+
1022
+
1023
+
1024
+
1025
+
1026
+
1027
+
1028
+
1029
+
1030
+
1031
+
1032
+
1033
+
1034
+
1035
+
1036
+
1037
+
1038
+
1039
+
1040
+
1041
+
1042
+
1043
+
1044
+
1045
+
1046
+
1047
+
1048
+
1049
+
1050
+
1051
+ exports.DEFAULT_DEVICE_WORKER_URL = _chunkMHB36MYEjs.DEFAULT_DEVICE_WORKER_URL; exports.DEFAULT_SQLITE_MODULE_URL = _chunkMHB36MYEjs.DEFAULT_SQLITE_MODULE_URL; exports.DEVICE_WORKER_FILE = _chunkMHB36MYEjs.DEVICE_WORKER_FILE; exports.DeviceStoreUnavailableError = _chunkMHB36MYEjs.DeviceStoreUnavailableError; exports.NeedsConnectionError = _chunkMHB36MYEjs.NeedsConnectionError; exports.OFFLINE_REPLAY_HEADER = _chunkMHB36MYEjs.OFFLINE_REPLAY_HEADER; exports.OFFLINE_SQLITE_FILES = _chunkMHB36MYEjs.OFFLINE_SQLITE_FILES; exports.OfflineUnavailableError = _chunkMHB36MYEjs.OfflineUnavailableError; exports.SERVER_DEFAULT_ORDER_BY = _chunkW62MHDWMjs.SERVER_DEFAULT_ORDER_BY; exports.configureOffline = configureOffline2; exports.deleteDeviceStore = _chunkPXDUJ47Njs.deleteDeviceStore; exports.drainQueue = drainQueue; exports.errorAnswer = _chunkW62MHDWMjs.errorAnswer; exports.finishOfflineLogout = finishOfflineLogout; exports.forgetOfflineStore = _chunkMHB36MYEjs.forgetOfflineStore; exports.getOfflineConfig = _chunkMHB36MYEjs.getOfflineConfig; exports.getOfflineState = _chunkMHB36MYEjs.getOfflineState; exports.getOfflineStore = _chunkMHB36MYEjs.getOfflineStore; exports.hasUnsentChanges = _chunkPXDUJ47Njs.hasUnsentChanges; exports.includedFor = _chunkW62MHDWMjs.includedFor; exports.isOfflineAvailable = _chunkMHB36MYEjs.isOfflineAvailable; exports.isOfflineConfigured = _chunkMHB36MYEjs.isOfflineConfigured; exports.isOfflineEnabledOnDevice = _chunkMHB36MYEjs.isOfflineEnabledOnDevice; exports.isRootLocked = _chunkPXDUJ47Njs.isRootLocked; exports.linkKindFor = _chunkW62MHDWMjs.linkKindFor; exports.linkKindsOf = _chunkW62MHDWMjs.linkKindsOf; exports.linksOfKind = _chunkW62MHDWMjs.linksOfKind; exports.listAnswer = _chunkW62MHDWMjs.listAnswer; exports.localTransport = _chunkW62MHDWMjs.localTransport; exports.matchPattern = _chunkW62MHDWMjs.matchPattern; exports.matchRoute = _chunkW62MHDWMjs.matchRoute; exports.mergeResource = _chunkW62MHDWMjs.mergeResource; exports.needsConnectionAnswer = _chunkW62MHDWMjs.needsConnectionAnswer; exports.notFoundAnswer = _chunkW62MHDWMjs.notFoundAnswer; exports.onUserSignedIn = _chunkPXDUJ47Njs.onUserSignedIn; exports.openDeviceStore = _chunkPXDUJ47Njs.openDeviceStore; exports.openMemoryDeviceStore = _chunkPXDUJ47Njs.openMemoryDeviceStore; exports.orderRecords = _chunkW62MHDWMjs.orderRecords; exports.orderedListAnswer = _chunkW62MHDWMjs.orderedListAnswer; exports.patternToString = _chunkMHB36MYEjs.patternToString; exports.prepareOfflineLogout = prepareOfflineLogout; exports.refreshOfflineDeviceState = _chunkMHB36MYEjs.refreshOfflineDeviceState; exports.resolveConflict = resolveConflict; exports.resourceFromDocument = _chunkW62MHDWMjs.resourceFromDocument; exports.resourceListAnswer = _chunkW62MHDWMjs.resourceListAnswer; exports.searchRecords = _chunkW62MHDWMjs.searchRecords; exports.setDeviceStoreOpener = _chunkMHB36MYEjs.setDeviceStoreOpener; exports.setOfflineState = _chunkMHB36MYEjs.setOfflineState; exports.singleAnswer = _chunkW62MHDWMjs.singleAnswer; exports.startOfflineRuntime = startOfflineRuntime; exports.stopOfflineRuntime = stopOfflineRuntime; exports.subscribeOfflineState = _chunkMHB36MYEjs.subscribeOfflineState; exports.syncAll = syncAll; exports.syncRoot = syncRoot; exports.turnOffOffline = turnOffOffline; exports.turnOnOffline = turnOnOffline; exports.useConflicts = useConflicts; exports.useNeedsConnection = _chunkGB6DBFYYjs.useNeedsConnection; exports.useOfflineState = _chunkGB6DBFYYjs.useOfflineState; exports.writeThrough = _chunkB6JGKDP2js.writeThrough;
1052
+ //# sourceMappingURL=index.js.map