@unbrained/pm-web 2026.8.29 → 2026.9.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.
package/public/sw.js CHANGED
@@ -213,12 +213,32 @@ async function flushMutationQueue() {
213
213
  const mutations = read.mutations;
214
214
  if (mutations.length === 0)
215
215
  return;
216
+ let replayCsrfToken;
217
+ try {
218
+ const bootstrap = await fetch('/api/auth/me', {
219
+ method: 'GET',
220
+ credentials: 'include',
221
+ cache: 'no-store',
222
+ });
223
+ replayCsrfToken = bootstrap.headers.get('x-csrf-token');
224
+ if (!replayCsrfToken) {
225
+ console.warn('Cannot replay offline mutations without a CSRF bootstrap token');
226
+ return;
227
+ }
228
+ }
229
+ catch {
230
+ // The network failed during token bootstrap; preserve the entire queue.
231
+ return;
232
+ }
216
233
  let replayed = 0;
217
234
  for (const mut of mutations) {
218
235
  try {
219
236
  const opts = {
220
237
  method: mut.method,
221
- headers: { 'Content-Type': 'application/json' },
238
+ headers: {
239
+ 'Content-Type': 'application/json',
240
+ 'X-CSRF-Token': replayCsrfToken,
241
+ },
222
242
  credentials: 'include',
223
243
  };
224
244
  if (mut.body !== null)