kaafil-react-uikit 0.2.0 → 0.3.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 (35) hide show
  1. package/dist/admin/index.cjs +73 -73
  2. package/dist/admin/index.js +3 -3
  3. package/dist/{chunk-6WV5VYT2.cjs → chunk-6TI6YQPE.cjs} +171 -7
  4. package/dist/chunk-6TI6YQPE.cjs.map +1 -0
  5. package/dist/{chunk-RG4YDSCN.cjs → chunk-BBC5EX5O.cjs} +4 -4
  6. package/dist/{chunk-RG4YDSCN.cjs.map → chunk-BBC5EX5O.cjs.map} +1 -1
  7. package/dist/{chunk-7UFX3Y2U.cjs → chunk-ECCQW5LN.cjs} +5 -2
  8. package/dist/chunk-ECCQW5LN.cjs.map +1 -0
  9. package/dist/{chunk-OZJ74DVQ.cjs → chunk-HACH2NUM.cjs} +3 -3
  10. package/dist/chunk-HACH2NUM.cjs.map +1 -0
  11. package/dist/{chunk-HTIY33UH.cjs → chunk-IU2UM5JP.cjs} +21 -21
  12. package/dist/{chunk-HTIY33UH.cjs.map → chunk-IU2UM5JP.cjs.map} +1 -1
  13. package/dist/{chunk-RSC2ZJUP.js → chunk-JHMN6Q5R.js} +172 -8
  14. package/dist/chunk-JHMN6Q5R.js.map +1 -0
  15. package/dist/{chunk-SIAPCJ7G.js → chunk-RO2RNHQP.js} +4 -4
  16. package/dist/{chunk-SIAPCJ7G.js.map → chunk-RO2RNHQP.js.map} +1 -1
  17. package/dist/{chunk-7ISKFGLW.js → chunk-RWLO6IFX.js} +3 -3
  18. package/dist/chunk-RWLO6IFX.js.map +1 -0
  19. package/dist/{chunk-L3QEMEFM.js → chunk-VLP323AD.js} +5 -2
  20. package/dist/chunk-VLP323AD.js.map +1 -0
  21. package/dist/{chunk-LJJMNZ7B.js → chunk-YU2242AR.js} +3 -3
  22. package/dist/{chunk-LJJMNZ7B.js.map → chunk-YU2242AR.js.map} +1 -1
  23. package/dist/core/index.cjs +56 -56
  24. package/dist/core/index.js +7 -7
  25. package/dist/manager/index.cjs +48 -48
  26. package/dist/manager/index.js +2 -2
  27. package/dist/traveller/index.cjs +4 -4
  28. package/dist/traveller/index.js +2 -2
  29. package/package.json +2 -2
  30. package/dist/chunk-6WV5VYT2.cjs.map +0 -1
  31. package/dist/chunk-7ISKFGLW.js.map +0 -1
  32. package/dist/chunk-7UFX3Y2U.cjs.map +0 -1
  33. package/dist/chunk-L3QEMEFM.js.map +0 -1
  34. package/dist/chunk-OZJ74DVQ.cjs.map +0 -1
  35. package/dist/chunk-RSC2ZJUP.js.map +0 -1
@@ -177,6 +177,51 @@ function createDomainHook(moduleKey, build) {
177
177
  }
178
178
 
179
179
  // src/core/hooks/useChecklists.ts
180
+ function optimisticChecklistItem(input, sections, fetchedAt) {
181
+ return {
182
+ // Replaced by the id the engine mints — this hook never invents identity.
183
+ id: "pending",
184
+ // Cannot beat any server row in the snapshot's version-guarded merge.
185
+ version: 0,
186
+ // The write addresses a section by KEY; the board groups rows by ID. An
187
+ // unknown section leaves the row ungrouped rather than filing it under a
188
+ // heading that does not exist.
189
+ sectionId: sections.find((section) => section.key === input.sectionKey)?.id ?? "",
190
+ // The server derives the key from the title when one is not sent. Blank
191
+ // rather than a guessed slug: a key that disagrees with the server's is
192
+ // worse than an obviously-absent one, and nothing renders it.
193
+ key: input.key ?? "",
194
+ title: input.title,
195
+ subLine: null,
196
+ status: "OPEN",
197
+ // `=== true`, never `?? false` (hard rule #5): an omitted `mandatory` is
198
+ // the SERVER's default to apply, not this hook's to guess.
199
+ isMandatory: input.mandatory === true,
200
+ // `'NONE'`, never null. The add request carries no `gate` at all — the
201
+ // engine derives it from `phase` — and `'NONE'` is the one value that
202
+ // cannot make a pending item look like it is blocking the trip.
203
+ gate: "NONE",
204
+ dayOffset: null,
205
+ // Appended. The server's own ordering arrives with the canonical row.
206
+ sortOrder: Number.MAX_SAFE_INTEGER,
207
+ completedByManagerId: null,
208
+ performedByKind: null,
209
+ performedById: null,
210
+ completedAt: null,
211
+ // The last reading the SERVER gave this hook, never a device clock (hard
212
+ // rule #6). Blank when nothing has been fetched yet, which is the only
213
+ // honest answer and which the board already prefers `fetchedAt` over.
214
+ updatedAt: fetchedAt ?? ""
215
+ };
216
+ }
217
+ function appendPendingRows(fromAggregate, fromSnapshot) {
218
+ if (fromSnapshot.length === 0) {
219
+ return fromAggregate;
220
+ }
221
+ const known = new Set(fromAggregate.map((row) => row.id));
222
+ const pending = fromSnapshot.filter((row) => !known.has(row.id));
223
+ return pending.length === 0 ? fromAggregate : [...fromAggregate, ...pending];
224
+ }
180
225
  var useChecklistsInternal = createDomainHook("checklists", (tripRef) => {
181
226
  const client$1 = chunkUALMCHNW_cjs.useKaafilClient();
182
227
  const engine = react.useContext(chunkUALMCHNW_cjs.OfflineEngineContext);
@@ -250,7 +295,33 @@ var useChecklistsInternal = createDomainHook("checklists", (tripRef) => {
250
295
  method: client.SyncOpMethod.Post,
251
296
  path: `/api/v1/trips/${tripRef}/checklist/items`,
252
297
  operationId: "addChecklistItem",
253
- body: input
298
+ body: input,
299
+ // ── THE OPTIMISTIC CREATE ──────────────────────────────────────
300
+ // Without this the item a manager adds out of signal does not
301
+ // appear until it syncs. It was queued, durable and landed on
302
+ // reconnect the whole time — and from where the manager is
303
+ // standing, work that does not show up is work that was lost, so
304
+ // they add it again.
305
+ //
306
+ // `creates` makes the ENGINE mint the row's temporary id (this
307
+ // hook never invents identifiers) and swap it for the server's
308
+ // canonical row the moment the write lands, in one
309
+ // `snapshot.updated`, so the item is never rendered twice.
310
+ creates: true,
311
+ entity: { listName: "checklist" },
312
+ // Shaped as a real `ChecklistItemDeltaRow` so the board renders it
313
+ // through the same path as every other row rather than a special
314
+ // "pending" branch. `id` is a placeholder the engine replaces with
315
+ // the id it mints; `version: 0` cannot beat any server row in the
316
+ // snapshot's version-guarded merge.
317
+ //
318
+ // The write addresses a section by its `sectionKey`, but the board
319
+ // groups rows by `sectionId`, so the id is resolved from the sections
320
+ // this hook already holds. Adding to a section that does not exist
321
+ // yet resolves to `''` and the row sits ungrouped until the write
322
+ // lands — correct rather than clever: inventing a section id would
323
+ // put the item under a heading that does not exist.
324
+ optimistic: optimisticChecklistItem(input, aggregate.sections, aggregate.fetchedAt)
254
325
  }),
255
326
  // ── THE DESK LANE ─────────────────────────────────────────────────
256
327
  // All five checklist writes take the admin triple, and a desk console
@@ -392,7 +463,7 @@ var useChecklistsInternal = createDomainHook("checklists", (tripRef) => {
392
463
  (input) => client$1.checklists.agencyTemplates.publish(input),
393
464
  [client$1]
394
465
  );
395
- const items = syncedAt === void 0 ? aggregate.items : snapshotItems;
466
+ const items = syncedAt === void 0 ? appendPendingRows(aggregate.items, snapshotItems) : snapshotItems;
396
467
  return {
397
468
  items,
398
469
  syncedAt,
@@ -485,6 +556,34 @@ var useCloseoutInternal = createDomainHook("closing-day", (tripRef) => {
485
556
  function useCloseout(tripRef) {
486
557
  return useCloseoutInternal(tripRef);
487
558
  }
559
+ function optimisticCollection(input, syncedAt) {
560
+ const collectedAt = input.collectedAt === void 0 ? "" : client.normalizeDateTimeInput(input.collectedAt, "collectedAt");
561
+ return {
562
+ // Replaced by the id the engine mints.
563
+ id: "pending",
564
+ version: 0,
565
+ travellerId: input.travellerId,
566
+ amountMinor: input.amountMinor,
567
+ // The request's own default, restated: this tenant's money unit.
568
+ currency: input.currency ?? "INR",
569
+ mode: input.mode,
570
+ reference: input.reference ?? null,
571
+ note: input.note ?? null,
572
+ collectedByManagerId: null,
573
+ performedByKind: null,
574
+ performedById: null,
575
+ collectedAt,
576
+ reportedAt: null,
577
+ voidedAt: null,
578
+ voidReason: null,
579
+ // The server's arithmetic, deliberately not guessed — see above.
580
+ outstandingMinor: null,
581
+ // The last reading the SERVER gave this list, never a device clock
582
+ // (hard rule #6).
583
+ createdAt: syncedAt ?? "",
584
+ updatedAt: syncedAt ?? ""
585
+ };
586
+ }
488
587
  var useCollectionsInternal = createDomainHook("collections", (tripRef) => {
489
588
  const client$1 = chunkUALMCHNW_cjs.useKaafilClient();
490
589
  const {
@@ -534,7 +633,12 @@ var useCollectionsInternal = createDomainHook("collections", (tripRef) => {
534
633
  // hardcoded literal, verified against
535
634
  // `kaafil-js/src/generated/security.ts` this session.
536
635
  operationId: "recordCollection",
537
- body: input
636
+ body: input,
637
+ // A payment recorded out of signal appears at once — see
638
+ // `optimisticCollection` for what it deliberately does not claim.
639
+ creates: true,
640
+ entity: { listName: "collections" },
641
+ optimistic: optimisticCollection(input, syncedAt)
538
642
  }),
539
643
  // The desk lane. `recordCollection` takes the admin triple, and a desk
540
644
  // console mounts no `OfflineShell` — without this the write has no
@@ -1522,6 +1626,34 @@ function useParties(tripRef) {
1522
1626
  remove
1523
1627
  };
1524
1628
  }
1629
+ function optimisticPickupStop(input, syncedAt) {
1630
+ return {
1631
+ // Replaced by the id the engine mints.
1632
+ id: "pending",
1633
+ version: 0,
1634
+ // The request's own default, restated rather than guessed: the SDK's
1635
+ // `kind` is optional and the engine treats an absent one as a pickup.
1636
+ kind: input.kind ?? "PICKUP",
1637
+ name: input.name,
1638
+ locationLabel: input.locationLabel ?? null,
1639
+ lat: input.lat ?? null,
1640
+ lng: input.lng ?? null,
1641
+ scheduledTime: client.normalizeDateTimeInput(input.scheduledTime, "scheduledTime"),
1642
+ // Appended; the server's ordering arrives with the canonical row.
1643
+ sortOrder: input.sortOrder ?? Number.MAX_SAFE_INTEGER,
1644
+ status: "OPEN",
1645
+ closedAt: null,
1646
+ closedByManagerId: null,
1647
+ performedByKind: null,
1648
+ performedById: null,
1649
+ rollup: "not_started",
1650
+ boardedCount: 0,
1651
+ expectedCount: 0,
1652
+ // The last reading the SERVER gave this list, never a device clock
1653
+ // (hard rule #6).
1654
+ updatedAt: syncedAt ?? ""
1655
+ };
1656
+ }
1525
1657
  var usePickupsInternal = createDomainHook("pickup-points", (tripRef) => {
1526
1658
  const client$1 = chunkUALMCHNW_cjs.useKaafilClient();
1527
1659
  const {
@@ -1545,7 +1677,14 @@ var usePickupsInternal = createDomainHook("pickup-points", (tripRef) => {
1545
1677
  // literal below is checked against `kaafil-js/src/generated/
1546
1678
  // security.ts`'s own operation-id table.
1547
1679
  operationId: "createPickupStop",
1548
- body: input
1680
+ body: input,
1681
+ // A stop added out of signal appears at once, keyed on an id the
1682
+ // ENGINE mints and swapped for the server's row when the write lands
1683
+ // — see `optimisticPickupStop` for why every field here is one the
1684
+ // client can honestly know.
1685
+ creates: true,
1686
+ entity: { listName: "pickups" },
1687
+ optimistic: optimisticPickupStop(input, syncedAt)
1549
1688
  }),
1550
1689
  // The desk lane. `board`, `close` and `reopen` below deliberately get
1551
1690
  // NONE — they are `managerAuth`-only on the wire, so a direct call from
@@ -1691,6 +1830,24 @@ var usePickupsInternal = createDomainHook("pickup-points", (tripRef) => {
1691
1830
  function usePickups(tripRef) {
1692
1831
  return usePickupsInternal(tripRef);
1693
1832
  }
1833
+ function optimisticStayWindow(input, syncedAt) {
1834
+ return {
1835
+ // Replaced by the id the engine mints.
1836
+ id: "pending",
1837
+ version: 0,
1838
+ label: input.label,
1839
+ startDate: client.normalizeDateTimeInput(input.startDate, "startDate"),
1840
+ endDate: client.normalizeDateTimeInput(input.endDate, "endDate"),
1841
+ // Appended; the server's ordering arrives with the canonical row.
1842
+ sortOrder: input.sortOrder ?? Number.MAX_SAFE_INTEGER,
1843
+ // A window created by hand has no CRM segment behind it. This is a fact
1844
+ // about the write, not a placeholder.
1845
+ sourceSegmentRef: null,
1846
+ sourceUpdatedAt: null,
1847
+ // The last reading the SERVER gave this list, never a device clock.
1848
+ updatedAt: syncedAt ?? ""
1849
+ };
1850
+ }
1694
1851
  var useRoomingInternal = createDomainHook("rooming", (tripRef) => {
1695
1852
  const client$1 = chunkUALMCHNW_cjs.useKaafilClient();
1696
1853
  const {
@@ -1778,7 +1935,14 @@ var useRoomingInternal = createDomainHook("rooming", (tripRef) => {
1778
1935
  method: client.SyncOpMethod.Post,
1779
1936
  path: `/api/v1/trips/${tripRef}/rooming/stay-windows`,
1780
1937
  operationId: "createRoomingStayWindow",
1781
- body: input
1938
+ body: input,
1939
+ // A window added out of signal appears at once. Every field of a
1940
+ // stay window is either given by the caller or genuinely absent —
1941
+ // which is exactly what `createRoom` below cannot say, and why only
1942
+ // this one of the two gets an optimistic row.
1943
+ creates: true,
1944
+ entity: { listName: "stayWindows" },
1945
+ optimistic: optimisticStayWindow(input, windowsSyncedAt)
1782
1946
  }),
1783
1947
  direct: (liveClient, input) => liveClient.rooming.stayWindows.create({ tripRef, ...input })
1784
1948
  });
@@ -2207,5 +2371,5 @@ exports.useSeating = useSeating;
2207
2371
  exports.useSnapshotList = useSnapshotList;
2208
2372
  exports.useTravellerProfile = useTravellerProfile;
2209
2373
  exports.useVendors = useVendors;
2210
- //# sourceMappingURL=chunk-6WV5VYT2.cjs.map
2211
- //# sourceMappingURL=chunk-6WV5VYT2.cjs.map
2374
+ //# sourceMappingURL=chunk-6TI6YQPE.cjs.map
2375
+ //# sourceMappingURL=chunk-6TI6YQPE.cjs.map