@superbright/indexeddb-orm 1.0.29 → 1.0.31

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 (58) hide show
  1. package/dist/adapters/structured-store.cjs +1 -1
  2. package/dist/adapters/structured-store.cjs.map +1 -1
  3. package/dist/adapters/structured-store.d.ts +1 -0
  4. package/dist/adapters/structured-store.mjs +8 -7
  5. package/dist/adapters/structured-store.mjs.map +1 -1
  6. package/dist/adapters/zustand-store.cjs +1 -1
  7. package/dist/adapters/zustand-store.cjs.map +1 -1
  8. package/dist/adapters/zustand-store.d.ts +3 -6
  9. package/dist/adapters/zustand-store.mjs +212 -164
  10. package/dist/adapters/zustand-store.mjs.map +1 -1
  11. package/dist/base/enums.cjs +1 -1
  12. package/dist/base/enums.cjs.map +1 -1
  13. package/dist/base/enums.d.ts +4 -0
  14. package/dist/base/enums.mjs +2 -1
  15. package/dist/base/enums.mjs.map +1 -1
  16. package/dist/base/userinquiry.d.ts +23 -0
  17. package/dist/base/visitor.d.ts +17 -0
  18. package/dist/base/visitorfilter.d.ts +25 -0
  19. package/dist/base/visitorquestionnaire.d.ts +25 -0
  20. package/dist/base/visitorunitengagement.d.ts +24 -0
  21. package/dist/features/units/transformers.cjs.map +1 -1
  22. package/dist/features/units/transformers.d.ts +2 -0
  23. package/dist/features/units/transformers.mjs.map +1 -1
  24. package/dist/index.cjs +1 -1
  25. package/dist/index.d.ts +1 -5
  26. package/dist/index.mjs +111 -127
  27. package/dist/index.mjs.map +1 -1
  28. package/dist/schema.cjs +1 -1
  29. package/dist/schema.cjs.map +1 -1
  30. package/dist/schema.d.ts +13 -41
  31. package/dist/schema.mjs +63 -74
  32. package/dist/schema.mjs.map +1 -1
  33. package/dist/stores/store.cjs +1 -1
  34. package/dist/stores/store.cjs.map +1 -1
  35. package/dist/stores/store.d.ts +3 -14
  36. package/dist/stores/store.mjs +58 -86
  37. package/dist/stores/store.mjs.map +1 -1
  38. package/package.json +1 -1
  39. package/dist/api/favorites.cjs +0 -2
  40. package/dist/api/favorites.cjs.map +0 -1
  41. package/dist/api/favorites.d.ts +0 -4
  42. package/dist/api/favorites.mjs +0 -34
  43. package/dist/api/favorites.mjs.map +0 -1
  44. package/dist/api/properties.cjs +0 -2
  45. package/dist/api/properties.cjs.map +0 -1
  46. package/dist/api/properties.d.ts +0 -22
  47. package/dist/api/properties.mjs +0 -197
  48. package/dist/api/properties.mjs.map +0 -1
  49. package/dist/api/users.cjs +0 -2
  50. package/dist/api/users.cjs.map +0 -1
  51. package/dist/api/users.d.ts +0 -5
  52. package/dist/api/users.mjs +0 -54
  53. package/dist/api/users.mjs.map +0 -1
  54. package/dist/units/favorites.cjs +0 -2
  55. package/dist/units/favorites.cjs.map +0 -1
  56. package/dist/units/favorites.d.ts +0 -7
  57. package/dist/units/favorites.mjs +0 -19
  58. package/dist/units/favorites.mjs.map +0 -1
@@ -1,13 +1,13 @@
1
- import { kvGet as S, kvSet as P } from "../storage.mjs";
2
- import { UnifiedStoreDataSchema as f, UserPropertyStateSchema as v, UnitSchema as g, PropertySchema as h } from "../schema.mjs";
1
+ import { kvGet as y, kvSet as h } from "../storage.mjs";
2
+ import { UnifiedStoreDataSchema as w, UserPropertyStateSchema as m, UnitSchema as g, PropertySchema as f } from "../schema.mjs";
3
3
  import { validate as d } from "../validation.mjs";
4
- import { transformFiltersToUnitsSearchParams as m } from "../features/filters/transformers.mjs";
5
- const w = {
4
+ import { transformFiltersToUnitsSearchParams as v } from "../features/filters/transformers.mjs";
5
+ const P = {
6
6
  date_availability: void 0,
7
7
  qty_bedrooms: void 0,
8
8
  base_price: void 0,
9
9
  highlights: void 0
10
- }, y = {
10
+ }, S = {
11
11
  // Property data
12
12
  properties: {},
13
13
  currentPropertyId: null,
@@ -15,8 +15,8 @@ const w = {
15
15
  hasPreviouslySearched: [],
16
16
  // App data
17
17
  unitResults: [],
18
- filters: w,
19
- tempFilters: w,
18
+ filters: P,
19
+ tempFilters: P,
20
20
  apiFilters: {
21
21
  limit: 10,
22
22
  page: 1,
@@ -32,21 +32,21 @@ class U {
32
32
  * and sanitizing invalid entries where possible.
33
33
  */
34
34
  async getState() {
35
- const t = await S("app");
35
+ const t = await y("app");
36
36
  if (!t)
37
- return y;
37
+ return S;
38
38
  const e = {
39
- ...y,
39
+ ...S,
40
40
  ...t,
41
41
  properties: t.properties ?? {},
42
42
  unitResults: t.unitResults ?? [],
43
43
  currentPropertyId: t.currentPropertyId == null ? null : String(t.currentPropertyId),
44
44
  currentPropertySlug: t.currentPropertySlug ?? null,
45
45
  hasPreviouslySearched: Array.isArray(t.hasPreviouslySearched) ? t.hasPreviouslySearched.map(String) : []
46
- }, r = f.safeParse(e);
46
+ }, r = w.safeParse(e);
47
47
  if (r.success) return r.data;
48
48
  const s = Object.entries(e.properties ?? {}).reduce((p, [u, c]) => {
49
- const l = v.safeParse(c);
49
+ const l = m.safeParse(c);
50
50
  return l.success && (p[u] = l.data), p;
51
51
  }, {}), i = (Array.isArray(e.unitResults) ? e.unitResults : e.unitResults && typeof e.unitResults == "object" ? Object.values(e.unitResults) : []).reduce((p, u) => {
52
52
  const c = g.safeParse(u);
@@ -55,8 +55,8 @@ class U {
55
55
  ...e,
56
56
  properties: s,
57
57
  unitResults: i
58
- }, o = f.safeParse(a);
59
- return o.success ? o.data : y;
58
+ }, n = w.safeParse(a);
59
+ return n.success ? n.data : S;
60
60
  }
61
61
  /**
62
62
  * Applies an updater function to the current store state, validates the result, and persists it.
@@ -64,8 +64,8 @@ class U {
64
64
  * @param updater - Pure function that maps the current state to the next state.
65
65
  */
66
66
  async setState(t) {
67
- const e = await this.getState(), r = t(e), s = f.parse(r);
68
- await P("app", s);
67
+ const e = await this.getState(), r = t(e), s = w.parse(r);
68
+ await h("app", s);
69
69
  }
70
70
  /**
71
71
  * Polls the persisted state until a current property pointer is available or the timeout elapses.
@@ -77,8 +77,8 @@ class U {
77
77
  async waitForCurrentProperty(t = 1e3) {
78
78
  const e = Date.now() + t;
79
79
  for (; Date.now() < e; ) {
80
- const n = await this.getState(), i = n.currentPropertyId;
81
- if (i && n.properties[i]) return i;
80
+ const o = await this.getState(), i = o.currentPropertyId;
81
+ if (i && o.properties[i]) return i;
82
82
  await new Promise((a) => setTimeout(a, 16));
83
83
  }
84
84
  const r = await this.getState(), s = r.currentPropertyId;
@@ -126,8 +126,8 @@ class U {
126
126
  async setUnitResults(t, e) {
127
127
  const r = e ?? g, s = [];
128
128
  (Array.isArray(t) ? t : t && typeof t == "object" ? Object.values(t) : []).forEach((i, a) => {
129
- const o = d(r, i, `unitResults[${a}]`);
130
- o && s.push(o);
129
+ const n = d(r, i, `unitResults[${a}]`);
130
+ n && s.push(n);
131
131
  }), await this.setState((i) => ({
132
132
  ...i,
133
133
  unitResults: s
@@ -151,18 +151,18 @@ class U {
151
151
  * @param schema - Optional schema override used for validation.
152
152
  */
153
153
  async setPropertyData(t, e, r) {
154
- const s = String(t), n = r ?? h;
154
+ const s = String(t), o = r ?? f;
155
155
  await this.setState((i) => {
156
156
  const a = i.properties[s];
157
157
  if (!a) return i;
158
- const o = d(n, e, `properties.${s}.data`);
159
- return o ? {
158
+ const n = d(o, e, `properties.${s}.data`);
159
+ return n ? {
160
160
  ...i,
161
161
  properties: {
162
162
  ...i.properties,
163
163
  [s]: {
164
164
  ...a,
165
- data: o
165
+ data: n
166
166
  }
167
167
  }
168
168
  } : i;
@@ -176,13 +176,13 @@ class U {
176
176
  * @param schema - Optional schema override for validation.
177
177
  */
178
178
  async mergePropertyData(t, e, r) {
179
- const s = String(t), n = r ?? h;
179
+ const s = String(t), o = r ?? f;
180
180
  await this.setState((i) => {
181
181
  const a = i.properties[s];
182
182
  if (!a) return i;
183
- const o = a.data;
184
- if (!o) {
185
- const l = d(n, e, `properties.${s}.data`);
183
+ const n = a.data;
184
+ if (!n) {
185
+ const l = d(o, e, `properties.${s}.data`);
186
186
  return l ? {
187
187
  ...i,
188
188
  properties: {
@@ -194,15 +194,15 @@ class U {
194
194
  }
195
195
  } : i;
196
196
  }
197
- const p = n.partial(), u = d(
197
+ const p = o.partial(), u = d(
198
198
  p,
199
199
  e,
200
200
  `properties.${s}.data.partial`
201
201
  );
202
202
  if (!u) return i;
203
203
  const c = d(
204
- n,
205
- { ...o, ...u },
204
+ o,
205
+ { ...n, ...u },
206
206
  `properties.${s}.data`
207
207
  );
208
208
  return c ? {
@@ -226,12 +226,12 @@ class U {
226
226
  * @param schema - Optional schema override.
227
227
  */
228
228
  async upsertPropertyFromApi(t, e) {
229
- const s = (e ?? h).parse(t), n = s.id ?? s.propertyId;
230
- if (n == null)
229
+ const s = (e ?? f).parse(t), o = s.id ?? s.propertyId;
230
+ if (o == null)
231
231
  throw new Error("upsertPropertyFromApi: property id is required");
232
- const i = String(n), a = s.slug ?? void 0;
233
- await this.setState((o) => {
234
- const p = o.properties[i], u = p ? {
232
+ const i = String(o), a = s.slug ?? void 0;
233
+ await this.setState((n) => {
234
+ const p = n.properties[i], u = p ? {
235
235
  ...p,
236
236
  ...a ? { slug: a } : {},
237
237
  data: s
@@ -246,9 +246,9 @@ class U {
246
246
  data: s
247
247
  };
248
248
  return {
249
- ...o,
249
+ ...n,
250
250
  properties: {
251
- ...o.properties,
251
+ ...n.properties,
252
252
  [i]: u
253
253
  }
254
254
  };
@@ -292,30 +292,6 @@ class U {
292
292
  )
293
293
  }));
294
294
  }
295
- /**
296
- * Toggles a unit's favorite state for the currently active property.
297
- *
298
- * @param unitId - Unit identifier to toggle.
299
- */
300
- async toggleFavorite(t) {
301
- await this.setState((e) => {
302
- const r = e.currentPropertyId;
303
- if (!r) return e;
304
- const s = e.properties[r];
305
- if (!s) return e;
306
- const i = s.favoritedUnits.includes(t) ? s.favoritedUnits.filter((a) => a !== t) : [...s.favoritedUnits, t];
307
- return {
308
- ...e,
309
- properties: {
310
- ...e.properties,
311
- [r]: {
312
- ...s,
313
- favoritedUnits: i
314
- }
315
- }
316
- };
317
- });
318
- }
319
295
  /**
320
296
  * Records the most recent view date for a unit and opens the unit URL in the browser when available.
321
297
  *
@@ -325,25 +301,25 @@ class U {
325
301
  async markUnitAsViewed(t, e) {
326
302
  const r = `https://${e}`;
327
303
  window.open(r, "_blank", "noopener,noreferrer");
328
- const s = /* @__PURE__ */ new Date(), n = `${String(s.getMonth() + 1).padStart(
304
+ const s = /* @__PURE__ */ new Date(), o = `${String(s.getMonth() + 1).padStart(
329
305
  2,
330
306
  "0"
331
307
  )}/${String(s.getDate()).padStart(2, "0")}`;
332
308
  await this.setState((i) => {
333
309
  const a = i.currentPropertyId;
334
310
  if (!a) return i;
335
- const o = i.properties[a];
336
- if (!o) return i;
311
+ const n = i.properties[a];
312
+ if (!n) return i;
337
313
  const p = [
338
- ...o.viewedUnits.filter((u) => u.unitId !== t),
339
- { unitId: t, viewedDate: n }
314
+ ...n.viewedUnits.filter((u) => u.unitId !== t),
315
+ { unitId: t, viewedDate: o }
340
316
  ];
341
317
  return {
342
318
  ...i,
343
319
  properties: {
344
320
  ...i.properties,
345
321
  [a]: {
346
- ...o,
322
+ ...n,
347
323
  viewedUnits: p
348
324
  }
349
325
  }
@@ -451,7 +427,7 @@ class U {
451
427
  * Resets the committed filters to their default values.
452
428
  */
453
429
  async setFiltersToDefault() {
454
- await this.setState((t) => ({ ...t, filters: w }));
430
+ await this.setState((t) => ({ ...t, filters: P }));
455
431
  }
456
432
  /**
457
433
  * Merges partial values into the API filters payload used for network requests.
@@ -481,7 +457,7 @@ class U {
481
457
  */
482
458
  async submitFilterUpdate() {
483
459
  await this.setState((t) => {
484
- const e = m(
460
+ const e = v(
485
461
  {
486
462
  ...t.filters,
487
463
  limit: t.apiFilters.limit,
@@ -540,7 +516,7 @@ class U {
540
516
  * @returns The visitor UUID string or null when not yet set.
541
517
  */
542
518
  async getVisitorUUID() {
543
- const t = await S("user");
519
+ const t = await y("user");
544
520
  return (t == null ? void 0 : t.visitor_uuid) ?? null;
545
521
  }
546
522
  /**
@@ -549,24 +525,20 @@ class U {
549
525
  * @param vid - Visitor UUID string returned by the session API.
550
526
  */
551
527
  async setVisitorUUID(t) {
552
- const e = await S("user"), r = e !== null && typeof e == "object" && !Array.isArray(e) ? e : {};
553
- await P("user", { ...r, visitor_uuid: t });
528
+ const e = await y("user"), r = e !== null && typeof e == "object" && !Array.isArray(e) ? e : {};
529
+ await h("user", { ...r, visitor_uuid: t });
554
530
  }
555
- // === UTILITY METHODS ===
556
531
  /**
557
- * Returns convenience state for a unit within the current property.
558
- *
559
- * @param unitId - Identifier of the unit to inspect.
560
- * @returns Favorite flag and last viewed date.
532
+ * Removes the visitor UUID from the KV store.
533
+ * Use when the stored UUID is stale (e.g. bootstrap returns 404).
561
534
  */
562
- async getUnitState(t) {
563
- var s;
564
- const e = await this.getState(), r = e.currentPropertyId ? e.properties[e.currentPropertyId] : null;
565
- return {
566
- isFavorite: (r == null ? void 0 : r.favoritedUnits.includes(t)) ?? !1,
567
- viewedDate: ((s = r == null ? void 0 : r.viewedUnits.find((n) => n.unitId === t)) == null ? void 0 : s.viewedDate) ?? ""
568
- };
535
+ async clearVisitorUUID() {
536
+ const t = await y("user");
537
+ if (t === null || typeof t != "object" || Array.isArray(t)) return;
538
+ const { visitor_uuid: e, ...r } = t;
539
+ await h("user", r);
569
540
  }
541
+ // === UTILITY METHODS ===
570
542
  /**
571
543
  * Builds a canonical results URL based on the current property slug.
572
544
  *
@@ -605,7 +577,7 @@ class U {
605
577
  * Hydrates the store with the default scaffold when no data has been persisted yet.
606
578
  */
607
579
  async initialize() {
608
- await this.setState((t) => ({ ...y, ...t }));
580
+ await this.setState((t) => ({ ...S, ...t }));
609
581
  }
610
582
  }
611
583
  const C = new U();
@@ -1 +1 @@
1
- {"version":3,"file":"store.mjs","sources":["../../src/stores/store.ts"],"sourcesContent":["import { kvGet, kvSet } from \"../storage\";\nimport type { ZodObject, ZodType, ZodTypeAny } from \"zod\";\nimport {\n UnifiedStoreDataSchema,\n UserPropertyStateSchema,\n type UnifiedStoreData,\n type UserPropertyState,\n type Property,\n type Filters,\n type QueryParams,\n type ResultsMode,\n type SortBy,\n type TourContactData,\n type Unit,\n PropertySchema,\n TourContactDataSchema,\n UnitSchema,\n} from \"../schema\";\nimport { validate } from \"../validation\";\nimport { transformFiltersToUnitsSearchParams } from \"../features/filters/transformers\";\n\n// Default values\nconst defaultFilters: Filters = {\n date_availability: undefined,\n qty_bedrooms: undefined,\n base_price: undefined,\n highlights: undefined,\n};\n\nconst defaultUnifiedStoreData: UnifiedStoreData = {\n // Property data\n properties: {},\n currentPropertyId: null,\n currentPropertySlug: null,\n hasPreviouslySearched: [],\n\n // App data\n unitResults: [],\n filters: defaultFilters,\n tempFilters: defaultFilters,\n apiFilters: {\n limit: 10,\n page: 1,\n sortBy: \"relevance\",\n },\n resultsMode: \"all\",\n resolvedQuestionnaireValues: {},\n sortBy: \"relevance\",\n};\n\nconst toArray = (input: unknown): unknown[] => {\n if (input == null) return [];\n return Array.isArray(input) ? input : [input];\n};\n\nconst extractFilterValues = (value: unknown): unknown[] => {\n return toArray(value).flatMap(item => {\n if (item == null) return [];\n if (Array.isArray(item)) return item;\n if (typeof item === \"object\" && \"value\" in (item as any)) {\n const v = (item as any).value;\n return Array.isArray(v) ? v : v != null ? [v] : [];\n }\n return [item];\n });\n};\n\nconst toStringArray = (value: unknown): string[] =>\n extractFilterValues(value)\n .flatMap(v => (Array.isArray(v) ? v : [v]))\n .map(v => String(v))\n .map(v => v.trim())\n .filter(v => v.length > 0);\n\nconst toNumberArray = (value: unknown): number[] =>\n extractFilterValues(value)\n .map(v => {\n if (typeof v === \"number\" && Number.isFinite(v)) return v;\n const num = Number(v);\n return Number.isFinite(num) ? num : null;\n })\n .filter((v): v is number => v !== null);\n\nconst toNumberValue = (value: unknown): number | null => {\n if (value == null) return null;\n if (typeof value === \"number\") return Number.isFinite(value) ? value : null;\n if (typeof value === \"object\" && \"value\" in (value as any)) {\n return toNumberValue((value as any).value);\n }\n const num = Number(value);\n return Number.isFinite(num) ? num : null;\n};\n\n// Unified store class\nexport class UnifiedStore {\n /**\n * Resolves the persisted unified store snapshot, coercing legacy shapes into the latest schema\n * and sanitizing invalid entries where possible.\n */\n private async getState(): Promise<UnifiedStoreData> {\n const state = await kvGet<UnifiedStoreData>(\"app\");\n if (!state) {\n return defaultUnifiedStoreData;\n }\n\n const merged = {\n ...defaultUnifiedStoreData,\n ...state,\n properties: state.properties ?? {},\n unitResults: state.unitResults ?? [],\n currentPropertyId:\n state.currentPropertyId == null ? null : String(state.currentPropertyId),\n currentPropertySlug: state.currentPropertySlug ?? null,\n hasPreviouslySearched: Array.isArray(state.hasPreviouslySearched)\n ? state.hasPreviouslySearched.map(String)\n : [],\n };\n\n const parsed = UnifiedStoreDataSchema.safeParse(merged);\n if (parsed.success) return parsed.data;\n\n // Sanitize by dropping invalid property entries and unit results\n const sanitizedProperties = Object.entries(merged.properties ?? {}).reduce<\n Record<string, UserPropertyState>\n >((acc, [key, value]) => {\n const entry = UserPropertyStateSchema.safeParse(value);\n if (entry.success) acc[key] = entry.data;\n return acc;\n }, {});\n\n const rawUnitResults = Array.isArray(merged.unitResults)\n ? merged.unitResults\n : merged.unitResults && typeof merged.unitResults === \"object\"\n ? Object.values(merged.unitResults as Record<string, unknown>)\n : [];\n\n const sanitizedUnitResults = rawUnitResults.reduce<Unit[]>((acc, value) => {\n const entry = UnitSchema.safeParse(value);\n if (entry.success) acc.push(entry.data);\n return acc;\n }, []);\n\n const fallback = {\n ...merged,\n properties: sanitizedProperties,\n unitResults: sanitizedUnitResults,\n };\n\n const fallbackParsed = UnifiedStoreDataSchema.safeParse(fallback);\n return fallbackParsed.success ? fallbackParsed.data : defaultUnifiedStoreData;\n }\n\n /**\n * Applies an updater function to the current store state, validates the result, and persists it.\n *\n * @param updater - Pure function that maps the current state to the next state.\n */\n private async setState(updater: (state: UnifiedStoreData) => UnifiedStoreData): Promise<void> {\n const currentState = await this.getState();\n const newState = updater(currentState);\n const validatedState = UnifiedStoreDataSchema.parse(newState);\n await kvSet(\"app\", validatedState);\n }\n\n /**\n * Polls the persisted state until a current property pointer is available or the timeout elapses.\n *\n * @param timeoutMs - Maximum time in milliseconds to wait before failing.\n * @returns The active property ID once it becomes available.\n * @throws Error if the property pointer is not set before the timeout expires.\n */\n private async waitForCurrentProperty(timeoutMs = 1000): Promise<string> {\n const deadline = Date.now() + timeoutMs;\n\n while (Date.now() < deadline) {\n const state = await this.getState();\n const propertyId = state.currentPropertyId;\n if (propertyId && state.properties[propertyId]) return propertyId;\n\n await new Promise(resolve => setTimeout(resolve, 16));\n }\n\n const finalState = await this.getState();\n const propertyId = finalState.currentPropertyId;\n if (propertyId && finalState.properties[propertyId]) return propertyId;\n\n throw new Error(\"UnifiedStore: current property was not initialized in time\");\n }\n\n // === PROPERTY OPERATIONS ===\n\n /**\n * Ensures a property entry exists and registers it as the current property.\n *\n * @param propertyId - Identifier used to track the property.\n * @param slug - Canonical slug associated with the property.\n */\n async initializeProperty(propertyId: string | number, slug: string): Promise<void> {\n const id = String(propertyId);\n await this.setState(state => {\n if (state.properties && state.properties[id]) {\n return {\n ...state,\n currentPropertyId: id,\n currentPropertySlug: slug\n };\n }\n\n return {\n ...state,\n currentPropertyId: id,\n currentPropertySlug: slug,\n properties: {\n ...state.properties,\n [id]: {\n id,\n slug,\n favoritedUnits: [],\n tourContactedOn: null,\n viewedUnits: [],\n questionnaireResults: null,\n tourContactData: null,\n },\n },\n };\n });\n }\n\n // === UNIT RESULTS CACHE ===\n /**\n * Persists a collection of units after validating each entry against the provided schema.\n *\n * @param units - Raw units collection returned by an API call.\n * @param schema - Optional override schema when the default `UnitSchema` is not sufficient.\n */\n async setUnitResults(\n units: unknown,\n schema?: ZodTypeAny,\n ): Promise<void> {\n const baseSchema = (schema ?? UnitSchema) as ZodType<Unit>;\n const validatedUnits: Unit[] = [];\n const collection = Array.isArray(units)\n ? units\n : units && typeof units === \"object\"\n ? Object.values(units as Record<string, unknown>)\n : [];\n\n collection.forEach((unit, index) => {\n const parsed = validate(baseSchema, unit, `unitResults[${index}]`);\n if (parsed) validatedUnits.push(parsed);\n });\n await this.setState(state => ({\n ...state,\n unitResults: validatedUnits,\n }));\n }\n\n /**\n * Clears the cached unit results array.\n */\n async clearUnitResults(): Promise<void> {\n await this.setState(state => ({\n ...state,\n unitResults: [],\n }));\n }\n\n // === PROPERTY DATA BAG (full property payloads & custom data) ===\n /**\n * Replaces the persisted property payload with validated data.\n *\n * @param propertyId - ID of the property to mutate.\n * @param data - New property payload.\n * @param schema - Optional schema override used for validation.\n */\n async setPropertyData(\n propertyId: string | number,\n data: unknown,\n schema?: ZodObject<any, any, any, any, any>,\n ): Promise<void> {\n const id = String(propertyId);\n const baseSchema = (schema ?? PropertySchema) as ZodObject<any, any, any, any, any>;\n await this.setState(state => {\n const property = state.properties[id];\n if (!property) return state;\n const validated = validate(baseSchema, data, `properties.${id}.data`) as Property | null;\n if (!validated) return state;\n return {\n ...state,\n properties: {\n ...state.properties,\n [id]: {\n ...property,\n data: validated,\n },\n },\n };\n });\n }\n\n /**\n * Merges partial property data into the persisted payload with validation safeguards.\n *\n * @param propertyId - ID of the property to update.\n * @param partial - Partial payload to merge.\n * @param schema - Optional schema override for validation.\n */\n async mergePropertyData(\n propertyId: string | number,\n partial: unknown,\n schema?: ZodObject<any, any, any, any, any>,\n ): Promise<void> {\n const id = String(propertyId);\n const baseSchema = (schema ?? PropertySchema) as ZodObject<any, any, any, any, any>;\n await this.setState(state => {\n const property = state.properties[id];\n if (!property) return state;\n const current = property.data;\n if (!current) {\n const full = validate(baseSchema, partial, `properties.${id}.data`) as Property | null;\n if (!full) return state;\n return {\n ...state,\n properties: {\n ...state.properties,\n [id]: {\n ...property,\n data: full,\n },\n },\n };\n }\n\n const partialSchema = baseSchema.partial();\n const validatedPartial = validate(\n partialSchema,\n partial,\n `properties.${id}.data.partial`,\n ) as Partial<Property> | null;\n if (!validatedPartial) return state;\n const merged = validate(\n baseSchema,\n { ...current, ...validatedPartial },\n `properties.${id}.data`,\n ) as Property | null;\n if (!merged) return state;\n return {\n ...state,\n properties: {\n ...state.properties,\n [id]: {\n ...property,\n data: merged,\n },\n },\n };\n });\n }\n\n // Accepts a full API property object, validates, and stores it into the\n // per-property `data` bag. Ensures the property entry exists/updated.\n /**\n * Inserts or updates a property entry from an API payload, enforcing schema validation.\n *\n * @param apiProperty - Raw property object returned by an API.\n * @param schema - Optional schema override.\n */\n async upsertPropertyFromApi(\n apiProperty: unknown,\n schema?: ZodTypeAny,\n ): Promise<void> {\n const s = schema ?? PropertySchema;\n const parsed: any = s.parse(apiProperty);\n const id = parsed.id ?? parsed.propertyId;\n if (id === undefined || id === null) {\n throw new Error(\"upsertPropertyFromApi: property id is required\");\n }\n const propertyId = String(id);\n const slug: string | undefined = parsed.slug ?? undefined;\n\n await this.setState(state => {\n const existing = state.properties[propertyId];\n const next: UserPropertyState = existing\n ? {\n ...existing,\n ...(slug ? { slug } : {}),\n data: parsed,\n }\n : {\n id: propertyId,\n slug: slug ?? \"\",\n favoritedUnits: [],\n tourContactedOn: null,\n viewedUnits: [],\n questionnaireResults: null,\n tourContactData: null,\n data: parsed,\n };\n\n return {\n ...state,\n properties: {\n ...state.properties,\n [propertyId]: next,\n },\n };\n });\n }\n\n /**\n * Marks the provided property as current and optionally updates the slug.\n *\n * @param propertyId - Property identifier to focus.\n * @param slug - Optional slug override.\n */\n async setCurrentProperty(propertyId: string | number, slug?: string): Promise<void> {\n const id = String(propertyId);\n await this.setState(state => ({\n ...state,\n currentPropertyId: id,\n currentPropertySlug: slug || state.currentPropertySlug,\n }));\n }\n\n /**\n * Updates the slug for the current property selection.\n *\n * @param slug - New slug to persist.\n */\n async setCurrentPropertySlug(slug: string): Promise<void> {\n await this.setState(state => ({\n ...state,\n currentPropertySlug: slug\n }));\n }\n\n /**\n * Adds a slug to the `hasPreviouslySearched` list without duplicating existing entries.\n *\n * @param slug - Slug to record.\n */\n async setHasPreviouslySearched(slug: string): Promise<void> {\n await this.setState(state => ({\n ...state,\n hasPreviouslySearched: Array.from(\n new Set([...state.hasPreviouslySearched, slug])\n ),\n }));\n }\n\n /**\n * Toggles a unit's favorite state for the currently active property.\n *\n * @param unitId - Unit identifier to toggle.\n */\n async toggleFavorite(unitId: string): Promise<void> {\n await this.setState(state => {\n const propertyId = state.currentPropertyId;\n if (!propertyId) return state;\n\n const property = state.properties[propertyId];\n if (!property) return state;\n\n const isFavorited = property.favoritedUnits.includes(unitId);\n const updatedFavoritedUnits = isFavorited\n ? property.favoritedUnits.filter((id) => id !== unitId)\n : [...property.favoritedUnits, unitId];\n\n return {\n ...state,\n properties: {\n ...state.properties,\n [propertyId]: {\n ...property,\n favoritedUnits: updatedFavoritedUnits,\n },\n },\n };\n });\n }\n\n /**\n * Records the most recent view date for a unit and opens the unit URL in the browser when available.\n *\n * @param unitId - Identifier of the viewed unit.\n * @param slug - Property slug used to construct the URL.\n */\n async markUnitAsViewed(unitId: string, slug: string): Promise<void> {\n\n const url = `https://${slug}`;\n window.open(url, \"_blank\", \"noopener,noreferrer\");\n\n const today = new Date();\n const formattedDate = `${String(today.getMonth() + 1).padStart(\n 2,\n \"0\"\n )}/${String(today.getDate()).padStart(2, \"0\")}`;\n\n await this.setState(state => {\n const propertyId = state.currentPropertyId;\n if (!propertyId) return state;\n\n const property = state.properties[propertyId];\n if (!property) return state;\n\n const updatedViewedUnits = [\n ...property.viewedUnits.filter((u) => u.unitId !== unitId),\n { unitId, viewedDate: formattedDate },\n ];\n\n return {\n ...state,\n properties: {\n ...state.properties,\n [propertyId]: {\n ...property,\n viewedUnits: updatedViewedUnits,\n },\n },\n };\n });\n\n\n }\n\n /**\n * Stamps the current property with the moment the tour outreach occurred.\n */\n async setTourContactedOn(): Promise<void> {\n await this.setState(state => {\n const propertyId = state.currentPropertyId;\n if (!propertyId) return state;\n\n const property = state.properties[propertyId];\n if (!property) return state;\n\n return {\n ...state,\n properties: {\n ...state.properties,\n [propertyId]: {\n ...property,\n tourContactedOn: new Date().toISOString(),\n },\n },\n };\n });\n }\n\n /**\n * Reads the stored tour contact timestamp for the current property.\n *\n * @returns ISO string or null when no timestamp exists.\n */\n async getTourContactedOn(): Promise<string | null> {\n const state = await this.getState();\n const propertyId = state.currentPropertyId;\n if (!propertyId) return null;\n\n return state.properties[propertyId]?.tourContactedOn ?? null;\n }\n\n /**\n * Persists questionnaire results captured for the current property.\n *\n * @param results - Arbitrary questionnaire data.\n */\n async setQuestionnaireResults(results: unknown): Promise<void> {\n await this.setState(state => {\n const propertyId = state.currentPropertyId;\n if (!propertyId) return state;\n\n const property = state.properties[propertyId];\n if (!property) return state;\n\n return {\n ...state,\n properties: {\n ...state.properties,\n [propertyId]: {\n ...property,\n questionnaireResults: results,\n },\n },\n };\n });\n }\n\n /**\n * Persists structured tour contact preferences for the active property. The method waits until\n * a current property is available, allowing callers to invoke it before initialization completes.\n *\n * @param data - Contact preferences captured from the UI.\n */\n async setTourContactData(data: TourContactData): Promise<void> {\n const propertyId = await this.waitForCurrentProperty();\n\n await this.setState(state => {\n const property = state.properties[propertyId];\n if (!property) return state;\n\n return {\n ...state,\n properties: {\n ...state.properties,\n [propertyId]: {\n ...property,\n tourContactData: data,\n },\n },\n };\n });\n }\n\n\n\n\n\n\n\n // === FILTER OPERATIONS ===\n\n /**\n * Merges the provided filter values into the committed filter state.\n *\n * @param filters - Partial filter payload to apply.\n */\n async setFilters(filters: Partial<Filters>): Promise<void> {\n await this.setState(state => ({\n ...state,\n filters: { ...state.filters, ...filters }\n }));\n }\n\n /**\n * Updates the transient filters used for in-progress UI interactions.\n *\n * @param filters - Partial staging filter payload.\n */\n async setTempFilters(filters: Partial<Filters>): Promise<void> {\n await this.setState(state => ({\n ...state,\n tempFilters: { ...state.tempFilters, ...filters }\n }));\n }\n\n /**\n * Resets the committed filters to their default values.\n */\n async setFiltersToDefault(): Promise<void> {\n await this.setState(state => ({ ...state, filters: defaultFilters }));\n }\n\n /**\n * Merges partial values into the API filters payload used for network requests.\n *\n * @param filters - Partial query parameters to persist.\n */\n async setApiFilters(filters: Partial<QueryParams>): Promise<void> {\n await this.setState(state => ({\n ...state,\n apiFilters: { ...state.apiFilters, ...filters }\n }));\n }\n\n /**\n * Updates a single temporary filter field without touching the rest of the staged filters.\n *\n * @param key - Filter key to mutate.\n * @param value - New value to assign.\n */\n async handleTempFilterChange<K extends keyof Filters>(\n key: K,\n value: Filters[K]\n ): Promise<void> {\n await this.setState(state => ({\n ...state,\n tempFilters: { ...state.tempFilters, [key]: value }\n }));\n }\n\n /**\n * Normalizes the committed filters into API-ready structures and persists the result.\n */\n async submitFilterUpdate(): Promise<void> {\n await this.setState(state => {\n const apiParams: QueryParams = transformFiltersToUnitsSearchParams(\n {\n ...state.filters,\n limit: state.apiFilters.limit,\n page: state.apiFilters.page,\n sortBy: state.sortBy,\n },\n {\n defaultLimit: state.apiFilters.limit,\n defaultPage: state.apiFilters.page,\n defaultSort: state.sortBy,\n },\n );\n\n return {\n ...state,\n apiFilters: apiParams,\n };\n });\n }\n\n // === RESULTS AND SORTING ===\n\n /**\n * Persists the selected results mode (e.g. \"all\" or \"favorites\").\n *\n * @param mode - Mode identifier to store.\n */\n async setResultsMode(mode: ResultsMode): Promise<void> {\n await this.setState(state => ({ ...state, resultsMode: mode }));\n }\n\n /**\n * Persists the currently selected sort option.\n *\n * @param sortBy - Sort identifier.\n */\n async setSortBy(sortBy: SortBy): Promise<void> {\n await this.setState(state => ({ ...state, sortBy }));\n }\n\n // === QUESTIONNAIRE ===\n\n /**\n * Stores resolved questionnaire answers keyed by questionnaire name.\n *\n * @param name - Questionnaire identifier.\n * @param values - Selected option values.\n */\n async setResolvedQuestionnaireValues(name: string, values: string[]): Promise<void> {\n await this.setState(state => ({\n ...state,\n resolvedQuestionnaireValues: {\n ...state.resolvedQuestionnaireValues,\n [name]: values\n }\n }));\n }\n\n // === VISITOR UUID ===\n\n /**\n * Reads the persisted visitor UUID from the KV store.\n *\n * @returns The visitor UUID string or null when not yet set.\n */\n async getVisitorUUID(): Promise<string | null> {\n const user = await kvGet<{ visitor_uuid?: string }>(\"user\");\n return user?.visitor_uuid ?? null;\n }\n\n /**\n * Persists a visitor UUID to the KV store.\n *\n * @param vid - Visitor UUID string returned by the session API.\n */\n async setVisitorUUID(vid: string): Promise<void> {\n const current = await kvGet<Record<string, unknown>>(\"user\");\n const safe = current !== null && typeof current === \"object\" && !Array.isArray(current) ? current : {};\n await kvSet(\"user\", { ...safe, visitor_uuid: vid });\n }\n\n // === UTILITY METHODS ===\n\n /**\n * Returns convenience state for a unit within the current property.\n *\n * @param unitId - Identifier of the unit to inspect.\n * @returns Favorite flag and last viewed date.\n */\n async getUnitState(unitId: string): Promise<{\n isFavorite: boolean;\n viewedDate: string;\n }> {\n const state = await this.getState();\n const property = state.currentPropertyId ? state.properties[state.currentPropertyId] : null;\n\n return {\n isFavorite: property?.favoritedUnits.includes(unitId) ?? false,\n viewedDate:\n property?.viewedUnits.find((u) => u.unitId === unitId)?.viewedDate ?? \"\",\n };\n }\n\n /**\n * Builds a canonical results URL based on the current property slug.\n *\n * @returns Relative results URL or null when no property is selected.\n */\n async getResultsUrl(): Promise<string | null> {\n const state = await this.getState();\n return state.currentPropertySlug ? `/${state.currentPropertySlug}/results` : null;\n }\n\n /**\n * Retrieves the currently selected property entry.\n *\n * @returns Property state or null when unset.\n */\n async getCurrentProperty(): Promise<UserPropertyState | null> {\n const state = await this.getState();\n return state.currentPropertyId ? state.properties[state.currentPropertyId] ?? null : null;\n }\n\n /**\n * Retrieves property data for a specific property or defaults to the current property.\n *\n * @param propertyId - Optional property identifier to fetch.\n * @returns Property state or null when unavailable.\n */\n async getPropertyData(propertyId?: string | number): Promise<UserPropertyState | null> {\n const state = await this.getState();\n const id = propertyId == null ? state.currentPropertyId : String(propertyId);\n return id ? state.properties[id] ?? null : null;\n }\n\n /**\n * Reads and returns the full validated unified store state.\n */\n async getFullState(): Promise<UnifiedStoreData> {\n return this.getState();\n }\n\n /**\n * Hydrates the store with the default scaffold when no data has been persisted yet.\n */\n async initialize(): Promise<void> {\n // Ensure default shape is present; no-op if already initialized\n await this.setState(state => ({ ...defaultUnifiedStoreData, ...state }));\n }\n\n}\n\n// Export singleton instance\nexport const store = new UnifiedStore();\n// Alias to prefer neutral naming going forward\nexport { UnifiedStore as Store };\n// Re-export types for convenience (tests import from this module)\nexport type { UserPropertyState, Filters } from \"../schema\";\n"],"names":["defaultFilters","defaultUnifiedStoreData","UnifiedStore","state","kvGet","merged","parsed","UnifiedStoreDataSchema","sanitizedProperties","acc","key","value","entry","UserPropertyStateSchema","sanitizedUnitResults","UnitSchema","fallback","fallbackParsed","updater","currentState","newState","validatedState","kvSet","timeoutMs","deadline","propertyId","resolve","finalState","slug","id","units","schema","baseSchema","validatedUnits","unit","index","validate","data","PropertySchema","property","validated","partial","current","full","partialSchema","validatedPartial","apiProperty","existing","next","unitId","updatedFavoritedUnits","url","today","formattedDate","updatedViewedUnits","_a","results","filters","apiParams","transformFiltersToUnitsSearchParams","mode","sortBy","name","values","user","vid","safe","u","store"],"mappings":";;;;AAsBA,MAAMA,IAA0B;AAAA,EAC9B,mBAAmB;AAAA,EACnB,cAAc;AAAA,EACd,YAAY;AAAA,EACZ,YAAY;AACd,GAEMC,IAA4C;AAAA;AAAA,EAEhD,YAAY,CAAA;AAAA,EACZ,mBAAmB;AAAA,EACnB,qBAAqB;AAAA,EACrB,uBAAuB,CAAA;AAAA;AAAA,EAGvB,aAAa,CAAA;AAAA,EACb,SAASD;AAAA,EACT,aAAaA;AAAA,EACb,YAAY;AAAA,IACV,OAAO;AAAA,IACP,MAAM;AAAA,IACN,QAAQ;AAAA,EAAA;AAAA,EAEV,aAAa;AAAA,EACb,6BAA6B,CAAA;AAAA,EAC7B,QAAQ;AACV;AA8CO,MAAME,EAAa;AAAA;AAAA;AAAA;AAAA;AAAA,EAKxB,MAAc,WAAsC;AAClD,UAAMC,IAAQ,MAAMC,EAAwB,KAAK;AACjD,QAAI,CAACD;AACH,aAAOF;AAGT,UAAMI,IAAS;AAAA,MACb,GAAGJ;AAAA,MACH,GAAGE;AAAA,MACH,YA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iBAAiB,KAAK,OAAO;AAAA,EACvF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,MAAM,gBAAgBsB,GAAiE;AACrF,UAAMtB,IAAQ,MAAM,KAAK,SAAA,GACnB0B,IAAKJ,KAAc,OAAOtB,EAAM,oBAAoB,OAAOsB,CAAU;AAC3E,WAAOI,IAAK1B,EAAM,WAAW0B,CAAE,KAAK,OAAO;AAAA,EAC7C;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,eAA0C;AAC9C,WAAO,KAAK,SAAA;AAAA,EACd;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,aAA4B;AAEhC,UAAM,KAAK,SAAS,CAAA1B,OAAU,EAAE,GAAGF,GAAyB,GAAGE,IAAQ;AAAA,EACzE;AAEF;AAGO,MAAMiE,IAAQ,IAAIlE,EAAA;"}
1
+ {"version":3,"file":"store.mjs","sources":["../../src/stores/store.ts"],"sourcesContent":["import { kvGet, kvSet } from \"../storage\";\nimport type { ZodObject, ZodType, ZodTypeAny } from \"zod\";\nimport {\n UnifiedStoreDataSchema,\n UserPropertyStateSchema,\n type UnifiedStoreData,\n type UserPropertyState,\n type Property,\n type Filters,\n type QueryParams,\n type ResultsMode,\n type SortBy,\n type TourContactData,\n type Unit,\n PropertySchema,\n TourContactDataSchema,\n UnitSchema,\n} from \"../schema\";\nimport { validate } from \"../validation\";\nimport { transformFiltersToUnitsSearchParams } from \"../features/filters/transformers\";\n\n// Default values\nconst defaultFilters: Filters = {\n date_availability: undefined,\n qty_bedrooms: undefined,\n base_price: undefined,\n highlights: undefined,\n};\n\nconst defaultUnifiedStoreData: UnifiedStoreData = {\n // Property data\n properties: {},\n currentPropertyId: null,\n currentPropertySlug: null,\n hasPreviouslySearched: [],\n\n // App data\n unitResults: [],\n filters: defaultFilters,\n tempFilters: defaultFilters,\n apiFilters: {\n limit: 10,\n page: 1,\n sortBy: \"relevance\",\n },\n resultsMode: \"all\",\n resolvedQuestionnaireValues: {},\n sortBy: \"relevance\",\n};\n\nconst toArray = (input: unknown): unknown[] => {\n if (input == null) return [];\n return Array.isArray(input) ? input : [input];\n};\n\nconst extractFilterValues = (value: unknown): unknown[] => {\n return toArray(value).flatMap(item => {\n if (item == null) return [];\n if (Array.isArray(item)) return item;\n if (typeof item === \"object\" && \"value\" in (item as any)) {\n const v = (item as any).value;\n return Array.isArray(v) ? v : v != null ? [v] : [];\n }\n return [item];\n });\n};\n\nconst toStringArray = (value: unknown): string[] =>\n extractFilterValues(value)\n .flatMap(v => (Array.isArray(v) ? v : [v]))\n .map(v => String(v))\n .map(v => v.trim())\n .filter(v => v.length > 0);\n\nconst toNumberArray = (value: unknown): number[] =>\n extractFilterValues(value)\n .map(v => {\n if (typeof v === \"number\" && Number.isFinite(v)) return v;\n const num = Number(v);\n return Number.isFinite(num) ? num : null;\n })\n .filter((v): v is number => v !== null);\n\nconst toNumberValue = (value: unknown): number | null => {\n if (value == null) return null;\n if (typeof value === \"number\") return Number.isFinite(value) ? value : null;\n if (typeof value === \"object\" && \"value\" in (value as any)) {\n return toNumberValue((value as any).value);\n }\n const num = Number(value);\n return Number.isFinite(num) ? num : null;\n};\n\n// Unified store class\nexport class UnifiedStore {\n /**\n * Resolves the persisted unified store snapshot, coercing legacy shapes into the latest schema\n * and sanitizing invalid entries where possible.\n */\n private async getState(): Promise<UnifiedStoreData> {\n const state = await kvGet<UnifiedStoreData>(\"app\");\n if (!state) {\n return defaultUnifiedStoreData;\n }\n\n const merged = {\n ...defaultUnifiedStoreData,\n ...state,\n properties: state.properties ?? {},\n unitResults: state.unitResults ?? [],\n currentPropertyId:\n state.currentPropertyId == null ? null : String(state.currentPropertyId),\n currentPropertySlug: state.currentPropertySlug ?? null,\n hasPreviouslySearched: Array.isArray(state.hasPreviouslySearched)\n ? state.hasPreviouslySearched.map(String)\n : [],\n };\n\n const parsed = UnifiedStoreDataSchema.safeParse(merged);\n if (parsed.success) return parsed.data;\n\n // Sanitize by dropping invalid property entries and unit results\n const sanitizedProperties = Object.entries(merged.properties ?? {}).reduce<\n Record<string, UserPropertyState>\n >((acc, [key, value]) => {\n const entry = UserPropertyStateSchema.safeParse(value);\n if (entry.success) acc[key] = entry.data;\n return acc;\n }, {});\n\n const rawUnitResults = Array.isArray(merged.unitResults)\n ? merged.unitResults\n : merged.unitResults && typeof merged.unitResults === \"object\"\n ? Object.values(merged.unitResults as Record<string, unknown>)\n : [];\n\n const sanitizedUnitResults = rawUnitResults.reduce<Unit[]>((acc, value) => {\n const entry = UnitSchema.safeParse(value);\n if (entry.success) acc.push(entry.data);\n return acc;\n }, []);\n\n const fallback = {\n ...merged,\n properties: sanitizedProperties,\n unitResults: sanitizedUnitResults,\n };\n\n const fallbackParsed = UnifiedStoreDataSchema.safeParse(fallback);\n return fallbackParsed.success ? fallbackParsed.data : defaultUnifiedStoreData;\n }\n\n /**\n * Applies an updater function to the current store state, validates the result, and persists it.\n *\n * @param updater - Pure function that maps the current state to the next state.\n */\n private async setState(updater: (state: UnifiedStoreData) => UnifiedStoreData): Promise<void> {\n const currentState = await this.getState();\n const newState = updater(currentState);\n const validatedState = UnifiedStoreDataSchema.parse(newState);\n await kvSet(\"app\", validatedState);\n }\n\n /**\n * Polls the persisted state until a current property pointer is available or the timeout elapses.\n *\n * @param timeoutMs - Maximum time in milliseconds to wait before failing.\n * @returns The active property ID once it becomes available.\n * @throws Error if the property pointer is not set before the timeout expires.\n */\n private async waitForCurrentProperty(timeoutMs = 1000): Promise<string> {\n const deadline = Date.now() + timeoutMs;\n\n while (Date.now() < deadline) {\n const state = await this.getState();\n const propertyId = state.currentPropertyId;\n if (propertyId && state.properties[propertyId]) return propertyId;\n\n await new Promise(resolve => setTimeout(resolve, 16));\n }\n\n const finalState = await this.getState();\n const propertyId = finalState.currentPropertyId;\n if (propertyId && finalState.properties[propertyId]) return propertyId;\n\n throw new Error(\"UnifiedStore: current property was not initialized in time\");\n }\n\n // === PROPERTY OPERATIONS ===\n\n /**\n * Ensures a property entry exists and registers it as the current property.\n *\n * @param propertyId - Identifier used to track the property.\n * @param slug - Canonical slug associated with the property.\n */\n async initializeProperty(propertyId: string | number, slug: string): Promise<void> {\n const id = String(propertyId);\n await this.setState(state => {\n if (state.properties && state.properties[id]) {\n return {\n ...state,\n currentPropertyId: id,\n currentPropertySlug: slug\n };\n }\n\n return {\n ...state,\n currentPropertyId: id,\n currentPropertySlug: slug,\n properties: {\n ...state.properties,\n [id]: {\n id,\n slug,\n favoritedUnits: [],\n tourContactedOn: null,\n viewedUnits: [],\n questionnaireResults: null,\n tourContactData: null,\n },\n },\n };\n });\n }\n\n // === UNIT RESULTS CACHE ===\n /**\n * Persists a collection of units after validating each entry against the provided schema.\n *\n * @param units - Raw units collection returned by an API call.\n * @param schema - Optional override schema when the default `UnitSchema` is not sufficient.\n */\n async setUnitResults(\n units: unknown,\n schema?: ZodTypeAny,\n ): Promise<void> {\n const baseSchema = (schema ?? UnitSchema) as ZodType<Unit>;\n const validatedUnits: Unit[] = [];\n const collection = Array.isArray(units)\n ? units\n : units && typeof units === \"object\"\n ? Object.values(units as Record<string, unknown>)\n : [];\n\n collection.forEach((unit, index) => {\n const parsed = validate(baseSchema, unit, `unitResults[${index}]`);\n if (parsed) validatedUnits.push(parsed);\n });\n await this.setState(state => ({\n ...state,\n unitResults: validatedUnits,\n }));\n }\n\n /**\n * Clears the cached unit results array.\n */\n async clearUnitResults(): Promise<void> {\n await this.setState(state => ({\n ...state,\n unitResults: [],\n }));\n }\n\n // === PROPERTY DATA BAG (full property payloads & custom data) ===\n /**\n * Replaces the persisted property payload with validated data.\n *\n * @param propertyId - ID of the property to mutate.\n * @param data - New property payload.\n * @param schema - Optional schema override used for validation.\n */\n async setPropertyData(\n propertyId: string | number,\n data: unknown,\n schema?: ZodObject<any, any, any, any, any>,\n ): Promise<void> {\n const id = String(propertyId);\n const baseSchema = (schema ?? PropertySchema) as ZodObject<any, any, any, any, any>;\n await this.setState(state => {\n const property = state.properties[id];\n if (!property) return state;\n const validated = validate(baseSchema, data, `properties.${id}.data`) as Property | null;\n if (!validated) return state;\n return {\n ...state,\n properties: {\n ...state.properties,\n [id]: {\n ...property,\n data: validated,\n },\n },\n };\n });\n }\n\n /**\n * Merges partial property data into the persisted payload with validation safeguards.\n *\n * @param propertyId - ID of the property to update.\n * @param partial - Partial payload to merge.\n * @param schema - Optional schema override for validation.\n */\n async mergePropertyData(\n propertyId: string | number,\n partial: unknown,\n schema?: ZodObject<any, any, any, any, any>,\n ): Promise<void> {\n const id = String(propertyId);\n const baseSchema = (schema ?? PropertySchema) as ZodObject<any, any, any, any, any>;\n await this.setState(state => {\n const property = state.properties[id];\n if (!property) return state;\n const current = property.data;\n if (!current) {\n const full = validate(baseSchema, partial, `properties.${id}.data`) as Property | null;\n if (!full) return state;\n return {\n ...state,\n properties: {\n ...state.properties,\n [id]: {\n ...property,\n data: full,\n },\n },\n };\n }\n\n const partialSchema = baseSchema.partial();\n const validatedPartial = validate(\n partialSchema,\n partial,\n `properties.${id}.data.partial`,\n ) as Partial<Property> | null;\n if (!validatedPartial) return state;\n const merged = validate(\n baseSchema,\n { ...current, ...validatedPartial },\n `properties.${id}.data`,\n ) as Property | null;\n if (!merged) return state;\n return {\n ...state,\n properties: {\n ...state.properties,\n [id]: {\n ...property,\n data: merged,\n },\n },\n };\n });\n }\n\n // Accepts a full API property object, validates, and stores it into the\n // per-property `data` bag. Ensures the property entry exists/updated.\n /**\n * Inserts or updates a property entry from an API payload, enforcing schema validation.\n *\n * @param apiProperty - Raw property object returned by an API.\n * @param schema - Optional schema override.\n */\n async upsertPropertyFromApi(\n apiProperty: unknown,\n schema?: ZodTypeAny,\n ): Promise<void> {\n const s = schema ?? PropertySchema;\n const parsed: any = s.parse(apiProperty);\n const id = parsed.id ?? parsed.propertyId;\n if (id === undefined || id === null) {\n throw new Error(\"upsertPropertyFromApi: property id is required\");\n }\n const propertyId = String(id);\n const slug: string | undefined = parsed.slug ?? undefined;\n\n await this.setState(state => {\n const existing = state.properties[propertyId];\n const next: UserPropertyState = existing\n ? {\n ...existing,\n ...(slug ? { slug } : {}),\n data: parsed,\n }\n : {\n id: propertyId,\n slug: slug ?? \"\",\n favoritedUnits: [],\n tourContactedOn: null,\n viewedUnits: [],\n questionnaireResults: null,\n tourContactData: null,\n data: parsed,\n };\n\n return {\n ...state,\n properties: {\n ...state.properties,\n [propertyId]: next,\n },\n };\n });\n }\n\n /**\n * Marks the provided property as current and optionally updates the slug.\n *\n * @param propertyId - Property identifier to focus.\n * @param slug - Optional slug override.\n */\n async setCurrentProperty(propertyId: string | number, slug?: string): Promise<void> {\n const id = String(propertyId);\n await this.setState(state => ({\n ...state,\n currentPropertyId: id,\n currentPropertySlug: slug || state.currentPropertySlug,\n }));\n }\n\n /**\n * Updates the slug for the current property selection.\n *\n * @param slug - New slug to persist.\n */\n async setCurrentPropertySlug(slug: string): Promise<void> {\n await this.setState(state => ({\n ...state,\n currentPropertySlug: slug\n }));\n }\n\n /**\n * Adds a slug to the `hasPreviouslySearched` list without duplicating existing entries.\n *\n * @param slug - Slug to record.\n */\n async setHasPreviouslySearched(slug: string): Promise<void> {\n await this.setState(state => ({\n ...state,\n hasPreviouslySearched: Array.from(\n new Set([...state.hasPreviouslySearched, slug])\n ),\n }));\n }\n\n /**\n * Records the most recent view date for a unit and opens the unit URL in the browser when available.\n *\n * @param unitId - Identifier of the viewed unit.\n * @param slug - Property slug used to construct the URL.\n */\n async markUnitAsViewed(unitId: string, slug: string): Promise<void> {\n\n const url = `https://${slug}`;\n window.open(url, \"_blank\", \"noopener,noreferrer\");\n\n const today = new Date();\n const formattedDate = `${String(today.getMonth() + 1).padStart(\n 2,\n \"0\"\n )}/${String(today.getDate()).padStart(2, \"0\")}`;\n\n await this.setState(state => {\n const propertyId = state.currentPropertyId;\n if (!propertyId) return state;\n\n const property = state.properties[propertyId];\n if (!property) return state;\n\n const updatedViewedUnits = [\n ...property.viewedUnits.filter((u) => u.unitId !== unitId),\n { unitId, viewedDate: formattedDate },\n ];\n\n return {\n ...state,\n properties: {\n ...state.properties,\n [propertyId]: {\n ...property,\n viewedUnits: updatedViewedUnits,\n },\n },\n };\n });\n\n\n }\n\n /**\n * Stamps the current property with the moment the tour outreach occurred.\n */\n async setTourContactedOn(): Promise<void> {\n await this.setState(state => {\n const propertyId = state.currentPropertyId;\n if (!propertyId) return state;\n\n const property = state.properties[propertyId];\n if (!property) return state;\n\n return {\n ...state,\n properties: {\n ...state.properties,\n [propertyId]: {\n ...property,\n tourContactedOn: new Date().toISOString(),\n },\n },\n };\n });\n }\n\n /**\n * Reads the stored tour contact timestamp for the current property.\n *\n * @returns ISO string or null when no timestamp exists.\n */\n async getTourContactedOn(): Promise<string | null> {\n const state = await this.getState();\n const propertyId = state.currentPropertyId;\n if (!propertyId) return null;\n\n return state.properties[propertyId]?.tourContactedOn ?? null;\n }\n\n /**\n * Persists questionnaire results captured for the current property.\n *\n * @param results - Arbitrary questionnaire data.\n */\n async setQuestionnaireResults(results: unknown): Promise<void> {\n await this.setState(state => {\n const propertyId = state.currentPropertyId;\n if (!propertyId) return state;\n\n const property = state.properties[propertyId];\n if (!property) return state;\n\n return {\n ...state,\n properties: {\n ...state.properties,\n [propertyId]: {\n ...property,\n questionnaireResults: results,\n },\n },\n };\n });\n }\n\n /**\n * Persists structured tour contact preferences for the active property. The method waits until\n * a current property is available, allowing callers to invoke it before initialization completes.\n *\n * @param data - Contact preferences captured from the UI.\n */\n async setTourContactData(data: TourContactData): Promise<void> {\n const propertyId = await this.waitForCurrentProperty();\n\n await this.setState(state => {\n const property = state.properties[propertyId];\n if (!property) return state;\n\n return {\n ...state,\n properties: {\n ...state.properties,\n [propertyId]: {\n ...property,\n tourContactData: data,\n },\n },\n };\n });\n }\n\n\n\n\n\n\n\n // === FILTER OPERATIONS ===\n\n /**\n * Merges the provided filter values into the committed filter state.\n *\n * @param filters - Partial filter payload to apply.\n */\n async setFilters(filters: Partial<Filters>): Promise<void> {\n await this.setState(state => ({\n ...state,\n filters: { ...state.filters, ...filters }\n }));\n }\n\n /**\n * Updates the transient filters used for in-progress UI interactions.\n *\n * @param filters - Partial staging filter payload.\n */\n async setTempFilters(filters: Partial<Filters>): Promise<void> {\n await this.setState(state => ({\n ...state,\n tempFilters: { ...state.tempFilters, ...filters }\n }));\n }\n\n /**\n * Resets the committed filters to their default values.\n */\n async setFiltersToDefault(): Promise<void> {\n await this.setState(state => ({ ...state, filters: defaultFilters }));\n }\n\n /**\n * Merges partial values into the API filters payload used for network requests.\n *\n * @param filters - Partial query parameters to persist.\n */\n async setApiFilters(filters: Partial<QueryParams>): Promise<void> {\n await this.setState(state => ({\n ...state,\n apiFilters: { ...state.apiFilters, ...filters }\n }));\n }\n\n /**\n * Updates a single temporary filter field without touching the rest of the staged filters.\n *\n * @param key - Filter key to mutate.\n * @param value - New value to assign.\n */\n async handleTempFilterChange<K extends keyof Filters>(\n key: K,\n value: Filters[K]\n ): Promise<void> {\n await this.setState(state => ({\n ...state,\n tempFilters: { ...state.tempFilters, [key]: value }\n }));\n }\n\n /**\n * Normalizes the committed filters into API-ready structures and persists the result.\n */\n async submitFilterUpdate(): Promise<void> {\n await this.setState(state => {\n const apiParams: QueryParams = transformFiltersToUnitsSearchParams(\n {\n ...state.filters,\n limit: state.apiFilters.limit,\n page: state.apiFilters.page,\n sortBy: state.sortBy,\n },\n {\n defaultLimit: state.apiFilters.limit,\n defaultPage: state.apiFilters.page,\n defaultSort: state.sortBy,\n },\n );\n\n return {\n ...state,\n apiFilters: apiParams,\n };\n });\n }\n\n // === RESULTS AND SORTING ===\n\n /**\n * Persists the selected results mode (e.g. \"all\" or \"favorites\").\n *\n * @param mode - Mode identifier to store.\n */\n async setResultsMode(mode: ResultsMode): Promise<void> {\n await this.setState(state => ({ ...state, resultsMode: mode }));\n }\n\n /**\n * Persists the currently selected sort option.\n *\n * @param sortBy - Sort identifier.\n */\n async setSortBy(sortBy: SortBy): Promise<void> {\n await this.setState(state => ({ ...state, sortBy }));\n }\n\n // === QUESTIONNAIRE ===\n\n /**\n * Stores resolved questionnaire answers keyed by questionnaire name.\n *\n * @param name - Questionnaire identifier.\n * @param values - Selected option values.\n */\n async setResolvedQuestionnaireValues(name: string, values: string[]): Promise<void> {\n await this.setState(state => ({\n ...state,\n resolvedQuestionnaireValues: {\n ...state.resolvedQuestionnaireValues,\n [name]: values\n }\n }));\n }\n\n // === VISITOR UUID ===\n\n /**\n * Reads the persisted visitor UUID from the KV store.\n *\n * @returns The visitor UUID string or null when not yet set.\n */\n async getVisitorUUID(): Promise<string | null> {\n const user = await kvGet<{ visitor_uuid?: string }>(\"user\");\n return user?.visitor_uuid ?? null;\n }\n\n /**\n * Persists a visitor UUID to the KV store.\n *\n * @param vid - Visitor UUID string returned by the session API.\n */\n async setVisitorUUID(vid: string): Promise<void> {\n const current = await kvGet<Record<string, unknown>>(\"user\");\n const safe = current !== null && typeof current === \"object\" && !Array.isArray(current) ? current : {};\n await kvSet(\"user\", { ...safe, visitor_uuid: vid });\n }\n\n /**\n * Removes the visitor UUID from the KV store.\n * Use when the stored UUID is stale (e.g. bootstrap returns 404).\n */\n async clearVisitorUUID(): Promise<void> {\n const current = await kvGet<Record<string, unknown>>(\"user\");\n if (current === null || typeof current !== \"object\" || Array.isArray(current)) return;\n const { visitor_uuid: _, ...rest } = current;\n await kvSet(\"user\", rest);\n }\n\n // === UTILITY METHODS ===\n\n /**\n * Builds a canonical results URL based on the current property slug.\n *\n * @returns Relative results URL or null when no property is selected.\n */\n async getResultsUrl(): Promise<string | null> {\n const state = await this.getState();\n return state.currentPropertySlug ? `/${state.currentPropertySlug}/results` : null;\n }\n\n /**\n * Retrieves the currently selected property entry.\n *\n * @returns Property state or null when unset.\n */\n async getCurrentProperty(): Promise<UserPropertyState | null> {\n const state = await this.getState();\n return state.currentPropertyId ? state.properties[state.currentPropertyId] ?? null : null;\n }\n\n /**\n * Retrieves property data for a specific property or defaults to the current property.\n *\n * @param propertyId - Optional property identifier to fetch.\n * @returns Property state or null when unavailable.\n */\n async getPropertyData(propertyId?: string | number): Promise<UserPropertyState | null> {\n const state = await this.getState();\n const id = propertyId == null ? state.currentPropertyId : String(propertyId);\n return id ? state.properties[id] ?? null : null;\n }\n\n /**\n * Reads and returns the full validated unified store state.\n */\n async getFullState(): Promise<UnifiedStoreData> {\n return this.getState();\n }\n\n /**\n * Hydrates the store with the default scaffold when no data has been persisted yet.\n */\n async initialize(): Promise<void> {\n // Ensure default shape is present; no-op if already initialized\n await this.setState(state => ({ ...defaultUnifiedStoreData, ...state }));\n }\n\n}\n\n// Export singleton instance\nexport const store = new UnifiedStore();\n// Alias to prefer neutral naming going forward\nexport { UnifiedStore as Store };\n// Re-export types for convenience (tests import from this module)\nexport type { UserPropertyState, Filters } from \"../schema\";\n"],"names":["defaultFilters","defaultUnifiedStoreData","UnifiedStore","state","kvGet","merged","parsed","UnifiedStoreDataSchema","sanitizedProperties","acc","key","value","entry","UserPropertyStateSchema","sanitizedUnitResults","UnitSchema","fallback","fallbackParsed","updater","currentState","newState","validatedState","kvSet","timeoutMs","deadline","propertyId","resolve","finalState","slug","id","units","schema","baseSchema","validatedUnits","unit","index","validate","data","PropertySchema","property","validated","partial","current","full","partialSchema","validatedPartial","apiProperty","existing","next","unitId","url","today","formattedDate","updatedViewedUnits","_a","results","filters","apiParams","transformFiltersToUnitsSearchParams","mode","sortBy","name","values","user","vid","safe","_","rest","store"],"mappings":";;;;AAsBA,MAAMA,IAA0B;AAAA,EAC9B,mBAAmB;AAAA,EACnB,cAAc;AAAA,EACd,YAAY;AAAA,EACZ,YAAY;AACd,GAEMC,IAA4C;AAAA;AAAA,EAEhD,YAAY,CAAA;AAAA,EACZ,mBAAmB;AAAA,EACnB,qBAAqB;AAAA,EACrB,uBAAuB,CAAA;AAAA;AAAA,EAGvB,aAAa,CAAA;AAAA,EACb,SAASD;AAAA,EACT,aAAaA;AAAA,EACb,YAAY;AAAA,IACV,OAAO;AAAA,IACP,MAAM;AAAA,IACN,QAAQ;AAAA,EAAA;AAAA,EAEV,aAAa;AAAA,EACb,6B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AAA,EACzE;AAEF;AAGO,MAAMiE,IAAQ,IAAIlE,EAAA;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superbright/indexeddb-orm",
3
- "version": "1.0.29",
3
+ "version": "1.0.31",
4
4
  "description": "Vite + TypeScript starter for an IndexedDB ORM (Dexie + Zod) with playground.",
5
5
  "license": "UNLICENSED",
6
6
  "type": "module",
@@ -1,2 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("../db.cjs"),l=require("./users.cjs"),c=require("../schema.cjs"),g=(e,t)=>`favorites:${e}:${t}`;async function u(e){const t=await v.getDB(),{uuid:a}=await l.ensureUser(),n=g(a,String(e)),r=await t.kv.get(n),s=r?c.FavoritesSchema.safeParse(r.value):null;return s!=null&&s.success?s.data.unitIds:[]}async function w(e,t,a){const n=await v.getDB(),{uuid:r}=await l.ensureUser(),s=g(r,String(e));return n.transaction("rw",n.kv,async()=>{const i=await n.kv.get(s),F=i&&c.FavoritesSchema.safeParse(i.value).success?i.value:{unitIds:[],updatedAt:new Date().toISOString()},o=new Set(F.unitIds);a?o.add(t):o.delete(t);const S={unitIds:[...o],updatedAt:new Date().toISOString()},d=c.FavoritesSchema.parse(S);return await n.kv.put({key:s,value:d}),d.unitIds})}async function y(e,t){const n=!(await u(e)).includes(t);return w(e,t,n)}async function U(e,t){return(await u(e)).includes(t)}exports.getFavoritedUnitsForProperty=u;exports.isUnitFavorited=U;exports.setFavoriteUnit=w;exports.toggleFavoriteUnit=y;
2
- //# sourceMappingURL=favorites.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"favorites.cjs","sources":["../../src/api/favorites.ts"],"sourcesContent":["// src/api/favourites.ts\nimport { getDB } from \"../db\";\nimport { ensureUser } from \"./users\";\nimport { FavoritesSchema } from \"../schema\";\n\nconst keyFor = (userId: string, propertyId: string) =>\n `favorites:${userId}:${propertyId}`;\n\nexport async function getFavoritedUnitsForProperty(\n propertyId: string | number,\n): Promise<string[]> {\n const db = await getDB();\n const { uuid } = await ensureUser();\n const key = keyFor(uuid, String(propertyId));\n const row = await db.kv.get(key);\n const parsed = row ? FavoritesSchema.safeParse(row.value) : null;\n return parsed?.success ? parsed.data.unitIds : [];\n}\n\nexport async function setFavoriteUnit(\n propertyId: string | number,\n unitId: string,\n on: boolean,\n): Promise<string[]> {\n const db = await getDB();\n const { uuid } = await ensureUser();\n const key = keyFor(uuid, String(propertyId));\n\n return db.transaction(\"rw\", db.kv, async () => {\n const row = await db.kv.get(key);\n const current =\n row && FavoritesSchema.safeParse(row.value).success\n ? (row!.value as any)\n : { unitIds: [] as string[], updatedAt: new Date().toISOString() };\n\n const nextSet = new Set<string>(current.unitIds);\n on ? nextSet.add(unitId) : nextSet.delete(unitId);\n\n const next = {\n unitIds: [...nextSet],\n updatedAt: new Date().toISOString(),\n };\n const validated = FavoritesSchema.parse(next);\n await db.kv.put({ key, value: validated });\n return validated.unitIds;\n });\n}\n\nexport async function toggleFavoriteUnit(\n propertyId: string | number,\n unitId: string,\n): Promise<string[]> {\n const current = await getFavoritedUnitsForProperty(propertyId);\n const on = !current.includes(unitId);\n return setFavoriteUnit(propertyId, unitId, on);\n}\n\nexport async function isUnitFavorited(\n propertyId: string | number,\n unitId: string,\n): Promise<boolean> {\n const list = await getFavoritedUnitsForProperty(propertyId);\n return list.includes(unitId);\n}\n"],"names":["keyFor","userId","propertyId","getFavoritedUnitsForProperty","db","getDB","uuid","ensureUser","key","row","parsed","FavoritesSchema","setFavoriteUnit","unitId","on","current","nextSet","next","validated","toggleFavoriteUnit","isUnitFavorited"],"mappings":"iKAKMA,EAAS,CAACC,EAAgBC,IAC9B,aAAaD,CAAM,IAAIC,CAAU,GAEnC,eAAsBC,EACpBD,EACmB,CACnB,MAAME,EAAK,MAAMC,QAAA,EACX,CAAE,KAAAC,GAAS,MAAMC,aAAA,EACjBC,EAAMR,EAAOM,EAAM,OAAOJ,CAAU,CAAC,EACrCO,EAAM,MAAML,EAAG,GAAG,IAAII,CAAG,EACzBE,EAASD,EAAME,EAAAA,gBAAgB,UAAUF,EAAI,KAAK,EAAI,KAC5D,OAAOC,GAAA,MAAAA,EAAQ,QAAUA,EAAO,KAAK,QAAU,CAAA,CACjD,CAEA,eAAsBE,EACpBV,EACAW,EACAC,EACmB,CACnB,MAAMV,EAAK,MAAMC,QAAA,EACX,CAAE,KAAAC,GAAS,MAAMC,aAAA,EACjBC,EAAMR,EAAOM,EAAM,OAAOJ,CAAU,CAAC,EAE3C,OAAOE,EAAG,YAAY,KAAMA,EAAG,GAAI,SAAY,CAC7C,MAAMK,EAAM,MAAML,EAAG,GAAG,IAAII,CAAG,EACzBO,EACJN,GAAOE,EAAAA,gBAAgB,UAAUF,EAAI,KAAK,EAAE,QACvCA,EAAK,MACN,CAAE,QAAS,GAAgB,cAAe,KAAA,EAAO,aAAY,EAE7DO,EAAU,IAAI,IAAYD,EAAQ,OAAO,EAC/CD,EAAKE,EAAQ,IAAIH,CAAM,EAAIG,EAAQ,OAAOH,CAAM,EAEhD,MAAMI,EAAO,CACX,QAAS,CAAC,GAAGD,CAAO,EACpB,UAAW,IAAI,KAAA,EAAO,YAAA,CAAY,EAE9BE,EAAYP,EAAAA,gBAAgB,MAAMM,CAAI,EAC5C,aAAMb,EAAG,GAAG,IAAI,CAAE,IAAAI,EAAK,MAAOU,EAAW,EAClCA,EAAU,OACnB,CAAC,CACH,CAEA,eAAsBC,EACpBjB,EACAW,EACmB,CAEnB,MAAMC,EAAK,EADK,MAAMX,EAA6BD,CAAU,GACzC,SAASW,CAAM,EACnC,OAAOD,EAAgBV,EAAYW,EAAQC,CAAE,CAC/C,CAEA,eAAsBM,EACpBlB,EACAW,EACkB,CAElB,OADa,MAAMV,EAA6BD,CAAU,GAC9C,SAASW,CAAM,CAC7B"}
@@ -1,4 +0,0 @@
1
- export declare function getFavoritedUnitsForProperty(propertyId: string | number): Promise<string[]>;
2
- export declare function setFavoriteUnit(propertyId: string | number, unitId: string, on: boolean): Promise<string[]>;
3
- export declare function toggleFavoriteUnit(propertyId: string | number, unitId: string): Promise<string[]>;
4
- export declare function isUnitFavorited(propertyId: string | number, unitId: string): Promise<boolean>;
@@ -1,34 +0,0 @@
1
- import { getDB as d } from "../db.mjs";
2
- import { ensureUser as v } from "./users.mjs";
3
- import { FavoritesSchema as c } from "../schema.mjs";
4
- const w = (n, t) => `favorites:${n}:${t}`;
5
- async function l(n) {
6
- const t = await d(), { uuid: s } = await v(), e = w(s, String(n)), o = await t.kv.get(e), a = o ? c.safeParse(o.value) : null;
7
- return a != null && a.success ? a.data.unitIds : [];
8
- }
9
- async function S(n, t, s) {
10
- const e = await d(), { uuid: o } = await v(), a = w(o, String(n));
11
- return e.transaction("rw", e.kv, async () => {
12
- const r = await e.kv.get(a), f = r && c.safeParse(r.value).success ? r.value : { unitIds: [], updatedAt: (/* @__PURE__ */ new Date()).toISOString() }, i = new Set(f.unitIds);
13
- s ? i.add(t) : i.delete(t);
14
- const g = {
15
- unitIds: [...i],
16
- updatedAt: (/* @__PURE__ */ new Date()).toISOString()
17
- }, u = c.parse(g);
18
- return await e.kv.put({ key: a, value: u }), u.unitIds;
19
- });
20
- }
21
- async function F(n, t) {
22
- const e = !(await l(n)).includes(t);
23
- return S(n, t, e);
24
- }
25
- async function p(n, t) {
26
- return (await l(n)).includes(t);
27
- }
28
- export {
29
- l as getFavoritedUnitsForProperty,
30
- p as isUnitFavorited,
31
- S as setFavoriteUnit,
32
- F as toggleFavoriteUnit
33
- };
34
- //# sourceMappingURL=favorites.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"favorites.mjs","sources":["../../src/api/favorites.ts"],"sourcesContent":["// src/api/favourites.ts\nimport { getDB } from \"../db\";\nimport { ensureUser } from \"./users\";\nimport { FavoritesSchema } from \"../schema\";\n\nconst keyFor = (userId: string, propertyId: string) =>\n `favorites:${userId}:${propertyId}`;\n\nexport async function getFavoritedUnitsForProperty(\n propertyId: string | number,\n): Promise<string[]> {\n const db = await getDB();\n const { uuid } = await ensureUser();\n const key = keyFor(uuid, String(propertyId));\n const row = await db.kv.get(key);\n const parsed = row ? FavoritesSchema.safeParse(row.value) : null;\n return parsed?.success ? parsed.data.unitIds : [];\n}\n\nexport async function setFavoriteUnit(\n propertyId: string | number,\n unitId: string,\n on: boolean,\n): Promise<string[]> {\n const db = await getDB();\n const { uuid } = await ensureUser();\n const key = keyFor(uuid, String(propertyId));\n\n return db.transaction(\"rw\", db.kv, async () => {\n const row = await db.kv.get(key);\n const current =\n row && FavoritesSchema.safeParse(row.value).success\n ? (row!.value as any)\n : { unitIds: [] as string[], updatedAt: new Date().toISOString() };\n\n const nextSet = new Set<string>(current.unitIds);\n on ? nextSet.add(unitId) : nextSet.delete(unitId);\n\n const next = {\n unitIds: [...nextSet],\n updatedAt: new Date().toISOString(),\n };\n const validated = FavoritesSchema.parse(next);\n await db.kv.put({ key, value: validated });\n return validated.unitIds;\n });\n}\n\nexport async function toggleFavoriteUnit(\n propertyId: string | number,\n unitId: string,\n): Promise<string[]> {\n const current = await getFavoritedUnitsForProperty(propertyId);\n const on = !current.includes(unitId);\n return setFavoriteUnit(propertyId, unitId, on);\n}\n\nexport async function isUnitFavorited(\n propertyId: string | number,\n unitId: string,\n): Promise<boolean> {\n const list = await getFavoritedUnitsForProperty(propertyId);\n return list.includes(unitId);\n}\n"],"names":["keyFor","userId","propertyId","getFavoritedUnitsForProperty","db","getDB","uuid","ensureUser","key","row","parsed","FavoritesSchema","setFavoriteUnit","unitId","on","current","nextSet","next","validated","toggleFavoriteUnit","isUnitFavorited"],"mappings":";;;AAKA,MAAMA,IAAS,CAACC,GAAgBC,MAC9B,aAAaD,CAAM,IAAIC,CAAU;AAEnC,eAAsBC,EACpBD,GACmB;AACnB,QAAME,IAAK,MAAMC,EAAA,GACX,EAAE,MAAAC,MAAS,MAAMC,EAAA,GACjBC,IAAMR,EAAOM,GAAM,OAAOJ,CAAU,CAAC,GACrCO,IAAM,MAAML,EAAG,GAAG,IAAII,CAAG,GACzBE,IAASD,IAAME,EAAgB,UAAUF,EAAI,KAAK,IAAI;AAC5D,SAAOC,KAAA,QAAAA,EAAQ,UAAUA,EAAO,KAAK,UAAU,CAAA;AACjD;AAEA,eAAsBE,EACpBV,GACAW,GACAC,GACmB;AACnB,QAAMV,IAAK,MAAMC,EAAA,GACX,EAAE,MAAAC,MAAS,MAAMC,EAAA,GACjBC,IAAMR,EAAOM,GAAM,OAAOJ,CAAU,CAAC;AAE3C,SAAOE,EAAG,YAAY,MAAMA,EAAG,IAAI,YAAY;AAC7C,UAAMK,IAAM,MAAML,EAAG,GAAG,IAAII,CAAG,GACzBO,IACJN,KAAOE,EAAgB,UAAUF,EAAI,KAAK,EAAE,UACvCA,EAAK,QACN,EAAE,SAAS,IAAgB,gCAAe,KAAA,GAAO,cAAY,GAE7DO,IAAU,IAAI,IAAYD,EAAQ,OAAO;AAC/C,IAAAD,IAAKE,EAAQ,IAAIH,CAAM,IAAIG,EAAQ,OAAOH,CAAM;AAEhD,UAAMI,IAAO;AAAA,MACX,SAAS,CAAC,GAAGD,CAAO;AAAA,MACpB,YAAW,oBAAI,KAAA,GAAO,YAAA;AAAA,IAAY,GAE9BE,IAAYP,EAAgB,MAAMM,CAAI;AAC5C,iBAAMb,EAAG,GAAG,IAAI,EAAE,KAAAI,GAAK,OAAOU,GAAW,GAClCA,EAAU;AAAA,EACnB,CAAC;AACH;AAEA,eAAsBC,EACpBjB,GACAW,GACmB;AAEnB,QAAMC,IAAK,EADK,MAAMX,EAA6BD,CAAU,GACzC,SAASW,CAAM;AACnC,SAAOD,EAAgBV,GAAYW,GAAQC,CAAE;AAC/C;AAEA,eAAsBM,EACpBlB,GACAW,GACkB;AAElB,UADa,MAAMV,EAA6BD,CAAU,GAC9C,SAASW,CAAM;AAC7B;"}
@@ -1,2 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=require("../storage.cjs"),s=require("../schema.cjs"),c={data:{},propertySlug:null,propertyId:null,hasPreviouslySearched:[]};class l{async getState(){const e=await y.kvGet("property");if(!e)return c;const t={...e,propertyId:e.propertyId==null?null:String(e.propertyId),propertySlug:e.propertySlug??null,hasPreviouslySearched:Array.isArray(e.hasPreviouslySearched)?e.hasPreviouslySearched.map(String):[]},r=s.PropertyStoreDataSchema.safeParse(t);if(r.success)return r.data;const a=Object.entries(t.data??{}).reduce((i,[d,p])=>{const u=s.UserPropertyStateSchema.safeParse(p);return u.success&&(i[d]=u.data),i},{}),n={...c,...t,data:a},o=s.PropertyStoreDataSchema.safeParse(n);return o.success?o.data:c}async setState(e){const t=await this.getState(),r=e(t),a=s.PropertyStoreDataSchema.parse(r);await y.kvSet("property",a)}async setHasPreviouslySearched(e){await this.setState(t=>({...t,hasPreviouslySearched:Array.from(new Set([...t.hasPreviouslySearched,e]))}))}async setTourContactedOn(){await this.setState(e=>{const t=e.propertyId;if(!t)return e;const r=e.data[t];return r?{...e,data:{...e.data,[t]:{...r,tourContactedOn:new Date().toISOString()}}}:e})}async getTourContactedOn(){var r;const e=await this.getState(),t=e.propertyId;return t?((r=e.data[t])==null?void 0:r.tourContactedOn)??null:null}async setQuestionnaireResults(e){await this.setState(t=>{const r=t.propertyId;if(!r)return t;const a=t.data[r];return a?{...t,data:{...t.data,[r]:{...a,questionnaireResults:e}}}:t})}async setTourContactData(e){await this.setState(t=>{const r=t.propertyId;if(!r)return t;const a=t.data[r];return a?{...t,data:{...t.data,[r]:{...a,tourContactData:e}}}:t})}async toggleFavorite(e){await this.setState(t=>{const r=t.propertyId;if(!r)return t;const a=t.data[r];if(!a)return t;const o=a.favoritedUnits.includes(e)?a.favoritedUnits.filter(i=>i!==e):[...a.favoritedUnits,e];return{...t,data:{...t.data,[r]:{...a,favoritedUnits:o}}}})}async markUnitAsViewed(e,t){const r=new Date,a=`${String(r.getMonth()+1).padStart(2,"0")}/${String(r.getDate()).padStart(2,"0")}`;await this.setState(n=>{const o=n.propertyId;if(!o)return n;const i=n.data[o];if(!i)return n;const d=[...i.viewedUnits.filter(p=>p.unitId!==e),{unitId:e,viewedDate:a}];return{...n,data:{...n.data,[o]:{...i,viewedUnits:d}}}}),typeof window<"u"&&window.open(`//${t}`,"_blank")}async getUnitState(e){var a;const t=await this.getState(),r=t.propertyId?t.data[t.propertyId]:null;return{isFavorite:(r==null?void 0:r.favoritedUnits.includes(e))??!1,viewedDate:((a=r==null?void 0:r.viewedUnits.find(n=>n.unitId===e))==null?void 0:a.viewedDate)??""}}async getPropertyData(e){const t=await this.getState(),r=e==null?t.propertyId:String(e);return r?t.data[r]??null:null}async getCurrentProperty(){const e=await this.getState();return e.propertyId?e.data[e.propertyId]??null:null}async getFullState(){return this.getState()}async initializeProperty(e,t){const r=String(e);await this.setState(a=>a.data[r]?{...a,propertyId:r,propertySlug:t}:{...a,propertyId:r,propertySlug:t,data:{...a.data,[r]:{id:r,slug:t,favoritedUnits:[],tourContactedOn:null,viewedUnits:[],questionnaireResults:null,tourContactData:null}}})}}const S=new l;exports.PropertyStore=l;exports.propertyStore=S;
2
- //# sourceMappingURL=properties.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"properties.cjs","sources":["../../src/api/properties.ts"],"sourcesContent":["import { kvGet, kvSet } from \"../storage\";\nimport {\n ViewedUnitSchema,\n TourContactDataSchema,\n UserPropertyStateSchema,\n PropertyStoreDataSchema,\n type ViewedUnit,\n type TourContactData,\n type UserPropertyState,\n type PropertyStoreData,\n} from \"../schema\";\n\n// Re-export types for legacy import paths\nexport type { ViewedUnit, TourContactData, UserPropertyState, PropertyStoreData } from \"../schema\";\n\n// Default state\nconst defaultPropertyStoreData: PropertyStoreData = {\n data: {},\n propertySlug: null,\n propertyId: null,\n hasPreviouslySearched: [],\n};\n\n// Core property store API\nexport class PropertyStore {\n private async getState(): Promise<PropertyStoreData> {\n const state = await kvGet<PropertyStoreData>(\"property\");\n if (!state) return defaultPropertyStoreData;\n\n const normalized = {\n ...state,\n propertyId: state.propertyId == null ? null : String(state.propertyId),\n propertySlug: state.propertySlug ?? null,\n hasPreviouslySearched: Array.isArray(state.hasPreviouslySearched)\n ? state.hasPreviouslySearched.map(String)\n : [],\n };\n\n const parsed = PropertyStoreDataSchema.safeParse(normalized);\n if (parsed.success) return parsed.data;\n\n const sanitizedData = Object.entries(normalized.data ?? {}).reduce<\n Record<string, UserPropertyState>\n >((acc, [key, value]) => {\n const entry = UserPropertyStateSchema.safeParse(value);\n if (entry.success) acc[key] = entry.data;\n return acc;\n }, {});\n\n const fallbackState = {\n ...defaultPropertyStoreData,\n ...normalized,\n data: sanitizedData,\n };\n\n const fallbackParsed = PropertyStoreDataSchema.safeParse(fallbackState);\n return fallbackParsed.success ? fallbackParsed.data : defaultPropertyStoreData;\n }\n\n private async setState(updater: (state: PropertyStoreData) => PropertyStoreData): Promise<void> {\n const currentState = await this.getState();\n const newState = updater(currentState);\n const validatedState = PropertyStoreDataSchema.parse(newState);\n await kvSet(\"property\", validatedState);\n }\n\n // Basic state operations (legacy direct setters removed in vNext)\n\n async setHasPreviouslySearched(slug: string): Promise<void> {\n await this.setState(state => ({\n ...state,\n hasPreviouslySearched: Array.from(\n new Set([...state.hasPreviouslySearched, slug])\n ),\n }));\n }\n\n // Property-specific operations\n async setTourContactedOn(): Promise<void> {\n await this.setState(state => {\n const propertyId = state.propertyId;\n if (!propertyId) return state;\n\n const property = state.data[propertyId];\n if (!property) return state;\n\n return {\n ...state,\n data: {\n ...state.data,\n [propertyId]: {\n ...property,\n tourContactedOn: new Date().toISOString(),\n },\n },\n };\n });\n }\n\n async getTourContactedOn(): Promise<string | null> {\n const state = await this.getState();\n const propertyId = state.propertyId;\n if (!propertyId) return null;\n\n return state.data[propertyId]?.tourContactedOn ?? null;\n }\n\n async setQuestionnaireResults(results: unknown): Promise<void> {\n await this.setState(state => {\n const propertyId = state.propertyId;\n if (!propertyId) return state;\n\n const property = state.data[propertyId];\n if (!property) return state;\n\n return {\n ...state,\n data: {\n ...state.data,\n [propertyId]: {\n ...property,\n questionnaireResults: results,\n },\n },\n };\n });\n }\n\n async setTourContactData(data: TourContactData): Promise<void> {\n await this.setState(state => {\n const propertyId = state.propertyId;\n if (!propertyId) return state;\n\n const property = state.data[propertyId];\n if (!property) return state;\n\n return {\n ...state,\n data: {\n ...state.data,\n [propertyId]: {\n ...property,\n tourContactData: data,\n },\n },\n };\n });\n }\n\n async toggleFavorite(unitId: string): Promise<void> {\n await this.setState(state => {\n const propertyId = state.propertyId;\n if (!propertyId) return state;\n\n const property = state.data[propertyId];\n if (!property) return state;\n\n const isFavorited = property.favoritedUnits.includes(unitId);\n const updatedFavoritedUnits = isFavorited\n ? property.favoritedUnits.filter((id) => id !== unitId)\n : [...property.favoritedUnits, unitId];\n\n return {\n ...state,\n data: {\n ...state.data,\n [propertyId]: {\n ...property,\n favoritedUnits: updatedFavoritedUnits,\n },\n },\n };\n });\n }\n\n async markUnitAsViewed(unitId: string, slug: string): Promise<void> {\n const today = new Date();\n const formattedDate = `${String(today.getMonth() + 1).padStart(\n 2,\n \"0\"\n )}/${String(today.getDate()).padStart(2, \"0\")}`;\n\n await this.setState(state => {\n const propertyId = state.propertyId;\n if (!propertyId) return state;\n\n const property = state.data[propertyId];\n if (!property) return state;\n\n const updatedViewedUnits = [\n // Remove existing entry if it exists\n ...property.viewedUnits.filter((u) => u.unitId !== unitId),\n // Add updated one\n {\n unitId,\n viewedDate: formattedDate,\n },\n ];\n\n return {\n ...state,\n data: {\n ...state.data,\n [propertyId]: {\n ...property,\n viewedUnits: updatedViewedUnits,\n },\n },\n };\n });\n\n // Note: This opens a new window - you might want to handle this in the consuming app\n if (typeof window !== 'undefined') {\n window.open(`//${slug}`, \"_blank\");\n }\n }\n\n // Utility methods for getting specific data\n async getUnitState(unitId: string): Promise<{\n isFavorite: boolean;\n viewedDate: string;\n }> {\n const state = await this.getState();\n const property = state.propertyId ? state.data[state.propertyId] : null;\n\n return {\n isFavorite: property?.favoritedUnits.includes(unitId) ?? false,\n viewedDate:\n property?.viewedUnits.find((u) => u.unitId === unitId)?.viewedDate ?? \"\",\n };\n }\n\n async getPropertyData(propertyId?: string | number): Promise<UserPropertyState | null> {\n const state = await this.getState();\n const id = propertyId == null ? state.propertyId : String(propertyId);\n return id ? state.data[id] ?? null : null;\n }\n\n async getCurrentProperty(): Promise<UserPropertyState | null> {\n const state = await this.getState();\n return state.propertyId ? state.data[state.propertyId] ?? null : null;\n }\n\n async getFullState(): Promise<PropertyStoreData> {\n return this.getState();\n }\n\n // Initialize property if it doesn't exist\n async initializeProperty(propertyId: string | number, slug: string): Promise<void> {\n const id = String(propertyId);\n await this.setState(state => {\n if (state.data[id]) {\n return { ...state, propertyId: id, propertySlug: slug };\n }\n\n return {\n ...state,\n propertyId: id,\n propertySlug: slug,\n data: {\n ...state.data,\n [id]: {\n id,\n slug,\n favoritedUnits: [],\n tourContactedOn: null,\n viewedUnits: [],\n questionnaireResults: null,\n tourContactData: null,\n },\n },\n };\n });\n }\n}\n\n// Export singleton instance\nexport const propertyStore = new PropertyStore();\n"],"names":["defaultPropertyStoreData","PropertyStore","state","kvGet","normalized","parsed","PropertyStoreDataSchema","sanitizedData","acc","key","value","entry","UserPropertyStateSchema","fallbackState","fallbackParsed","updater","currentState","newState","validatedState","kvSet","slug","propertyId","property","_a","results","data","unitId","updatedFavoritedUnits","id","today","formattedDate","updatedViewedUnits","u","propertyStore"],"mappings":"6IAgBMA,EAA8C,CAClD,KAAM,CAAA,EACN,aAAc,KACd,WAAY,KACZ,sBAAuB,CAAA,CACzB,EAGO,MAAMC,CAAc,CACzB,MAAc,UAAuC,CACnD,MAAMC,EAAQ,MAAMC,EAAAA,MAAyB,UAAU,EACvD,GAAI,CAACD,EAAO,OAAOF,EAEnB,MAAMI,EAAa,CACjB,GAAGF,EACH,WAAYA,EAAM,YAAc,KAAO,KAAO,OAAOA,EAAM,UAAU,EACrE,aAAcA,EAAM,cAAgB,KACpC,sBAAuB,MAAM,QAAQA,EAAM,qBAAqB,EAC5DA,EAAM,sBAAsB,IAAI,MAA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