@wix/himalaya-cli 0.1211.0 → 0.1213.0

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 (41) hide show
  1. package/dist/cli.mjs +20 -21
  2. package/dist/preview-assets.generated.bin +0 -0
  3. package/package.json +2 -2
  4. package/templates/beauty-salon-owner/dev/index.ts +218 -0
  5. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-post/index.ts +63 -16
  6. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-product/index.ts +61 -16
  7. package/templates/community-club-owner/dev/index.ts +327 -0
  8. package/templates/community-club-owner/tier5-src/himi-owner-lite-event/index.ts +59 -14
  9. package/templates/community-club-owner/tier5-src/himi-owner-lite-post/index.ts +63 -16
  10. package/templates/community-club-owner/tier5-src/himi-owner-lite-product/index.ts +61 -16
  11. package/templates/events-meetups-owner/dev/index.ts +218 -0
  12. package/templates/events-meetups-owner/tier5-src/himi-owner-lite-event/index.ts +59 -14
  13. package/templates/events-meetups-owner/tier5-src/himi-owner-lite-post/index.ts +63 -16
  14. package/templates/gym-fitness-owner/dev/index.ts +327 -0
  15. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-event/index.ts +59 -14
  16. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-post/index.ts +63 -16
  17. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-product/index.ts +61 -16
  18. package/templates/nonprofit-cause-owner/dev/index.ts +218 -0
  19. package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-event/index.ts +59 -14
  20. package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-post/index.ts +63 -16
  21. package/templates/owner-lite/dev/index.ts +327 -0
  22. package/templates/owner-lite/tier5-src/himi-owner-lite-event/index.ts +59 -14
  23. package/templates/owner-lite/tier5-src/himi-owner-lite-post/index.ts +63 -16
  24. package/templates/owner-lite/tier5-src/himi-owner-lite-product/index.ts +61 -16
  25. package/templates/podcast-creator-owner/dev/index.ts +327 -0
  26. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-event/index.ts +59 -14
  27. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-post/index.ts +63 -16
  28. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-product/index.ts +61 -16
  29. package/templates/portfolio-creative-owner/dev/index.ts +218 -0
  30. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-post/index.ts +63 -16
  31. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-product/index.ts +61 -16
  32. package/templates/restaurant-owner/dev/index.ts +327 -0
  33. package/templates/restaurant-owner/tier5-src/himi-owner-lite-event/index.ts +59 -14
  34. package/templates/restaurant-owner/tier5-src/himi-owner-lite-post/index.ts +63 -16
  35. package/templates/restaurant-owner/tier5-src/himi-owner-lite-product/index.ts +61 -16
  36. package/templates/retail-store-owner/dev/index.ts +218 -0
  37. package/templates/retail-store-owner/tier5-src/himi-owner-lite-post/index.ts +63 -16
  38. package/templates/retail-store-owner/tier5-src/himi-owner-lite-product/index.ts +61 -16
  39. package/templates/yoga-studio-owner/dev/index.ts +218 -0
  40. package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-event/index.ts +59 -14
  41. package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-post/index.ts +63 -16
@@ -59,6 +59,9 @@ interface ProductState {
59
59
  /** Non-empty when showing owner-preview-demo sample data (web preview, no owner bridge). */
60
60
  demoNote: string;
61
61
  notDemo: boolean;
62
+ /** #3158 — Delete ARMS a confirmation; only confirmDelete reaches the API. */
63
+ deletePending: boolean;
64
+ noDeleteConfirmation: boolean;
62
65
  }
63
66
 
64
67
  /* eslint-disable @typescript-eslint/no-explicit-any */
@@ -143,6 +146,9 @@ function shape(s: Partial<ProductState>): ProductState {
143
146
  hideHide: !visible || status !== "ready",
144
147
  demoNote: s.demoNote ?? "",
145
148
  notDemo: !s.demoNote,
149
+ // Only a loaded entity can be pending deletion; every other action disarms it (`disarm`).
150
+ deletePending: !!s.deletePending && hasEntity,
151
+ noDeleteConfirmation: !(s.deletePending && hasEntity),
146
152
  };
147
153
  }
148
154
 
@@ -265,16 +271,33 @@ async function setVisibility(s: ProductState, visible: boolean, msg: string): Pr
265
271
  }
266
272
  }
267
273
 
274
+ /** #3158 — a confirmed delete in flight. Synchronous and module-level on purpose: two
275
+ * confirmDelete dispatches (a double tap) both start from a state that says "armed", and only a
276
+ * flag set BEFORE the first await stops the second from issuing its own DELETE — whose late 404
277
+ * would otherwise land after, and overwrite, the first one's "deleted". */
278
+ let deleteInFlight = false;
279
+
280
+ /** #3158 — the confirmation describes THIS visit. Never take it from a persisted snapshot, or a
281
+ * reopened record comes back with "Delete this …?" already armed. */
282
+ const DELETE_RUN_KEYS = ["deletePending", "noDeleteConfirmation"] as const;
283
+
284
+ /** #3158 — clear an armed delete confirmation. */
285
+ const disarm = <T extends { deletePending: boolean }>(s: T): T => ({ ...s, deletePending: false });
286
+
268
287
  const svc = defineService<ProductState, {
269
288
  load: (s: ProductState, arg?: unknown) => Promise<ProductState>;
270
289
  retry: (s: ProductState) => Promise<ProductState>;
271
290
  show: (s: ProductState) => Promise<ProductState>;
272
291
  hide: (s: ProductState) => Promise<ProductState>;
273
292
  delete: (s: ProductState) => Promise<ProductState>;
293
+ cancelDelete: (s: ProductState) => Promise<ProductState>;
294
+ confirmDelete: (s: ProductState) => Promise<ProductState | undefined>;
274
295
  }>("himiOwnerLiteProduct", {
275
296
  state: shape({ status: "loading" }),
297
+ notHydrated: [...DELETE_RUN_KEYS],
276
298
  actions: {
277
- load: async (s, arg) => {
299
+ load: async (s0, arg) => {
300
+ const s = disarm(s0);
278
301
  stashCopy(arg); // absorb the descriptor's onAppear copy-pack param
279
302
  const id = idFrom(arg, s.id) || inputId();
280
303
  if (!id) return shape({ ...s, status: "error", error: copyParam("ownerProduct.errorNoId", "no product id") });
@@ -297,7 +320,8 @@ const svc = defineService<ProductState, {
297
320
  return shape({ ...s, id, status: "error", error: ownerLoadError(e) });
298
321
  }
299
322
  },
300
- retry: async (s) => {
323
+ retry: async (s0) => {
324
+ const s = disarm(s0);
301
325
  if (!s.id) return shape({ ...s, status: "error", error: copyParam("ownerProduct.errorNoId", "no product id") });
302
326
  if (isOwnerPreviewDemo()) {
303
327
  const demo = demoDetail(s, s.id);
@@ -317,25 +341,46 @@ const svc = defineService<ProductState, {
317
341
  return shape({ ...s, status: "error", error: ownerLoadError(e) });
318
342
  }
319
343
  },
320
- show: async (s) => setVisibility(s, true, copyParam("ownerProduct.shownMessage", "Product is now visible in your store.")),
321
- hide: async (s) => setVisibility(s, false, copyParam("ownerProduct.hiddenMessage", "Product hidden from your store.")),
322
- delete: async (s) => {
323
- if (isOwnerPreviewDemo() || s.demoNote) return shape({ ...s, actionMessage: copyParam("ownerCommon.demoSaveNote", DEMO_SAVE_NOTE) });
324
- if (!s.id) return shape({ ...s, actionMessage: copyParam("ownerProduct.noIdMessage", "No product id.") });
325
- // Optimistic local delete — the list drops the row immediately.
326
- await cacheDrop(s.id);
344
+ show: async (s0) => { const s = disarm(s0); return setVisibility(s, true, copyParam("ownerProduct.shownMessage", "Product is now visible in your store.")); },
345
+ hide: async (s0) => { const s = disarm(s0); return setVisibility(s, false, copyParam("ownerProduct.hiddenMessage", "Product hidden from your store.")); },
346
+ // #3158 — destructive, so two steps. `delete` (the Manage card's Delete button)
347
+ // only ARMS the inline confirmation, which names the record and says it cannot
348
+ // be undone; `cancelDelete` disarms it; only `confirmDelete` deletes. Anything
349
+ // that dispatches `delete` directly therefore still asks first.
350
+ delete: async (s) => shape({ ...s, deletePending: true, actionMessage: "" }),
351
+ cancelDelete: async (s) => shape({ ...s, deletePending: false }),
352
+ confirmDelete: async (s0) => {
353
+ // Nothing armed (a stray dispatch, a rehydrated snapshot) or a delete already running
354
+ // (a second tap): ignore it — `undefined` leaves the state exactly as it is.
355
+ if (!s0.deletePending || deleteInFlight) return undefined;
356
+ deleteInFlight = true;
327
357
  try {
328
- await deleteProduct(s.id);
329
- return shape({ ...s, status: "deleted", title: "", emptyText: copyParam("ownerProduct.deletedEmpty", "Product deleted."), actionMessage: "" });
330
- } catch (e) {
331
- if (shouldQueueOwnerWrite(e)) {
332
- await queueWrite("tier5.himiOwnerLiteProduct.delete", { id: s.id });
333
- return shape({ ...s, status: "deleted", title: "", emptyText: copyParam("ownerProduct.deletedEmpty", "Product deleted."), actionMessage: copyParam("ownerCommon.demoSaveNote", DEMO_SAVE_NOTE) });
358
+ const s = disarm(s0);
359
+ if (isOwnerPreviewDemo() || s.demoNote) return shape({ ...s, actionMessage: copyParam("ownerCommon.demoSaveNote", DEMO_SAVE_NOTE) });
360
+ if (!s.id) return shape({ ...s, actionMessage: copyParam("ownerProduct.noIdMessage", "No product id.") });
361
+ // Optimistic local delete — the list drops the row immediately.
362
+ await cacheDrop(s.id);
363
+ try {
364
+ await deleteProduct(s.id);
365
+ return shape({ ...s, status: "deleted", title: "", emptyText: copyParam("ownerProduct.deletedEmpty", "Product deleted."), actionMessage: "" });
366
+ } catch (e) {
367
+ if (shouldQueueOwnerWrite(e)) {
368
+ await queueWrite("tier5.himiOwnerLiteProduct.delete", { id: s.id });
369
+ return shape({ ...s, status: "deleted", title: "", emptyText: copyParam("ownerProduct.deletedEmpty", "Product deleted."), actionMessage: copyParam("ownerCommon.demoSaveNote", DEMO_SAVE_NOTE) });
370
+ }
371
+ return shape({ ...s, actionMessage: ownerLoadError(e) });
334
372
  }
335
- return shape({ ...s, actionMessage: ownerLoadError(e) });
373
+ } finally {
374
+ deleteInFlight = false;
336
375
  }
337
376
  },
338
377
  },
339
378
  });
340
379
 
380
+ // The same reset on a runtime from before `notHydrated` (an older binary on a new bundle).
381
+ if ((globalThis as { himalaya?: { hydrationOptOut?: unknown } }).himalaya?.hydrationOptOut !== true) {
382
+ const booted = svc.getState?.() as unknown as Record<string, unknown> | undefined;
383
+ if (booted && typeof booted === "object") Object.assign(booted, { deletePending: false, noDeleteConfirmation: true });
384
+ }
385
+
341
386
  export { svc };
@@ -73836,6 +73836,115 @@ const TEMPLATED: { pattern: string; display: string; liveSeed?: LiveSeed; static
73836
73836
  }
73837
73837
  }
73838
73838
  },
73839
+ {
73840
+ "id": "event_delete_confirmation",
73841
+ "body": {
73842
+ "package": "himalaya",
73843
+ "type": "VStack",
73844
+ "props": {
73845
+ "spacing": 10,
73846
+ "alignment": "leading",
73847
+ "children": [
73848
+ {
73849
+ "id": "event_delete_confirmation.title",
73850
+ "body": {
73851
+ "package": "himalaya",
73852
+ "type": "Text",
73853
+ "props": {
73854
+ "text": "Delete this workshop?",
73855
+ "style": "bodyEmphasis"
73856
+ }
73857
+ }
73858
+ },
73859
+ {
73860
+ "id": "event_delete_confirmation.record",
73861
+ "body": {
73862
+ "package": "himalaya",
73863
+ "type": "Text",
73864
+ "props": {
73865
+ "text": "$service:himiOwnerLiteEvent.title",
73866
+ "style": "body",
73867
+ "color": "textSecondary",
73868
+ "maxLines": 2
73869
+ }
73870
+ }
73871
+ },
73872
+ {
73873
+ "id": "",
73874
+ "body": {
73875
+ "package": "himalaya",
73876
+ "type": "Text",
73877
+ "props": {
73878
+ "text": "This cannot be undone.",
73879
+ "style": "footnote",
73880
+ "color": "textSecondary"
73881
+ }
73882
+ }
73883
+ },
73884
+ {
73885
+ "id": "",
73886
+ "body": {
73887
+ "package": "himalaya",
73888
+ "type": "HStack",
73889
+ "props": {
73890
+ "spacing": 8,
73891
+ "children": [
73892
+ {
73893
+ "id": "event_delete_cancel",
73894
+ "body": {
73895
+ "package": "himalaya",
73896
+ "type": "Button",
73897
+ "props": {
73898
+ "title": "Cancel",
73899
+ "style": "secondary",
73900
+ "action": {
73901
+ "actionId": "tier5.himiOwnerLiteEvent.cancelDelete"
73902
+ }
73903
+ }
73904
+ }
73905
+ },
73906
+ {
73907
+ "id": "event_delete_confirm",
73908
+ "body": {
73909
+ "package": "himalaya",
73910
+ "type": "Button",
73911
+ "props": {
73912
+ "title": "Delete",
73913
+ "style": "destructive",
73914
+ "action": {
73915
+ "actionId": "tier5.himiOwnerLiteEvent.confirmDelete"
73916
+ }
73917
+ }
73918
+ }
73919
+ }
73920
+ ]
73921
+ }
73922
+ }
73923
+ }
73924
+ ]
73925
+ }
73926
+ },
73927
+ "modifiers": {
73928
+ "background": {
73929
+ "token": "surfaceElevated"
73930
+ },
73931
+ "border": {
73932
+ "width": 1,
73933
+ "color": {
73934
+ "token": "danger"
73935
+ }
73936
+ },
73937
+ "cornerRadius": 12,
73938
+ "padding": {
73939
+ "leading": 14,
73940
+ "trailing": 14,
73941
+ "top": 14,
73942
+ "bottom": 14
73943
+ },
73944
+ "fillMaxWidth": true,
73945
+ "hiddenPath": "$service:himiOwnerLiteEvent.noDeleteConfirmation"
73946
+ }
73947
+ },
73839
73948
  {
73840
73949
  "id": "",
73841
73950
  "body": {
@@ -74697,6 +74806,115 @@ const TEMPLATED: { pattern: string; display: string; liveSeed?: LiveSeed; static
74697
74806
  }
74698
74807
  }
74699
74808
  },
74809
+ {
74810
+ "id": "post_delete_confirmation",
74811
+ "body": {
74812
+ "package": "himalaya",
74813
+ "type": "VStack",
74814
+ "props": {
74815
+ "spacing": 10,
74816
+ "alignment": "leading",
74817
+ "children": [
74818
+ {
74819
+ "id": "post_delete_confirmation.title",
74820
+ "body": {
74821
+ "package": "himalaya",
74822
+ "type": "Text",
74823
+ "props": {
74824
+ "text": "Delete this journal entry?",
74825
+ "style": "bodyEmphasis"
74826
+ }
74827
+ }
74828
+ },
74829
+ {
74830
+ "id": "post_delete_confirmation.record",
74831
+ "body": {
74832
+ "package": "himalaya",
74833
+ "type": "Text",
74834
+ "props": {
74835
+ "text": "$service:himiOwnerLitePost.title",
74836
+ "style": "body",
74837
+ "color": "textSecondary",
74838
+ "maxLines": 2
74839
+ }
74840
+ }
74841
+ },
74842
+ {
74843
+ "id": "",
74844
+ "body": {
74845
+ "package": "himalaya",
74846
+ "type": "Text",
74847
+ "props": {
74848
+ "text": "This cannot be undone.",
74849
+ "style": "footnote",
74850
+ "color": "textSecondary"
74851
+ }
74852
+ }
74853
+ },
74854
+ {
74855
+ "id": "",
74856
+ "body": {
74857
+ "package": "himalaya",
74858
+ "type": "HStack",
74859
+ "props": {
74860
+ "spacing": 8,
74861
+ "children": [
74862
+ {
74863
+ "id": "post_delete_cancel",
74864
+ "body": {
74865
+ "package": "himalaya",
74866
+ "type": "Button",
74867
+ "props": {
74868
+ "title": "Cancel",
74869
+ "style": "secondary",
74870
+ "action": {
74871
+ "actionId": "tier5.himiOwnerLitePost.cancelDelete"
74872
+ }
74873
+ }
74874
+ }
74875
+ },
74876
+ {
74877
+ "id": "post_delete_confirm",
74878
+ "body": {
74879
+ "package": "himalaya",
74880
+ "type": "Button",
74881
+ "props": {
74882
+ "title": "Delete",
74883
+ "style": "destructive",
74884
+ "action": {
74885
+ "actionId": "tier5.himiOwnerLitePost.confirmDelete"
74886
+ }
74887
+ }
74888
+ }
74889
+ }
74890
+ ]
74891
+ }
74892
+ }
74893
+ }
74894
+ ]
74895
+ }
74896
+ },
74897
+ "modifiers": {
74898
+ "background": {
74899
+ "token": "surfaceElevated"
74900
+ },
74901
+ "border": {
74902
+ "width": 1,
74903
+ "color": {
74904
+ "token": "danger"
74905
+ }
74906
+ },
74907
+ "cornerRadius": 12,
74908
+ "padding": {
74909
+ "leading": 14,
74910
+ "trailing": 14,
74911
+ "top": 14,
74912
+ "bottom": 14
74913
+ },
74914
+ "fillMaxWidth": true,
74915
+ "hiddenPath": "$service:himiOwnerLitePost.noDeleteConfirmation"
74916
+ }
74917
+ },
74700
74918
  {
74701
74919
  "id": "",
74702
74920
  "body": {
@@ -62,6 +62,9 @@ interface EventState {
62
62
  /** Non-empty when showing owner-preview-demo sample data (web preview, no owner bridge). */
63
63
  demoNote: string;
64
64
  notDemo: boolean;
65
+ /** #3158 — Delete ARMS a confirmation; only confirmDelete reaches the API. */
66
+ deletePending: boolean;
67
+ noDeleteConfirmation: boolean;
65
68
  }
66
69
 
67
70
  /* eslint-disable @typescript-eslint/no-explicit-any */
@@ -139,6 +142,9 @@ function shape(s: Partial<EventState>): EventState {
139
142
  noCover: !image,
140
143
  demoNote: s.demoNote ?? "",
141
144
  notDemo: !s.demoNote,
145
+ // Only a loaded entity can be pending deletion; every other action disarms it (`disarm`).
146
+ deletePending: !!s.deletePending && hasEntity,
147
+ noDeleteConfirmation: !(s.deletePending && hasEntity),
142
148
  };
143
149
  }
144
150
 
@@ -224,15 +230,32 @@ async function refresh(prev: EventState, id: string): Promise<EventState> {
224
230
  });
225
231
  }
226
232
 
233
+ /** #3158 — a confirmed delete in flight. Synchronous and module-level on purpose: two
234
+ * confirmDelete dispatches (a double tap) both start from a state that says "armed", and only a
235
+ * flag set BEFORE the first await stops the second from issuing its own DELETE — whose late 404
236
+ * would otherwise land after, and overwrite, the first one's "deleted". */
237
+ let deleteInFlight = false;
238
+
239
+ /** #3158 — the confirmation describes THIS visit. Never take it from a persisted snapshot, or a
240
+ * reopened record comes back with "Delete this …?" already armed. */
241
+ const DELETE_RUN_KEYS = ["deletePending", "noDeleteConfirmation"] as const;
242
+
243
+ /** #3158 — clear an armed delete confirmation. */
244
+ const disarm = <T extends { deletePending: boolean }>(s: T): T => ({ ...s, deletePending: false });
245
+
227
246
  const svc = defineService<EventState, {
228
247
  load: (s: EventState, arg?: unknown) => Promise<EventState>;
229
248
  retry: (s: EventState) => Promise<EventState>;
230
249
  delete: (s: EventState) => Promise<EventState>;
250
+ cancelDelete: (s: EventState) => Promise<EventState>;
251
+ confirmDelete: (s: EventState) => Promise<EventState | undefined>;
231
252
  openLink: (s: EventState, arg?: unknown) => Promise<EventState>;
232
253
  }>("himiOwnerLiteEvent", {
233
254
  state: shape({ status: "loading" }),
255
+ notHydrated: [...DELETE_RUN_KEYS],
234
256
  actions: {
235
- load: async (s, arg) => {
257
+ load: async (s0, arg) => {
258
+ const s = disarm(s0);
236
259
  stashCopy(arg); // absorb the descriptor's onAppear copy-pack param
237
260
  const id = idFrom(arg, s.id) || inputId();
238
261
  if (!id) return shape({ ...s, status: "error", error: copyParam("ownerEvent.errorNoId", "no event id") });
@@ -257,7 +280,8 @@ const svc = defineService<EventState, {
257
280
  return shape({ ...s, id, status: "error", error: ownerLoadError(e) });
258
281
  }
259
282
  },
260
- retry: async (s) => {
283
+ retry: async (s0) => {
284
+ const s = disarm(s0);
261
285
  if (!s.id) return shape({ ...s, status: "error", error: copyParam("ownerEvent.errorNoId", "no event id") });
262
286
  if (isOwnerPreviewDemo()) {
263
287
  const demo = demoDetail(s, s.id);
@@ -279,20 +303,35 @@ const svc = defineService<EventState, {
279
303
  return shape({ ...s, status: "error", error: ownerLoadError(e) });
280
304
  }
281
305
  },
282
- delete: async (s) => {
283
- if (isOwnerPreviewDemo() || s.demoNote) return shape({ ...s, actionMessage: copyParam("ownerCommon.demoSaveNote", DEMO_SAVE_NOTE) });
284
- if (!s.id) return shape({ ...s, actionMessage: copyParam("ownerEvent.noIdMessage", "No event id.") });
285
- // Optimistic local delete — the list drops the row immediately.
286
- await cacheDrop(s.id);
306
+ // #3158 — destructive, so two steps. `delete` (the Manage card's Delete button)
307
+ // only ARMS the inline confirmation, which names the record and says it cannot
308
+ // be undone; `cancelDelete` disarms it; only `confirmDelete` deletes. Anything
309
+ // that dispatches `delete` directly therefore still asks first.
310
+ delete: async (s) => shape({ ...s, deletePending: true, actionMessage: "" }),
311
+ cancelDelete: async (s) => shape({ ...s, deletePending: false }),
312
+ confirmDelete: async (s0) => {
313
+ // Nothing armed (a stray dispatch, a rehydrated snapshot) or a delete already running
314
+ // (a second tap): ignore it — `undefined` leaves the state exactly as it is.
315
+ if (!s0.deletePending || deleteInFlight) return undefined;
316
+ deleteInFlight = true;
287
317
  try {
288
- await deleteEvent(s.id);
289
- return shape({ ...s, status: "deleted", title: "", emptyText: copyParam("ownerEvent.deletedEmpty", "Event deleted."), actionMessage: "" });
290
- } catch (e) {
291
- if (shouldQueueOwnerWrite(e)) {
292
- await queueWrite("tier5.himiOwnerLiteEvent.delete", { id: s.id });
293
- return shape({ ...s, status: "deleted", title: "", emptyText: copyParam("ownerEvent.deletedEmpty", "Event deleted."), actionMessage: copyParam("ownerCommon.demoSaveNote", DEMO_SAVE_NOTE) });
318
+ const s = disarm(s0);
319
+ if (isOwnerPreviewDemo() || s.demoNote) return shape({ ...s, actionMessage: copyParam("ownerCommon.demoSaveNote", DEMO_SAVE_NOTE) });
320
+ if (!s.id) return shape({ ...s, actionMessage: copyParam("ownerEvent.noIdMessage", "No event id.") });
321
+ // Optimistic local delete — the list drops the row immediately.
322
+ await cacheDrop(s.id);
323
+ try {
324
+ await deleteEvent(s.id);
325
+ return shape({ ...s, status: "deleted", title: "", emptyText: copyParam("ownerEvent.deletedEmpty", "Event deleted."), actionMessage: "" });
326
+ } catch (e) {
327
+ if (shouldQueueOwnerWrite(e)) {
328
+ await queueWrite("tier5.himiOwnerLiteEvent.delete", { id: s.id });
329
+ return shape({ ...s, status: "deleted", title: "", emptyText: copyParam("ownerEvent.deletedEmpty", "Event deleted."), actionMessage: copyParam("ownerCommon.demoSaveNote", DEMO_SAVE_NOTE) });
330
+ }
331
+ return shape({ ...s, actionMessage: ownerLoadError(e) });
294
332
  }
295
- return shape({ ...s, actionMessage: ownerLoadError(e) });
333
+ } finally {
334
+ deleteInFlight = false;
296
335
  }
297
336
  },
298
337
  // [rico] #3499 — a link tapped in the RichContent description.
@@ -303,4 +342,10 @@ const svc = defineService<EventState, {
303
342
  },
304
343
  });
305
344
 
345
+ // The same reset on a runtime from before `notHydrated` (an older binary on a new bundle).
346
+ if ((globalThis as { himalaya?: { hydrationOptOut?: unknown } }).himalaya?.hydrationOptOut !== true) {
347
+ const booted = svc.getState?.() as unknown as Record<string, unknown> | undefined;
348
+ if (booted && typeof booted === "object") Object.assign(booted, { deletePending: false, noDeleteConfirmation: true });
349
+ }
350
+
306
351
  export { svc };
@@ -80,6 +80,9 @@ interface PostState {
80
80
  /** Non-empty when showing owner-preview-demo sample data (web preview, no owner bridge). */
81
81
  demoNote: string;
82
82
  notDemo: boolean;
83
+ /** #3158 — Delete ARMS a confirmation; only confirmDelete reaches the API. */
84
+ deletePending: boolean;
85
+ noDeleteConfirmation: boolean;
83
86
  }
84
87
 
85
88
  /* eslint-disable @typescript-eslint/no-explicit-any */
@@ -159,6 +162,9 @@ function shape(s: Partial<PostState>): PostState {
159
162
  hideUnpublish: !published || status !== "ready",
160
163
  demoNote: s.demoNote ?? "",
161
164
  notDemo: !s.demoNote,
165
+ // Only a loaded entity can be pending deletion; every other action disarms it (`disarm`).
166
+ deletePending: !!s.deletePending && hasEntity,
167
+ noDeleteConfirmation: !(s.deletePending && hasEntity),
162
168
  };
163
169
  }
164
170
 
@@ -276,18 +282,35 @@ async function refresh(prev: PostState, id: string, actionMessage = ""): Promise
276
282
  });
277
283
  }
278
284
 
285
+ /** #3158 — a confirmed delete in flight. Synchronous and module-level on purpose: two
286
+ * confirmDelete dispatches (a double tap) both start from a state that says "armed", and only a
287
+ * flag set BEFORE the first await stops the second from issuing its own DELETE — whose late 404
288
+ * would otherwise land after, and overwrite, the first one's "deleted". */
289
+ let deleteInFlight = false;
290
+
291
+ /** #3158 — the confirmation describes THIS visit. Never take it from a persisted snapshot, or a
292
+ * reopened record comes back with "Delete this …?" already armed. */
293
+ const DELETE_RUN_KEYS = ["deletePending", "noDeleteConfirmation"] as const;
294
+
295
+ /** #3158 — clear an armed delete confirmation. */
296
+ const disarm = <T extends { deletePending: boolean }>(s: T): T => ({ ...s, deletePending: false });
297
+
279
298
  const svc = defineService<PostState, {
280
299
  load: (s: PostState, arg?: unknown) => Promise<PostState>;
281
300
  retry: (s: PostState) => Promise<PostState>;
282
301
  publish: (s: PostState) => Promise<PostState>;
283
302
  unpublish: (s: PostState) => Promise<PostState>;
284
303
  delete: (s: PostState) => Promise<PostState>;
304
+ cancelDelete: (s: PostState) => Promise<PostState>;
305
+ confirmDelete: (s: PostState) => Promise<PostState | undefined>;
285
306
  /** [rico] #3370 — RichContent's on_link: `{ url }` of the tapped link. */
286
307
  openLink: (s: PostState, arg?: unknown) => Promise<PostState>;
287
308
  }>("himiOwnerLitePost", {
288
309
  state: shape({ status: "loading" }),
310
+ notHydrated: [...DELETE_RUN_KEYS],
289
311
  actions: {
290
- load: async (s, arg) => {
312
+ load: async (s0, arg) => {
313
+ const s = disarm(s0);
291
314
  stashCopy(arg); // absorb the descriptor's onAppear copy-pack param
292
315
  const id = idFrom(arg, s.id) || inputId();
293
316
  if (!id) return shape({ ...s, status: "error", error: copyParam("ownerPost.errorNoId", "no post id") });
@@ -312,7 +335,8 @@ const svc = defineService<PostState, {
312
335
  return shape({ ...s, id, status: "error", error: ownerLoadError(e) });
313
336
  }
314
337
  },
315
- retry: async (s) => {
338
+ retry: async (s0) => {
339
+ const s = disarm(s0);
316
340
  if (!s.id) return shape({ ...s, status: "error", error: copyParam("ownerPost.errorNoId", "no post id") });
317
341
  if (isOwnerPreviewDemo()) {
318
342
  const demo = demoDetail(s, s.id);
@@ -334,7 +358,8 @@ const svc = defineService<PostState, {
334
358
  return shape({ ...s, status: "error", error: ownerLoadError(e) });
335
359
  }
336
360
  },
337
- publish: async (s) => {
361
+ publish: async (s0) => {
362
+ const s = disarm(s0);
338
363
  if (isOwnerPreviewDemo() || s.demoNote) return shape({ ...s, actionMessage: copyParam("ownerCommon.demoSaveNote", DEMO_SAVE_NOTE) });
339
364
  if (!s.id) return shape({ ...s, actionMessage: copyParam("ownerPost.noIdMessage", "No post id.") });
340
365
  if (s.postStatusRaw === "PUBLISHED") return shape({ ...s, actionMessage: copyParam("ownerPost.alreadyPublished", "Post is already published.") });
@@ -352,7 +377,8 @@ const svc = defineService<PostState, {
352
377
  return shape({ ...s, actionMessage: ownerLoadError(e) });
353
378
  }
354
379
  },
355
- unpublish: async (s) => {
380
+ unpublish: async (s0) => {
381
+ const s = disarm(s0);
356
382
  if (isOwnerPreviewDemo() || s.demoNote) return shape({ ...s, actionMessage: copyParam("ownerCommon.demoSaveNote", DEMO_SAVE_NOTE) });
357
383
  if (!s.id) return shape({ ...s, actionMessage: copyParam("ownerPost.noIdMessage", "No post id.") });
358
384
  if (s.postStatusRaw !== "PUBLISHED" && s.postStatusRaw !== "SCHEDULED") {
@@ -372,20 +398,35 @@ const svc = defineService<PostState, {
372
398
  return shape({ ...s, actionMessage: ownerLoadError(e) });
373
399
  }
374
400
  },
375
- delete: async (s) => {
376
- if (isOwnerPreviewDemo() || s.demoNote) return shape({ ...s, actionMessage: copyParam("ownerCommon.demoSaveNote", DEMO_SAVE_NOTE) });
377
- if (!s.id) return shape({ ...s, actionMessage: copyParam("ownerPost.noIdMessage", "No post id.") });
378
- // Optimistic local delete — the list drops the row immediately.
379
- await cacheDrop(s.id);
401
+ // #3158 — destructive, so two steps. `delete` (the Manage card's Delete button)
402
+ // only ARMS the inline confirmation, which names the record and says it cannot
403
+ // be undone; `cancelDelete` disarms it; only `confirmDelete` deletes. Anything
404
+ // that dispatches `delete` directly therefore still asks first.
405
+ delete: async (s) => shape({ ...s, deletePending: true, actionMessage: "" }),
406
+ cancelDelete: async (s) => shape({ ...s, deletePending: false }),
407
+ confirmDelete: async (s0) => {
408
+ // Nothing armed (a stray dispatch, a rehydrated snapshot) or a delete already running
409
+ // (a second tap): ignore it — `undefined` leaves the state exactly as it is.
410
+ if (!s0.deletePending || deleteInFlight) return undefined;
411
+ deleteInFlight = true;
380
412
  try {
381
- await deleteDraftPost(s.id);
382
- return shape({ ...s, status: "deleted", title: "", emptyText: copyParam("ownerPost.deletedEmpty", "Post deleted."), actionMessage: "" });
383
- } catch (e) {
384
- if (shouldQueueOwnerWrite(e)) {
385
- await queueWrite("tier5.himiOwnerLitePost.delete", { id: s.id });
386
- return shape({ ...s, status: "deleted", title: "", emptyText: copyParam("ownerPost.deletedEmpty", "Post deleted."), actionMessage: copyParam("ownerCommon.demoSaveNote", DEMO_SAVE_NOTE) });
413
+ const s = disarm(s0);
414
+ if (isOwnerPreviewDemo() || s.demoNote) return shape({ ...s, actionMessage: copyParam("ownerCommon.demoSaveNote", DEMO_SAVE_NOTE) });
415
+ if (!s.id) return shape({ ...s, actionMessage: copyParam("ownerPost.noIdMessage", "No post id.") });
416
+ // Optimistic local delete — the list drops the row immediately.
417
+ await cacheDrop(s.id);
418
+ try {
419
+ await deleteDraftPost(s.id);
420
+ return shape({ ...s, status: "deleted", title: "", emptyText: copyParam("ownerPost.deletedEmpty", "Post deleted."), actionMessage: "" });
421
+ } catch (e) {
422
+ if (shouldQueueOwnerWrite(e)) {
423
+ await queueWrite("tier5.himiOwnerLitePost.delete", { id: s.id });
424
+ return shape({ ...s, status: "deleted", title: "", emptyText: copyParam("ownerPost.deletedEmpty", "Post deleted."), actionMessage: copyParam("ownerCommon.demoSaveNote", DEMO_SAVE_NOTE) });
425
+ }
426
+ return shape({ ...s, actionMessage: ownerLoadError(e) });
387
427
  }
388
- return shape({ ...s, actionMessage: ownerLoadError(e) });
428
+ } finally {
429
+ deleteInFlight = false;
389
430
  }
390
431
  },
391
432
  // Only http(s), mailto and tel links reach open_url; a refused link, or one nothing opened, says so, and
@@ -397,4 +438,10 @@ const svc = defineService<PostState, {
397
438
  },
398
439
  });
399
440
 
441
+ // The same reset on a runtime from before `notHydrated` (an older binary on a new bundle).
442
+ if ((globalThis as { himalaya?: { hydrationOptOut?: unknown } }).himalaya?.hydrationOptOut !== true) {
443
+ const booted = svc.getState?.() as unknown as Record<string, unknown> | undefined;
444
+ if (booted && typeof booted === "object") Object.assign(booted, { deletePending: false, noDeleteConfirmation: true });
445
+ }
446
+
400
447
  export { svc };