kaafil-react-uikit 0.3.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.
@@ -177,6 +177,43 @@ 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
+ }
180
217
  function appendPendingRows(fromAggregate, fromSnapshot) {
181
218
  if (fromSnapshot.length === 0) {
182
219
  return fromAggregate;
@@ -284,28 +321,7 @@ var useChecklistsInternal = createDomainHook("checklists", (tripRef) => {
284
321
  // yet resolves to `''` and the row sits ungrouped until the write
285
322
  // lands — correct rather than clever: inventing a section id would
286
323
  // put the item under a heading that does not exist.
287
- optimistic: {
288
- id: "pending",
289
- version: 0,
290
- sectionId: aggregate.sections.find((section) => section.key === input.sectionKey)?.id ?? "",
291
- key: input.key ?? null,
292
- title: input.title,
293
- subLine: null,
294
- status: "OPEN",
295
- // `=== true`, never `?? false` (hard rule #5): an omitted
296
- // `mandatory` is the SERVER's default to apply, not this hook's to
297
- // guess. The optimistic row shows it unstarred for the moment it
298
- // takes the write to land, and the canonical row replaces it.
299
- isMandatory: input.mandatory === true,
300
- gate: null,
301
- dayOffset: null,
302
- sortOrder: Number.MAX_SAFE_INTEGER,
303
- completedByManagerId: null,
304
- performedByKind: null,
305
- performedById: null,
306
- completedAt: null,
307
- updatedAt: null
308
- }
324
+ optimistic: optimisticChecklistItem(input, aggregate.sections, aggregate.fetchedAt)
309
325
  }),
310
326
  // ── THE DESK LANE ─────────────────────────────────────────────────
311
327
  // All five checklist writes take the admin triple, and a desk console
@@ -540,6 +556,34 @@ var useCloseoutInternal = createDomainHook("closing-day", (tripRef) => {
540
556
  function useCloseout(tripRef) {
541
557
  return useCloseoutInternal(tripRef);
542
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
+ }
543
587
  var useCollectionsInternal = createDomainHook("collections", (tripRef) => {
544
588
  const client$1 = chunkUALMCHNW_cjs.useKaafilClient();
545
589
  const {
@@ -589,7 +633,12 @@ var useCollectionsInternal = createDomainHook("collections", (tripRef) => {
589
633
  // hardcoded literal, verified against
590
634
  // `kaafil-js/src/generated/security.ts` this session.
591
635
  operationId: "recordCollection",
592
- 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)
593
642
  }),
594
643
  // The desk lane. `recordCollection` takes the admin triple, and a desk
595
644
  // console mounts no `OfflineShell` — without this the write has no
@@ -1577,6 +1626,34 @@ function useParties(tripRef) {
1577
1626
  remove
1578
1627
  };
1579
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
+ }
1580
1657
  var usePickupsInternal = createDomainHook("pickup-points", (tripRef) => {
1581
1658
  const client$1 = chunkUALMCHNW_cjs.useKaafilClient();
1582
1659
  const {
@@ -1600,7 +1677,14 @@ var usePickupsInternal = createDomainHook("pickup-points", (tripRef) => {
1600
1677
  // literal below is checked against `kaafil-js/src/generated/
1601
1678
  // security.ts`'s own operation-id table.
1602
1679
  operationId: "createPickupStop",
1603
- 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)
1604
1688
  }),
1605
1689
  // The desk lane. `board`, `close` and `reopen` below deliberately get
1606
1690
  // NONE — they are `managerAuth`-only on the wire, so a direct call from
@@ -1746,6 +1830,24 @@ var usePickupsInternal = createDomainHook("pickup-points", (tripRef) => {
1746
1830
  function usePickups(tripRef) {
1747
1831
  return usePickupsInternal(tripRef);
1748
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
+ }
1749
1851
  var useRoomingInternal = createDomainHook("rooming", (tripRef) => {
1750
1852
  const client$1 = chunkUALMCHNW_cjs.useKaafilClient();
1751
1853
  const {
@@ -1833,7 +1935,14 @@ var useRoomingInternal = createDomainHook("rooming", (tripRef) => {
1833
1935
  method: client.SyncOpMethod.Post,
1834
1936
  path: `/api/v1/trips/${tripRef}/rooming/stay-windows`,
1835
1937
  operationId: "createRoomingStayWindow",
1836
- 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)
1837
1946
  }),
1838
1947
  direct: (liveClient, input) => liveClient.rooming.stayWindows.create({ tripRef, ...input })
1839
1948
  });
@@ -2262,5 +2371,5 @@ exports.useSeating = useSeating;
2262
2371
  exports.useSnapshotList = useSnapshotList;
2263
2372
  exports.useTravellerProfile = useTravellerProfile;
2264
2373
  exports.useVendors = useVendors;
2265
- //# sourceMappingURL=chunk-MNUCVVIE.cjs.map
2266
- //# sourceMappingURL=chunk-MNUCVVIE.cjs.map
2374
+ //# sourceMappingURL=chunk-6TI6YQPE.cjs.map
2375
+ //# sourceMappingURL=chunk-6TI6YQPE.cjs.map