@wix/himalaya-cli 0.2016.0 → 0.2018.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/dev-server/src/app-config.d.ts +14 -0
- package/dist/browser-plane/assets.json +5 -5
- package/dist/browser-plane/preview-deferred/{c5078f43cc09f68f520bdcc966dac09b9005f22c16cc4eeac0ace1ae295cd684.bin → dda1fb76c0d4cd06bff81e83b374bfbf1937f894c6f2228ec6cd7140743d0775.bin} +1 -1
- package/dist/browser-plane/sw.js +10 -10
- package/dist/cli.mjs +81 -56
- package/dist/preview-assets.generated.bin +0 -0
- package/guides/widgets.md +4 -2
- package/package.json +2 -2
- package/templates/beauty-salon-owner/dev/index.ts +237 -200
- package/templates/beauty-salon-owner/himalaya.content.json +9 -0
- package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-today/glance.ts +274 -0
- package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-today/index.ts +89 -37
- package/templates/branded-lite/recipes/products-carousel.json +1 -1
- package/templates/branded-lite/recipes/products-grid.json +1 -1
- package/templates/branded-lite/tier5-src/_shared/products-section.ts +3 -1
- package/templates/community-club-owner/dev/index.ts +314 -49
- package/templates/community-club-owner/himalaya.content.json +9 -0
- package/templates/community-club-owner/tier5-src/himi-owner-lite-today/glance.ts +274 -0
- package/templates/community-club-owner/tier5-src/himi-owner-lite-today/index.ts +89 -37
- package/templates/events-meetups-owner/dev/index.ts +330 -23
- package/templates/events-meetups-owner/himalaya.content.json +9 -0
- package/templates/events-meetups-owner/tier5-src/himi-owner-lite-today/glance.ts +274 -0
- package/templates/events-meetups-owner/tier5-src/himi-owner-lite-today/index.ts +89 -37
- package/templates/gym-fitness-owner/dev/index.ts +237 -200
- package/templates/gym-fitness-owner/himalaya.content.json +9 -0
- package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-today/glance.ts +274 -0
- package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-today/index.ts +89 -37
- package/templates/nonprofit-cause-owner/dev/index.ts +237 -158
- package/templates/nonprofit-cause-owner/himalaya.content.json +9 -0
- package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-today/glance.ts +274 -0
- package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-today/index.ts +89 -37
- package/templates/owner-lite/dev/index.ts +237 -200
- package/templates/owner-lite/himalaya.content.json +9 -0
- package/templates/owner-lite/tier5-src/himi-owner-lite-today/glance.ts +274 -0
- package/templates/owner-lite/tier5-src/himi-owner-lite-today/index.ts +89 -37
- package/templates/podcast-creator-owner/dev/index.ts +314 -49
- package/templates/podcast-creator-owner/himalaya.content.json +9 -0
- package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-today/glance.ts +274 -0
- package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-today/index.ts +89 -37
- package/templates/portfolio-creative-owner/dev/index.ts +237 -200
- package/templates/portfolio-creative-owner/himalaya.content.json +9 -0
- package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-today/glance.ts +274 -0
- package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-today/index.ts +89 -37
- package/templates/restaurant-owner/dev/index.ts +237 -200
- package/templates/restaurant-owner/himalaya.content.json +9 -0
- package/templates/restaurant-owner/tier5-src/himi-owner-lite-today/glance.ts +274 -0
- package/templates/restaurant-owner/tier5-src/himi-owner-lite-today/index.ts +89 -37
- package/templates/retail-store-owner/dev/index.ts +314 -49
- package/templates/retail-store-owner/himalaya.content.json +9 -0
- package/templates/retail-store-owner/tier5-src/himi-owner-lite-today/glance.ts +274 -0
- package/templates/retail-store-owner/tier5-src/himi-owner-lite-today/index.ts +89 -37
- package/templates/yoga-studio-owner/dev/index.ts +237 -158
- package/templates/yoga-studio-owner/himalaya.content.json +9 -0
- package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-today/glance.ts +274 -0
- package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-today/index.ts +89 -37
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
// The GLANCE: "what matters now" across every area the business runs.
|
|
2
|
+
//
|
|
3
|
+
// Pure. The worker (index.ts) reads the business, turns each area into scored items here, ranks
|
|
4
|
+
// them, and spreads `glanceFields` into its state for the widget descriptors to bind. Scores are
|
|
5
|
+
// in ONE table (SCORE) so tuning them is one edit with tests beside it.
|
|
6
|
+
//
|
|
7
|
+
// Two audiences per item: the Home Screen fields may carry a client's first name (as the Today
|
|
8
|
+
// widget always has); every `lock*` field is shown on the Lock Screen and the watch face, where
|
|
9
|
+
// anyone near the phone can read it, so it is built only from name-free, money-free parts.
|
|
10
|
+
|
|
11
|
+
type Rec = Record<string, unknown>;
|
|
12
|
+
|
|
13
|
+
export type GlanceArea = "bookings" | "store" | "events" | "blog";
|
|
14
|
+
const AREA_ORDER: GlanceArea[] = ["bookings", "store", "events", "blog"];
|
|
15
|
+
|
|
16
|
+
export const SCORE = {
|
|
17
|
+
bookingWithinHour: 95,
|
|
18
|
+
eventWithinThreeHours: 90,
|
|
19
|
+
requests: 70,
|
|
20
|
+
ordersBase: 65,
|
|
21
|
+
ordersCountCap: 10,
|
|
22
|
+
bookingLaterToday: 60,
|
|
23
|
+
eventLaterToday: 55,
|
|
24
|
+
postScheduledToday: 40,
|
|
25
|
+
eventThisWeek: 25,
|
|
26
|
+
bookingLater: 20,
|
|
27
|
+
drafts: 10,
|
|
28
|
+
} as const;
|
|
29
|
+
|
|
30
|
+
export interface GlanceItem {
|
|
31
|
+
area: GlanceArea;
|
|
32
|
+
score: number;
|
|
33
|
+
/** Home headline ("Balayage · Maya"). May carry a client first name. */
|
|
34
|
+
title: string;
|
|
35
|
+
/** Home detail line ("Today", "142 registered"). */
|
|
36
|
+
detail: string;
|
|
37
|
+
/** "10:00", or "" for a count. */
|
|
38
|
+
timeLabel: string;
|
|
39
|
+
/** Epoch ms of the moment the item is about, for tie-breaks. */
|
|
40
|
+
at?: number;
|
|
41
|
+
count?: number;
|
|
42
|
+
/** A symbol name the descriptors may use. */
|
|
43
|
+
symbol: string;
|
|
44
|
+
/** Short, name-free label for the secondary line and the lock inline tail ("3 requests"). */
|
|
45
|
+
short: string;
|
|
46
|
+
/** Name-free Lock Screen / watch title ("10:00 Balayage") and detail ("Today"). */
|
|
47
|
+
lockTitle: string;
|
|
48
|
+
lockDetail: string;
|
|
49
|
+
/** The circular accessory: a value ("10:00", "7") over a tiny label ("next", "orders"). */
|
|
50
|
+
circValue: string;
|
|
51
|
+
circLabel: string;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface GlanceCopy {
|
|
55
|
+
allClear: string;
|
|
56
|
+
nothingWaiting: string;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export const GLANCE_COPY: GlanceCopy = { allClear: "All clear", nothingWaiting: "Nothing waiting" };
|
|
60
|
+
|
|
61
|
+
export interface GlanceFields {
|
|
62
|
+
glanceHeadline: string;
|
|
63
|
+
glanceDetail: string;
|
|
64
|
+
glanceTime: string;
|
|
65
|
+
hideGlanceTime: boolean;
|
|
66
|
+
glanceSymbol: string;
|
|
67
|
+
glanceSecondary: string;
|
|
68
|
+
hideGlanceSecondary: boolean;
|
|
69
|
+
glanceAllClear: boolean;
|
|
70
|
+
lockInline: string;
|
|
71
|
+
lockCircValue: string;
|
|
72
|
+
lockCircLabel: string;
|
|
73
|
+
lockRectTitle: string;
|
|
74
|
+
lockRectDetail: string;
|
|
75
|
+
lockRectSecondary: string;
|
|
76
|
+
lockHideSecondary: boolean;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const WEEKDAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
80
|
+
const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
81
|
+
const DAY_MS = 24 * 60 * 60 * 1000;
|
|
82
|
+
|
|
83
|
+
export function str(r: unknown, ...paths: string[]): string {
|
|
84
|
+
for (const path of paths) {
|
|
85
|
+
let v: unknown = r;
|
|
86
|
+
for (const k of path.split(".")) v = v && typeof v === "object" ? (v as Rec)[k] : undefined;
|
|
87
|
+
if (typeof v === "string" && v) return v;
|
|
88
|
+
if (typeof v === "number") return String(v);
|
|
89
|
+
}
|
|
90
|
+
return "";
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export function hhmm(d: Date): string {
|
|
94
|
+
return `${String(d.getHours()).padStart(2, "0")}:${String(d.getMinutes()).padStart(2, "0")}`;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function sameLocalDay(a: Date, b: Date): boolean {
|
|
98
|
+
return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** The day a moment falls on, as an owner would say it. */
|
|
102
|
+
export function dayLabel(start: Date, now: Date): string {
|
|
103
|
+
if (sameLocalDay(start, now)) return "Today";
|
|
104
|
+
const tomorrow = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1);
|
|
105
|
+
if (sameLocalDay(start, tomorrow)) return "Tomorrow";
|
|
106
|
+
return `${WEEKDAYS[start.getDay()]} ${start.getDate()} ${MONTHS[start.getMonth()]}`;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function plural(n: number, capped: boolean, cap: number, one: string, many: string): string {
|
|
110
|
+
return `${capped ? `${cap}+` : n} ${n === 1 && !capped ? one : many}`;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** The next booking (if any) and the booking requests waiting. */
|
|
114
|
+
export function bookingItems(
|
|
115
|
+
next: { start: Date; service: string; firstName: string } | undefined,
|
|
116
|
+
requestCount: number,
|
|
117
|
+
requestsCapped: boolean,
|
|
118
|
+
now: Date,
|
|
119
|
+
cap = 50,
|
|
120
|
+
): GlanceItem[] {
|
|
121
|
+
const items: GlanceItem[] = [];
|
|
122
|
+
if (next) {
|
|
123
|
+
const ms = next.start.getTime() - now.getTime();
|
|
124
|
+
const score = ms <= 60 * 60 * 1000 ? SCORE.bookingWithinHour
|
|
125
|
+
: sameLocalDay(next.start, now) ? SCORE.bookingLaterToday : SCORE.bookingLater;
|
|
126
|
+
const time = hhmm(next.start);
|
|
127
|
+
const day = dayLabel(next.start, now);
|
|
128
|
+
items.push({
|
|
129
|
+
area: "bookings", score, at: next.start.getTime(), symbol: "calendar",
|
|
130
|
+
title: next.firstName ? `${next.service} · ${next.firstName}` : next.service,
|
|
131
|
+
detail: day, timeLabel: time,
|
|
132
|
+
short: `${day === "Today" ? "" : `${day} `}${time} ${next.service}`.trim(),
|
|
133
|
+
lockTitle: `${time} ${next.service}`, lockDetail: day,
|
|
134
|
+
circValue: time, circLabel: "next",
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
if (requestCount > 0) {
|
|
138
|
+
const label = plural(requestCount, requestsCapped, cap, "request", "requests");
|
|
139
|
+
items.push({
|
|
140
|
+
area: "bookings", score: SCORE.requests, count: requestCount, symbol: "person",
|
|
141
|
+
title: `${plural(requestCount, requestsCapped, cap, "booking request", "booking requests")}`,
|
|
142
|
+
detail: "Waiting for you", timeLabel: "", short: label,
|
|
143
|
+
lockTitle: `${label} waiting`, lockDetail: "Bookings",
|
|
144
|
+
circValue: requestsCapped ? `${cap}+` : String(requestCount), circLabel: "req",
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
return items;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** Orders needing attention: 65 + the count, capped at +10. */
|
|
151
|
+
export function orderItems(count: number, capped: boolean, cap = 50): GlanceItem[] {
|
|
152
|
+
if (count <= 0) return [];
|
|
153
|
+
const label = plural(count, capped, cap, "order", "orders");
|
|
154
|
+
return [{
|
|
155
|
+
area: "store", score: SCORE.ordersBase + Math.min(count, SCORE.ordersCountCap), count, symbol: "bag",
|
|
156
|
+
title: `${label} to handle`, detail: "Store", timeLabel: "", short: label,
|
|
157
|
+
lockTitle: `${label} to handle`, lockDetail: "Store",
|
|
158
|
+
circValue: capped ? `${cap}+` : String(count), circLabel: "orders",
|
|
159
|
+
}];
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const LIVE_EVENT = ["UPCOMING", "SCHEDULED", "STARTED"];
|
|
163
|
+
|
|
164
|
+
/** The next event in the coming 7 days: ≤3 h today → 90, later today → 55, this week → 25. */
|
|
165
|
+
export function eventItems(events: Rec[], now: Date): GlanceItem[] {
|
|
166
|
+
const next = events
|
|
167
|
+
// `eventStatus` first: the events SDK decodes the v3 `status` into it, and that is the field
|
|
168
|
+
// the owner fixtures (and the events screen) carry.
|
|
169
|
+
.filter((e) => str(e, "id") && LIVE_EVENT.includes(str(e, "eventStatus", "status").toUpperCase()))
|
|
170
|
+
.map((e) => ({ e, start: new Date(str(e, "dateAndTimeSettings.startDate")) }))
|
|
171
|
+
.filter(({ start }) => !Number.isNaN(start.getTime()) && start.getTime() >= now.getTime() && start.getTime() - now.getTime() <= 7 * DAY_MS)
|
|
172
|
+
.sort((a, b) => a.start.getTime() - b.start.getTime())[0];
|
|
173
|
+
if (!next) return [];
|
|
174
|
+
const { e, start } = next;
|
|
175
|
+
const ms = start.getTime() - now.getTime();
|
|
176
|
+
const today = sameLocalDay(start, now);
|
|
177
|
+
const score = today && ms <= 3 * 60 * 60 * 1000 ? SCORE.eventWithinThreeHours
|
|
178
|
+
: today ? SCORE.eventLaterToday : SCORE.eventThisWeek;
|
|
179
|
+
const title = str(e, "title") || "Event";
|
|
180
|
+
const time = hhmm(start);
|
|
181
|
+
const day = dayLabel(start, now);
|
|
182
|
+
return [{
|
|
183
|
+
area: "events", score, at: start.getTime(), symbol: "ticket",
|
|
184
|
+
title, detail: day, timeLabel: time,
|
|
185
|
+
short: today ? `${title} ${time}` : `${title} ${day}`,
|
|
186
|
+
lockTitle: `${time} ${title}`, lockDetail: day,
|
|
187
|
+
circValue: time, circLabel: "event",
|
|
188
|
+
}];
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/** A post scheduled to publish today (40), and the drafts still unpublished (10). Only
|
|
192
|
+
* UNPUBLISHED counts as a draft: a trashed (DELETED) or unknown status is not work waiting. */
|
|
193
|
+
export function blogItems(drafts: Rec[], now: Date, cap = 50): GlanceItem[] {
|
|
194
|
+
const items: GlanceItem[] = [];
|
|
195
|
+
const rows = drafts.filter((d) => str(d, "id"));
|
|
196
|
+
const scheduled = rows
|
|
197
|
+
.filter((d) => str(d, "status").toUpperCase() === "SCHEDULED")
|
|
198
|
+
.map((d) => ({ d, at: new Date(str(d, "scheduledPublishDate")) }))
|
|
199
|
+
.filter(({ at }) => !Number.isNaN(at.getTime()) && at.getTime() >= now.getTime() && sameLocalDay(at, now))
|
|
200
|
+
.sort((a, b) => a.at.getTime() - b.at.getTime())[0];
|
|
201
|
+
if (scheduled) {
|
|
202
|
+
const title = str(scheduled.d, "title") || "Blog post";
|
|
203
|
+
const time = hhmm(scheduled.at);
|
|
204
|
+
items.push({
|
|
205
|
+
area: "blog", score: SCORE.postScheduledToday, at: scheduled.at.getTime(), symbol: "doc",
|
|
206
|
+
title, detail: `Publishes ${time}`, timeLabel: time, short: `Post at ${time}`,
|
|
207
|
+
// A fixed label, not the title: an unpublished post's title is not public yet, and the
|
|
208
|
+
// Lock Screen is read by anyone near the phone. Home keeps the title.
|
|
209
|
+
lockTitle: `${time} Post goes live`, lockDetail: "Blog",
|
|
210
|
+
circValue: time, circLabel: "post",
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
const draftCount = rows.filter((d) => str(d, "status").toUpperCase() === "UNPUBLISHED").length;
|
|
214
|
+
if (draftCount > 0) {
|
|
215
|
+
const label = plural(draftCount, draftCount >= cap, cap, "draft", "drafts");
|
|
216
|
+
items.push({
|
|
217
|
+
area: "blog", score: SCORE.drafts, count: draftCount, symbol: "doc",
|
|
218
|
+
title: `${label} in progress`, detail: "Blog", timeLabel: "", short: label,
|
|
219
|
+
lockTitle: `${label} in progress`, lockDetail: "Blog",
|
|
220
|
+
circValue: String(draftCount), circLabel: "drafts",
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
return items;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/** Highest score first; ties by the earlier moment, then by area order. Zero scores drop. */
|
|
227
|
+
export function rankItems(items: GlanceItem[]): GlanceItem[] {
|
|
228
|
+
return items
|
|
229
|
+
.filter((i) => i.score > 0)
|
|
230
|
+
.slice()
|
|
231
|
+
.sort((a, b) =>
|
|
232
|
+
b.score - a.score
|
|
233
|
+
|| (a.at ?? Infinity) - (b.at ?? Infinity)
|
|
234
|
+
|| AREA_ORDER.indexOf(a.area) - AREA_ORDER.indexOf(b.area));
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** When the frame stops being true: the earliest moment among the items it SHOWS (the headline
|
|
238
|
+
* and the two on the secondary line). A started booking, event or post is no longer "next". */
|
|
239
|
+
export function shownUntil(ranked: GlanceItem[]): number {
|
|
240
|
+
return Math.min(Infinity, ...ranked.slice(0, 3).map((i) => i.at ?? Infinity));
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/** The state fields the widget descriptors bind: the headline is the top item, the secondary
|
|
244
|
+
* line the next two. */
|
|
245
|
+
export function glanceFields(ranked: GlanceItem[], copy: GlanceCopy): GlanceFields {
|
|
246
|
+
const head = ranked[0];
|
|
247
|
+
if (!head) {
|
|
248
|
+
return {
|
|
249
|
+
glanceHeadline: copy.allClear, glanceDetail: copy.nothingWaiting, glanceTime: "", hideGlanceTime: true,
|
|
250
|
+
glanceSymbol: "checkmark", glanceSecondary: "", hideGlanceSecondary: true, glanceAllClear: true,
|
|
251
|
+
lockInline: copy.allClear, lockCircValue: "0", lockCircLabel: "waiting",
|
|
252
|
+
lockRectTitle: copy.allClear, lockRectDetail: copy.nothingWaiting, lockRectSecondary: "", lockHideSecondary: true,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
const rest = ranked.slice(1, 3).map((i) => i.short).filter(Boolean);
|
|
256
|
+
const secondary = rest.join(" · ");
|
|
257
|
+
return {
|
|
258
|
+
glanceHeadline: head.title,
|
|
259
|
+
glanceDetail: head.detail,
|
|
260
|
+
glanceTime: head.timeLabel,
|
|
261
|
+
hideGlanceTime: !head.timeLabel,
|
|
262
|
+
glanceSymbol: head.symbol,
|
|
263
|
+
glanceSecondary: secondary,
|
|
264
|
+
hideGlanceSecondary: !secondary,
|
|
265
|
+
glanceAllClear: false,
|
|
266
|
+
lockInline: rest[0] ? `${head.lockTitle} · ${rest[0]}` : head.lockTitle,
|
|
267
|
+
lockCircValue: head.circValue,
|
|
268
|
+
lockCircLabel: head.circLabel,
|
|
269
|
+
lockRectTitle: head.lockTitle,
|
|
270
|
+
lockRectDetail: head.lockDetail,
|
|
271
|
+
lockRectSecondary: secondary,
|
|
272
|
+
lockHideSecondary: !secondary,
|
|
273
|
+
};
|
|
274
|
+
}
|
|
@@ -19,8 +19,14 @@ import { searchOrders } from "@himalaya/wix-ecom";
|
|
|
19
19
|
import { ownerOrderAttentionFilter } from "../_shared/owner-order-attention.js";
|
|
20
20
|
import { readSelectedSite } from "../_shared/owner-selected-site.js";
|
|
21
21
|
import { isSectionUnavailable, isSignedOut } from "../_shared/owner-widget-reads.js";
|
|
22
|
+
import { queryEvents } from "@himalaya/wix-events";
|
|
23
|
+
import { queryDraftPosts } from "@himalaya/wix-blog";
|
|
24
|
+
import {
|
|
25
|
+
str, hhmm, sameLocalDay, dayLabel, rankItems, glanceFields, bookingItems, orderItems, eventItems, blogItems, shownUntil,
|
|
26
|
+
GLANCE_COPY, type GlanceFields,
|
|
27
|
+
} from "./glance.js";
|
|
22
28
|
|
|
23
|
-
export { isSectionUnavailable, isSignedOut };
|
|
29
|
+
export { isSectionUnavailable, isSignedOut, dayLabel };
|
|
24
30
|
|
|
25
31
|
type Rec = Record<string, unknown>;
|
|
26
32
|
|
|
@@ -37,7 +43,11 @@ export interface TodayBooking {
|
|
|
37
43
|
whenLabel: string;
|
|
38
44
|
}
|
|
39
45
|
|
|
40
|
-
|
|
46
|
+
/** The glance ("what matters now", glance.ts) rides on the same state: the existing fields stay
|
|
47
|
+
* for the embedding hosts that bind them (the embedding guide), the glance fields are added. */
|
|
48
|
+
export interface TodayState extends GlanceFields {
|
|
49
|
+
eventsReady: boolean;
|
|
50
|
+
blogReady: boolean;
|
|
41
51
|
status: "loading" | "ready" | "error" | "signedOut";
|
|
42
52
|
siteName: string;
|
|
43
53
|
/** Header line: "Today · <site>", or "Today" when the site has no name yet. */
|
|
@@ -76,6 +86,8 @@ export interface TodayState {
|
|
|
76
86
|
export interface Verticals {
|
|
77
87
|
bookings: boolean;
|
|
78
88
|
store: boolean;
|
|
89
|
+
events: boolean;
|
|
90
|
+
blog: boolean;
|
|
79
91
|
}
|
|
80
92
|
|
|
81
93
|
export const COPY = {
|
|
@@ -89,35 +101,6 @@ const PENDING = ["PENDING", "PENDING_APPROVAL", "WAITING_LIST"];
|
|
|
89
101
|
/** A glance, not a list: a count at the cap reads as "50+". */
|
|
90
102
|
export const LIMIT = 50;
|
|
91
103
|
|
|
92
|
-
const WEEKDAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
|
93
|
-
const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
|
|
94
|
-
|
|
95
|
-
function str(r: unknown, ...paths: string[]): string {
|
|
96
|
-
for (const path of paths) {
|
|
97
|
-
let v: unknown = r;
|
|
98
|
-
for (const k of path.split(".")) v = v && typeof v === "object" ? (v as Rec)[k] : undefined;
|
|
99
|
-
if (typeof v === "string" && v) return v;
|
|
100
|
-
if (typeof v === "number") return String(v);
|
|
101
|
-
}
|
|
102
|
-
return "";
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
function hhmm(d: Date): string {
|
|
106
|
-
return `${String(d.getHours()).padStart(2, "0")}:${String(d.getMinutes()).padStart(2, "0")}`;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function sameLocalDay(a: Date, b: Date): boolean {
|
|
110
|
-
return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth() && a.getDate() === b.getDate();
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/** The day a booking falls on, as an owner would say it. */
|
|
114
|
-
export function dayLabel(start: Date, now: Date): string {
|
|
115
|
-
if (sameLocalDay(start, now)) return "Today";
|
|
116
|
-
const tomorrow = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1);
|
|
117
|
-
if (sameLocalDay(start, tomorrow)) return "Tomorrow";
|
|
118
|
-
return `${WEEKDAYS[start.getDay()]} ${start.getDate()} ${MONTHS[start.getMonth()]}`;
|
|
119
|
-
}
|
|
120
|
-
|
|
121
104
|
function startOf(b: Rec): string {
|
|
122
105
|
return str(b, "startDate", "bookedEntity.slot.startDate");
|
|
123
106
|
}
|
|
@@ -149,6 +132,11 @@ export interface Sources {
|
|
|
149
132
|
requests: Rec[] | null;
|
|
150
133
|
/** Orders needing attention, or null when Store could not be read. */
|
|
151
134
|
orders: Rec[] | null;
|
|
135
|
+
/** Upcoming events (next 7 days), or null when Events could not be read. Optional so a caller
|
|
136
|
+
* that predates the glance reads as "not provisioned". */
|
|
137
|
+
events?: Rec[] | null;
|
|
138
|
+
/** Blog draft posts (scheduled + unpublished), or null when Blog could not be read. */
|
|
139
|
+
drafts?: Rec[] | null;
|
|
152
140
|
}
|
|
153
141
|
|
|
154
142
|
function upcoming(rows: Rec[] | null, statuses: string[], now: Date): Rec[] {
|
|
@@ -177,12 +165,36 @@ export function shape(sources: Sources, now: Date, siteName: string): TodayState
|
|
|
177
165
|
...(bookingsReady ? [`${requestsCapped ? `${LIMIT}+` : requestCount} req`] : []),
|
|
178
166
|
...(ordersReady ? [counted(orderCount, ordersCapped, "order", "orders")] : []),
|
|
179
167
|
];
|
|
180
|
-
const
|
|
168
|
+
const eventsReady = sources.events != null;
|
|
169
|
+
const blogReady = sources.drafts != null;
|
|
170
|
+
const nothing = !bookingsReady && !ordersReady && !eventsReady && !blogReady;
|
|
181
171
|
const nextNote = bookingsReady && !next ? COPY.noneUpcoming : "";
|
|
182
172
|
const midnight = new Date(now.getFullYear(), now.getMonth(), now.getDate() + 1).getTime();
|
|
183
173
|
const nextStart = next ? Date.parse(startOf(next)) : Infinity;
|
|
174
|
+
const nextShown = next ? booking(next, now) : undefined;
|
|
175
|
+
const ranked = rankItems([
|
|
176
|
+
...(bookingsReady ? bookingItems(
|
|
177
|
+
nextShown && { start: new Date(startOf(next!)), service: nextShown.service, firstName: str(next, "contactDetails.firstName") },
|
|
178
|
+
requestCount, requestsCapped, now, LIMIT) : []),
|
|
179
|
+
...(ordersReady ? orderItems(orderCount, ordersCapped, LIMIT) : []),
|
|
180
|
+
...(eventsReady ? eventItems(sources.events ?? [], now) : []),
|
|
181
|
+
...(blogReady ? blogItems(sources.drafts ?? [], now, LIMIT) : []),
|
|
182
|
+
]);
|
|
183
|
+
// A shown item stops being true when it starts (a booking or event is no longer "next"), as
|
|
184
|
+
// the next booking already did: the frame's lifetime ends at the first of them.
|
|
185
|
+
const headAt = shownUntil(ranked);
|
|
186
|
+
// Nothing could be read at all: the glance shows the degrade line, never "All clear".
|
|
187
|
+
const glance = nothing
|
|
188
|
+
? { ...glanceFields([], GLANCE_COPY), glanceHeadline: COPY.nothing, glanceDetail: "", glanceAllClear: false,
|
|
189
|
+
glanceSymbol: "", lockInline: COPY.nothing, lockRectTitle: COPY.nothing, lockRectDetail: "",
|
|
190
|
+
// A published frame: the Lock Screen circle must not be an empty bubble.
|
|
191
|
+
lockCircValue: "—", lockCircLabel: "Owner" }
|
|
192
|
+
: glanceFields(ranked, GLANCE_COPY);
|
|
184
193
|
return {
|
|
185
|
-
|
|
194
|
+
...glance,
|
|
195
|
+
eventsReady,
|
|
196
|
+
blogReady,
|
|
197
|
+
validUntil: Math.floor(Math.min(midnight, nextStart, headAt) / 1000),
|
|
186
198
|
status: "ready",
|
|
187
199
|
siteName,
|
|
188
200
|
header: siteName ? `Today · ${siteName}` : "Today",
|
|
@@ -215,7 +227,13 @@ export function degraded(status: "error" | "signedOut" | "loading", siteName: st
|
|
|
215
227
|
const message = status === "signedOut" ? COPY.signedOut : status === "error" ? COPY.error : "";
|
|
216
228
|
// validUntil pinned too: shape() derives it from LOCAL midnight, so even at a fixed instant it
|
|
217
229
|
// would vary with the build machine's timezone and change the baked services hash.
|
|
218
|
-
|
|
230
|
+
// The glance shows the degrade line too, never "All clear": a frame that could not read the
|
|
231
|
+
// business must not tell the owner nothing is waiting.
|
|
232
|
+
return {
|
|
233
|
+
...base, status, message, hideMessage: !message, validUntil: 0,
|
|
234
|
+
glanceHeadline: message, glanceDetail: "", glanceAllClear: false, glanceSymbol: "",
|
|
235
|
+
lockInline: message, lockRectTitle: message, lockRectDetail: "", lockCircValue: "", lockCircLabel: "",
|
|
236
|
+
};
|
|
219
237
|
}
|
|
220
238
|
|
|
221
239
|
/** The business this frame is about. An embedding host that publishes this widget once per
|
|
@@ -247,9 +265,9 @@ function rows(r: Read, key: string): Rec[] | null {
|
|
|
247
265
|
* host that passes none (an older descriptor) reads both, as before. */
|
|
248
266
|
export function buildVerticals(): Verticals {
|
|
249
267
|
const raw = (globalThis as { himalaya?: { input?: Record<string, unknown> } }).himalaya?.input?.verticals;
|
|
250
|
-
if (typeof raw !== "string") return { bookings: true, store: true };
|
|
268
|
+
if (typeof raw !== "string") return { bookings: true, store: true, events: true, blog: true };
|
|
251
269
|
const set = new Set(raw.split(",").map((v) => v.trim()));
|
|
252
|
-
return { bookings: set.has("bookings"), store: set.has("store") };
|
|
270
|
+
return { bookings: set.has("bookings"), store: set.has("store"), events: set.has("events"), blog: set.has("blog") };
|
|
253
271
|
}
|
|
254
272
|
|
|
255
273
|
/** A section this build does not provision: never read, and indistinguishable from "not
|
|
@@ -273,6 +291,38 @@ async function read(): Promise<TodayState> {
|
|
|
273
291
|
sort: [{ fieldName: "createdDate", order: "DESC" }, { fieldName: "id", order: "ASC" }],
|
|
274
292
|
cursorPaging: { limit: LIMIT },
|
|
275
293
|
} })) : Promise.resolve(NOT_PROVISIONED),
|
|
294
|
+
// The coming week's events (the glance looks 7 days ahead), soonest first.
|
|
295
|
+
verticals.events ? attempt(() => queryEvents({ query: {
|
|
296
|
+
filter: {
|
|
297
|
+
"dateAndTimeSettings.startDate": { $gte: nowIso, $lte: new Date(Date.now() + 7 * 24 * 60 * 60 * 1000).toISOString() },
|
|
298
|
+
// Events v3 vocabulary: a published event not yet started is UPCOMING. SCHEDULED is a
|
|
299
|
+
// v1 value, and a v1 filter on this route matches nothing.
|
|
300
|
+
status: { $in: ["UPCOMING"] },
|
|
301
|
+
},
|
|
302
|
+
sort: [{ fieldName: "dateAndTimeSettings.startDate", order: "ASC" }, { fieldName: "id", order: "ASC" }],
|
|
303
|
+
paging: { limit: LIMIT, offset: 0 },
|
|
304
|
+
} })) : Promise.resolve(NOT_PROVISIONED),
|
|
305
|
+
// Drafts: the scheduled posts and the ones still being written. Filtered on the server: the
|
|
306
|
+
// resource also returns every PUBLISHED post's draft, and a blog with 50+ published posts
|
|
307
|
+
// would otherwise fill the page with them and hide the post going out today.
|
|
308
|
+
// Scheduled posts are read on their own page, so a blog with 50+ drafts cannot push the post
|
|
309
|
+
// going out today off the one page the drafts fill.
|
|
310
|
+
verticals.blog ? attempt(async () => {
|
|
311
|
+
const page = (status: string) => queryDraftPosts({ query: {
|
|
312
|
+
filter: { status: { $in: [status] } },
|
|
313
|
+
paging: { limit: LIMIT, offset: 0 },
|
|
314
|
+
} });
|
|
315
|
+
const [scheduled, unpublished] = await Promise.all([page("SCHEDULED"), page("UNPUBLISHED")]);
|
|
316
|
+
// By id, once: a server that ignores the status filter answers both pages with the same rows.
|
|
317
|
+
const byId = new Map<string, Rec>();
|
|
318
|
+
const rowsOf = (r: { draftPosts?: unknown }) => (Array.isArray(r.draftPosts) ? r.draftPosts : []) as Rec[];
|
|
319
|
+
for (const d of [...rowsOf(scheduled), ...rowsOf(unpublished)]) {
|
|
320
|
+
const id = typeof d?.id === "string" ? d.id : "";
|
|
321
|
+
if (id && !byId.has(id)) byId.set(id, d);
|
|
322
|
+
}
|
|
323
|
+
return { draftPosts: [...byId.values()] };
|
|
324
|
+
})
|
|
325
|
+
: Promise.resolve(NOT_PROVISIONED),
|
|
276
326
|
]);
|
|
277
327
|
const failures = reads.flatMap((r) => (r.ok ? [] : [r.error]));
|
|
278
328
|
if (failures.some(isSignedOut)) return degraded("signedOut", "");
|
|
@@ -281,11 +331,13 @@ async function read(): Promise<TodayState> {
|
|
|
281
331
|
// not publish: the last good frame stays, rather than a frame that silently drops a
|
|
282
332
|
// section the owner does have and reads as "nothing waiting".
|
|
283
333
|
if (failures.some((e) => !isSectionUnavailable(e))) return degraded("error", siteName());
|
|
284
|
-
const [bookings, requests, orders] = reads;
|
|
334
|
+
const [bookings, requests, orders, events, drafts] = reads;
|
|
285
335
|
return shape({
|
|
286
336
|
bookings: rows(bookings, "bookings"),
|
|
287
337
|
requests: rows(requests, "bookings"),
|
|
288
338
|
orders: rows(orders, "orders"),
|
|
339
|
+
events: rows(events, "events"),
|
|
340
|
+
drafts: rows(drafts, "draftPosts"),
|
|
289
341
|
}, new Date(), siteName());
|
|
290
342
|
}
|
|
291
343
|
|
|
@@ -20,6 +20,8 @@ export interface ProductRow {
|
|
|
20
20
|
image: string; initial: string; hasImage: boolean; noImage: boolean;
|
|
21
21
|
/** The merchant's ribbon on the product ("Best Seller"), on the tile's image; a product without one keeps a plain tile. */
|
|
22
22
|
ribbon: string; noRibbon: boolean;
|
|
23
|
+
/** The tile's accessible name: the product name, then its ribbon when it has one, so a screen reader hears the badge too. */
|
|
24
|
+
label: string;
|
|
23
25
|
/** The product screen a tile opens; the tile binds `id` as its nav param. */
|
|
24
26
|
detailScreenId: string;
|
|
25
27
|
}
|
|
@@ -44,7 +46,7 @@ function rowOf(product: StoreProduct): ProductRow {
|
|
|
44
46
|
return {
|
|
45
47
|
id: product.id ?? "", name, price: productPrice(product),
|
|
46
48
|
image, initial: (name[0] ?? "#").toUpperCase(), hasImage: !!image, noImage: !image,
|
|
47
|
-
ribbon, noRibbon: !ribbon,
|
|
49
|
+
ribbon, noRibbon: !ribbon, label: ribbon ? `${name}, ${ribbon}` : name,
|
|
48
50
|
detailScreenId: "himi_product",
|
|
49
51
|
};
|
|
50
52
|
}
|