@wix/himalaya-cli 0.983.0 → 0.985.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/stdlib/wix-sdk/notification-preferences/src/index.d.ts +105 -33
  2. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/wix-notification-preferences.mjs +66 -5
  3. package/dist/cli.mjs +19 -15
  4. package/dist/preview-assets.generated.bin +0 -0
  5. package/fixtures/wix-canned.json +36 -29
  6. package/guides/sdk-reference.json +86 -49
  7. package/package.json +2 -2
  8. package/templates/beauty-salon/dev/index.ts +27 -2
  9. package/templates/beauty-salon/tier5-src/himi-branded-lite-order/index.ts +14 -6
  10. package/templates/beauty-salon/tier5-src/himi-store-account/index.ts +59 -20
  11. package/templates/branded-lite/dev/index.ts +27 -2
  12. package/templates/branded-lite/tier5-src/himi-branded-lite-notifsettings/index.ts +42 -14
  13. package/templates/branded-lite/tier5-src/himi-branded-lite-order/index.ts +14 -6
  14. package/templates/branded-lite/tier5-src/himi-store-account/index.ts +59 -20
  15. package/templates/community-club/tier5-src/himi-store-account/index.ts +59 -20
  16. package/templates/events-meetups/tier5-src/himi-store-account/index.ts +59 -20
  17. package/templates/gym-fitness/dev/index.ts +27 -2
  18. package/templates/gym-fitness/tier5-src/himi-branded-lite-order/index.ts +14 -6
  19. package/templates/gym-fitness/tier5-src/himi-store-account/index.ts +59 -20
  20. package/templates/nonprofit-cause/tier5-src/himi-store-account/index.ts +59 -20
  21. package/templates/podcast-creator/tier5-src/himi-store-account/index.ts +59 -20
  22. package/templates/portfolio-creative/dev/index.ts +25 -1
  23. package/templates/portfolio-creative/tier5-src/himi-branded-lite-order/index.ts +14 -6
  24. package/templates/portfolio-creative/tier5-src/himi-store-account/index.ts +59 -20
  25. package/templates/restaurant/tier5-src/himi-store-account/index.ts +59 -20
  26. package/templates/retail-store/dev/index.ts +25 -1
  27. package/templates/retail-store/tier5-src/himi-branded-lite-order/index.ts +14 -6
  28. package/templates/retail-store/tier5-src/himi-store-account/index.ts +59 -20
  29. package/templates/yoga-studio/dev/index.ts +2 -1
  30. package/templates/yoga-studio/tier5-src/himi-store-account/index.ts +59 -20
@@ -19042,109 +19042,146 @@
19042
19042
  "source": "stdlib/wix-sdk/notification-preferences/src/index.ts",
19043
19043
  "description": "Notification preferences",
19044
19044
  "api": [
19045
+ {
19046
+ "name": "NOTIFICATION_PREFERENCES_BASE",
19047
+ "kind": "const",
19048
+ "jsdoc": "/**\n * The service's own mount, from the published swagger `host`\n * (\"www.wixapis.com/notification-preferences\") — the PATH half of it.\n *\n * Relative, not absolute: the `wixApi` bridge supplies the gateway host. Baking one in\n * works on a phone and is rejected in a browser (`400 absolute_urls_not_allowed`), so a\n * client that spells the host works in one place and not the other. What was wrong\n * before was the mount (`/notifications`), not the host.\n */",
19049
+ "decl": "export const NOTIFICATION_PREFERENCES_BASE = \"/notification-preferences/v1\";"
19050
+ },
19051
+ {
19052
+ "name": "PreferenceState",
19053
+ "kind": "type",
19054
+ "jsdoc": "/** `enum State` on `StateData`. A scalar, not an object. */",
19055
+ "decl": "export type PreferenceState = \"MUTED\" | \"UNMUTED\" | string;"
19056
+ },
19045
19057
  {
19046
19058
  "name": "MuteStatus",
19047
19059
  "kind": "type",
19048
- "jsdoc": "/** \"MUTED\" silences the topic on this channel; \"UNMUTED\" delivers it. */",
19049
- "decl": "export type MuteStatus = \"MUTED\" | \"UNMUTED\";",
19050
- "verified": false
19060
+ "jsdoc": "/** Kept as the name the callers already use for the value they write. */",
19061
+ "decl": "export type MuteStatus = \"MUTED\" | \"UNMUTED\";"
19051
19062
  },
19052
19063
  {
19053
19064
  "name": "Channel",
19054
19065
  "kind": "type",
19055
- "jsdoc": "/** Delivery channel. The mobile push channel value is unconfirmed; \"MOBILE\" is\n * the working default the bundle passes. */",
19056
- "decl": "export type Channel = \"MOBILE\" | string;",
19057
- "verified": false
19066
+ "jsdoc": "/** `enum Channel { UNKNOWN_CHANNEL, ALL, MOBILE, EMAIL, SMS, VOICE, BROWSER, WEB_FEED }`.\n * `ALL` is real and covers mobile too — filtering it out hides preferences that do\n * apply on this surface. */",
19067
+ "decl": "export type Channel = \"ALL\" | \"MOBILE\" | \"EMAIL\" | \"SMS\" | \"VOICE\" | \"BROWSER\" | \"WEB_FEED\" | string;"
19058
19068
  },
19059
19069
  {
19060
- "name": "PreferenceState",
19061
- "kind": "interface",
19070
+ "name": "RecipientType",
19071
+ "kind": "type",
19062
19072
  "jsdoc": "",
19063
- "decl": "export interface PreferenceState {\n /** \"MUTED\" | \"UNMUTED\" — whether the topic is delivered on this channel. */\n muteStatus?: MuteStatus;\n}",
19064
- "verified": false
19073
+ "decl": "export type RecipientType = \"WIX_USER\" | \"CONTACT\";"
19065
19074
  },
19066
19075
  {
19067
- "name": "PreferenceStateData",
19076
+ "name": "StateData",
19068
19077
  "kind": "interface",
19069
- "jsdoc": "",
19070
- "decl": "export interface PreferenceStateData {\n state?: PreferenceState;\n}",
19071
- "verified": false
19078
+ "jsdoc": "/** `message StateData`. `granted` and `overridden` are read-only server verdicts. */",
19079
+ "decl": "export interface StateData {\n /** The state the recipient asked for. */\n state?: PreferenceState;\n /** Whether the notification is granted to be SENT. An UNMUTED topic under a muted\n * channel is `granted: false` — i.e. the row must not render ON. */\n granted?: boolean;\n /** Whether a broader rule overrides this row, so it cannot be changed here. */\n overridden?: boolean;\n displayName?: string;\n}"
19072
19080
  },
19073
19081
  {
19074
19082
  "name": "PreferenceInfo",
19075
19083
  "kind": "interface",
19076
- "jsdoc": "/** One topic×channel preference for the implicit recipient. */",
19077
- "decl": "export interface PreferenceInfo {\n /** The notification topic id (matches NotificationTopic.id). */\n topicId: string;\n /** Delivery channel this preference applies to (e.g. \"MOBILE\"). */\n channel?: Channel;\n stateData?: PreferenceStateData;\n}",
19078
- "verified": false
19084
+ "jsdoc": "/** `message PreferenceInfo` — one topic×channel preference. */",
19085
+ "decl": "export interface PreferenceInfo {\n topicId: string;\n channel?: Channel;\n stateData?: StateData;\n topicType?: string;\n}"
19079
19086
  },
19080
19087
  {
19081
19088
  "name": "NotificationPreferences",
19082
19089
  "kind": "interface",
19083
- "jsdoc": "",
19084
- "decl": "export interface NotificationPreferences {\n preferencesInfo?: PreferenceInfo[];\n}",
19085
- "verified": false
19090
+ "jsdoc": "/** `message NotificationPreferences`. */",
19091
+ "decl": "export interface NotificationPreferences {\n preferencesInfo?: PreferenceInfo[];\n}"
19086
19092
  },
19087
19093
  {
19088
19094
  "name": "GetMyNotificationPreferencesResponse",
19089
19095
  "kind": "interface",
19096
+ "jsdoc": "/** `GetPreferencesBy{Implicit,}RecipientResponse` uses `notification_preferences`;\n * `UpsertPreferencesBy{Implicit,}RecipientResponse` uses `preferences`. Both are\n * declared so a caller cannot read the wrong one by accident. */",
19097
+ "decl": "export interface GetMyNotificationPreferencesResponse {\n notificationPreferences?: NotificationPreferences;\n}"
19098
+ },
19099
+ {
19100
+ "name": "UpsertMyNotificationPreferencesResponse",
19101
+ "kind": "interface",
19090
19102
  "jsdoc": "",
19091
- "decl": "export interface GetMyNotificationPreferencesResponse {\n preferences?: NotificationPreferences;\n}",
19092
- "verified": false
19103
+ "decl": "export interface UpsertMyNotificationPreferencesResponse {\n preferences?: NotificationPreferences;\n}"
19093
19104
  },
19094
19105
  {
19095
- "name": "NotificationTopic",
19106
+ "name": "NotificationTopicDefinition",
19096
19107
  "kind": "interface",
19097
- "jsdoc": "/** A notification topic — its id is the PreferenceInfo.topicId; displayName is\n * the row label shown in the UI. */",
19098
- "decl": "export interface NotificationTopic {\n id: string;\n displayName?: string;\n}",
19099
- "verified": false
19108
+ "jsdoc": "/** `message NotificationTopicDefinition`. */",
19109
+ "decl": "export interface NotificationTopicDefinition {\n topicId: string;\n displayName?: string;\n state?: PreferenceState;\n topicType?: string;\n}"
19100
19110
  },
19101
19111
  {
19102
19112
  "name": "GetNotificationTopicsResponse",
19103
19113
  "kind": "interface",
19104
- "jsdoc": "",
19105
- "decl": "export interface GetNotificationTopicsResponse {\n topics?: NotificationTopic[];\n}",
19106
- "verified": false
19114
+ "jsdoc": "/** `GetNotificationTopicsDefinitionsResponse.preference_definitions`. */",
19115
+ "decl": "export interface GetNotificationTopicsResponse {\n preferenceDefinitions?: NotificationTopicDefinition[];\n}"
19107
19116
  },
19108
19117
  {
19109
- "name": "UpsertMyNotificationPreferencesRequest",
19110
- "kind": "interface",
19111
- "jsdoc": "",
19112
- "decl": "export interface UpsertMyNotificationPreferencesRequest {\n preferencesInfo: PreferenceInfo[];\n}",
19113
- "verified": false
19118
+ "name": "readTopics",
19119
+ "kind": "function",
19120
+ "jsdoc": "/** The topic list, or empty when the response carried none. */",
19121
+ "decl": "export function readTopics(res: GetNotificationTopicsResponse | undefined): NotificationTopicDefinition[];"
19114
19122
  },
19115
19123
  {
19116
- "name": "UpsertMyNotificationPreferencesResponse",
19117
- "kind": "interface",
19118
- "jsdoc": "",
19119
- "decl": "export interface UpsertMyNotificationPreferencesResponse {\n preferences?: NotificationPreferences;\n}",
19120
- "verified": false
19124
+ "name": "readPreferences",
19125
+ "kind": "function",
19126
+ "jsdoc": "/** The preference rows out of EITHER response shape (see the asymmetry note above). */",
19127
+ "decl": "export function readPreferences(\n res: GetMyNotificationPreferencesResponse | UpsertMyNotificationPreferencesResponse | undefined,\n): PreferenceInfo[];"
19121
19128
  },
19122
19129
  {
19123
19130
  "name": "muteStatusFor",
19124
19131
  "kind": "function",
19125
- "jsdoc": "/** Map a UI \"on\" boolean to a MuteStatus: on ⇒ delivered (\"UNMUTED\"). */",
19126
- "decl": "export function muteStatusFor(on: boolean): MuteStatus;",
19127
- "verified": false
19132
+ "jsdoc": "/** Map a UI \"on\" boolean to the state to WRITE: on ⇒ delivered (\"UNMUTED\"). */",
19133
+ "decl": "export function muteStatusFor(on: boolean): MuteStatus;"
19128
19134
  },
19129
19135
  {
19130
- "name": "getMyNotificationPreferences",
19136
+ "name": "isDeliveredNow",
19131
19137
  "kind": "function",
19132
- "jsdoc": "/** Get the signed-in member's notification preferences —\n * GET /notifications/v1/preferences-by-implicit-recipient. */",
19133
- "decl": "export function getMyNotificationPreferences(): Promise<GetMyNotificationPreferencesResponse>;",
19134
- "verified": false
19138
+ "jsdoc": "/**\n * Whether this row is actually being delivered right now.\n *\n * `granted` is the server's verdict and beats `state`: a topic the recipient unmuted\n * under a channel they muted is `state: \"UNMUTED\", granted: false`. Rendering `state`\n * alone shows ON for a notification that will never arrive.\n */",
19139
+ "decl": "export function isDeliveredNow(stateData: StateData | undefined): boolean;"
19140
+ },
19141
+ {
19142
+ "name": "isLocked",
19143
+ "kind": "function",
19144
+ "jsdoc": "/** Whether a broader rule overrides this row, so the UI must not offer to change it. */",
19145
+ "decl": "export function isLocked(stateData: StateData | undefined): boolean;"
19146
+ },
19147
+ {
19148
+ "name": "preferenceFor",
19149
+ "kind": "function",
19150
+ "jsdoc": "/**\n * The one preference row that governs `topicId` on `channel`, or undefined when the\n * recipient has no row for it (⇒ the topic's default, which is delivery).\n *\n * A topic can carry SEVERAL rows — one per channel, plus a channel-wide `ALL` — and\n * the response order is not specified. Picking with a bare `find` therefore rendered\n * whichever row the service happened to list first, so a mobile switch could show an\n * EMAIL preference, and a MOBILE + ALL pair flipped meaning between two identical\n * reads. Resolved by SPECIFICITY instead: the exact channel wins, then `ALL`, then a\n * row that names no channel at all.\n */",
19151
+ "decl": "export function preferenceFor(\n topicId: string,\n prefs: readonly PreferenceInfo[],\n channel: Channel = \"MOBILE\",\n): PreferenceInfo | undefined;"
19152
+ },
19153
+ {
19154
+ "name": "deliveredByTopic",
19155
+ "kind": "function",
19156
+ "jsdoc": "/**\n * Per-topic \"is this actually being delivered on `channel`\" verdicts.\n *\n * A topic with no row is absent from the map, not false: absent means \"the topic's\n * own default\", which the caller renders as ON.\n */",
19157
+ "decl": "export function deliveredByTopic(\n prefs: readonly PreferenceInfo[],\n channel: Channel = \"MOBILE\",\n): Record<string, boolean>;"
19135
19158
  },
19136
19159
  {
19137
19160
  "name": "getNotificationTopics",
19138
19161
  "kind": "function",
19139
- "jsdoc": "/** List the available notification topics (id + displayName for labels) —\n * GET /notifications/v1/preferences/topics. */",
19162
+ "jsdoc": "/** List the site's notification topics — `GET /v1/preferences/topics`\n * (GetNotificationTopicsDefinitions). Publicly mounted.\n * verify-live: source contract checked; live caller authorization remains untested. */",
19140
19163
  "decl": "export function getNotificationTopics(): Promise<GetNotificationTopicsResponse>;",
19141
19164
  "verified": false
19142
19165
  },
19166
+ {
19167
+ "name": "getPreferencesForRecipient",
19168
+ "kind": "function",
19169
+ "jsdoc": "/**\n * The PUBLICLY mounted preferences read — `GET /v1/preferences`\n * (GetPreferencesByRecipient). It needs the recipient explicitly: `CONTACT` + a\n * contactId for a member, `WIX_USER` + a wixUserId for an owner.\n *\n * Prefer this from an app going through the public gateway; the implicit-recipient\n * variant below is not among the five paths the swagger exposes.\n * verify-live: source contract checked; live caller authorization remains untested.\n */",
19170
+ "decl": "export function getPreferencesForRecipient(recipient: {\n recipientType: RecipientType;\n contactId?: string;\n wixUserId?: string;\n language?: string;\n}): Promise<GetMyNotificationPreferencesResponse>;",
19171
+ "verified": false
19172
+ },
19173
+ {
19174
+ "name": "getMyNotificationPreferences",
19175
+ "kind": "function",
19176
+ "jsdoc": "/** The signed-in recipient's preferences — `GET /v1/preferences-by-implicit-recipient`\n * (GetPreferencesByImplicitRecipient). NOT in the published public swagger; a 404 from\n * the public gateway is the expected outcome there, not a bug in this call.\n * verify-live: the implicit-recipient mount has not been verified for member callers. */",
19177
+ "decl": "export function getMyNotificationPreferences(): Promise<GetMyNotificationPreferencesResponse>;",
19178
+ "verified": false
19179
+ },
19143
19180
  {
19144
19181
  "name": "upsertMyNotificationPreferences",
19145
19182
  "kind": "function",
19146
- "jsdoc": "/** Upsert one or more of the signed-in member's preferences —\n * POST /notifications/v1/preferences-by-implicit-recipient, body\n * { preferencesInfo }. Pass only the rows that changed. */",
19147
- "decl": "export function upsertMyNotificationPreferences(\n preferencesInfo: PreferenceInfo[]\n): Promise<UpsertMyNotificationPreferencesResponse>;",
19183
+ "jsdoc": "/** Upsert some of the signed-in recipient's preferences —\n * `POST /v1/preferences-by-implicit-recipient` (UpsertPreferencesByImplicitRecipient),\n * body `{ preferencesInfo }`. Pass only the rows that changed.\n * verify-live: the implicit-recipient mount has not been verified for member callers. */",
19184
+ "decl": "export function upsertMyNotificationPreferences(\n preferencesInfo: PreferenceInfo[],\n): Promise<UpsertMyNotificationPreferencesResponse>;",
19148
19185
  "verified": false
19149
19186
  }
19150
19187
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/himalaya-cli",
3
- "version": "0.983.0",
3
+ "version": "0.985.0",
4
4
  "type": "module",
5
5
  "description": "himi — the Himalaya authoring CLI. Build a Tier-5 content package on your own machine, push it to the production serve as a draft, preview it on web + Himi Player, and read worker logs back — the remote dev loop. Wraps @himalaya/serve-cli for transport.",
6
6
  "keywords": [
@@ -65,5 +65,5 @@
65
65
  "artifactId": "himalaya-cli"
66
66
  }
67
67
  },
68
- "falconPackageHash": "7ef8920fa57356d1c20238a8c413cad1047a8b15da818664fd95a13b"
68
+ "falconPackageHash": "277e41b04416b46fd7ccd42d09987c9e0478a67820885fef3debe4eb"
69
69
  }
@@ -9201,7 +9201,8 @@ const SCREENS = runtimeSetting({
9201
9201
  "action": {
9202
9202
  "actionId": "himi.open",
9203
9203
  "params": {
9204
- "screenId": "himi_account"
9204
+ "screenId": "himi_account",
9205
+ "returnScreenId": "himi_orders"
9205
9206
  }
9206
9207
  }
9207
9208
  }
@@ -14352,7 +14353,8 @@ const SCREENS = runtimeSetting({
14352
14353
  "action": {
14353
14354
  "actionId": "himi.open",
14354
14355
  "params": {
14355
- "screenId": "himi_account"
14356
+ "screenId": "himi_account",
14357
+ "returnScreenId": "himi_bookings"
14356
14358
  }
14357
14359
  }
14358
14360
  }
@@ -23909,6 +23911,29 @@ const TEMPLATED: { pattern: string; display: string; liveSeed?: LiveSeed; static
23909
23911
  },
23910
23912
  "hiddenPath": "$service:himiBrandedOrder.noEmpty"
23911
23913
  }
23914
+ },
23915
+ {
23916
+ "id": "himi_order.signin",
23917
+ "body": {
23918
+ "package": "himalaya",
23919
+ "type": "Button",
23920
+ "props": {
23921
+ "title": "Sign in",
23922
+ "style": "primary",
23923
+ "fullWidth": true,
23924
+ "action": {
23925
+ "actionId": "himi.open",
23926
+ "params": {
23927
+ "screenId": "himi_account",
23928
+ "returnScreenId": "himi_order",
23929
+ "returnId": "$service:himiBrandedOrder.id"
23930
+ }
23931
+ }
23932
+ }
23933
+ },
23934
+ "modifiers": {
23935
+ "hiddenPath": "$service:himiBrandedOrder.noSignIn"
23936
+ }
23912
23937
  }
23913
23938
  ]
23914
23939
  }
@@ -63,6 +63,10 @@ interface State extends LiveSessionFields {
63
63
  cannotReorder: boolean;
64
64
  reorderMessage: string;
65
65
  emptyText: string;
66
+ /** No member session is what stands between the visitor and this order — drives the
67
+ * sign-in CTA, which returns here with `id` once the member has signed in. */
68
+ needsSignIn: boolean;
69
+ noSignIn: boolean;
66
70
  isLoading: boolean;
67
71
  notLoading: boolean;
68
72
  isErrored: boolean;
@@ -180,6 +184,7 @@ function derive(state: State): State {
180
184
  isErrored: state.status === "error",
181
185
  notErrored: state.status !== "error",
182
186
  noEmpty: state.status !== "ready" || hasContent,
187
+ noSignIn: !state.needsSignIn,
183
188
  hideContent: !hasContent,
184
189
  hasShipping: !!state.shipping,
185
190
  noShipping: !state.shipping,
@@ -249,7 +254,7 @@ function orderState(order: WixOrder): Partial<State> {
249
254
  let loadVersion = 0;
250
255
  let loadedMember: OrderMember | undefined;
251
256
  function clearOrder(state: State): State {
252
- return derive({ ...state, title: "", placedAt: "", fulfillmentStatus: "", paymentStatus: "", subtotal: "", shipping: "", tax: "", discount: "", total: "", rows: [], reorderRefs: [], reorderMessage: "", emptyText: "" });
257
+ return derive({ ...state, title: "", placedAt: "", fulfillmentStatus: "", paymentStatus: "", subtotal: "", shipping: "", tax: "", discount: "", total: "", rows: [], reorderRefs: [], reorderMessage: "", emptyText: "", needsSignIn: false });
253
258
  }
254
259
  async function load(state: State, arg?: unknown): Promise<State | undefined> {
255
260
  const version = ++loadVersion;
@@ -259,9 +264,10 @@ async function load(state: State, arg?: unknown): Promise<State | undefined> {
259
264
  const finish = (next: State) => version === loadVersion ? derive(next) : undefined;
260
265
  const id = inputId();
261
266
  const member = await orderMember();
262
- if (!id || !member.email) {
263
- return finish({ ...state, status: "ready", emptyText: member.email ? copyParam("order.notFoundEmptyText", "Order not found.") : copyParam("order.signInEmptyText", "Sign in to view this order.") });
264
- }
267
+ const signInText = copyParam("order.signInEmptyText", "Sign in to view this order.");
268
+ if (!id) return finish({ ...state, status: "ready", emptyText: member.email ? copyParam("order.notFoundEmptyText", "Order not found.") : signInText });
269
+ const signInRequired = (status: State["status"]) => finish({ ...state, id, status, needsSignIn: true, emptyText: signInText });
270
+ if (!member.email) return signInRequired("ready");
265
271
  try {
266
272
  const order = await findOwnedOrder(id, member.email);
267
273
  await assertOrderMember(member);
@@ -272,11 +278,11 @@ async function load(state: State, arg?: unknown): Promise<State | undefined> {
272
278
  } catch (error) {
273
279
  if (version !== loadVersion) return undefined;
274
280
  try { await assertOrderMember(member); } catch {
275
- return finish({ ...state, status: "error", emptyText: copyParam("order.signInEmptyText", "Sign in to view this order.") });
281
+ return signInRequired("error");
276
282
  }
277
283
  const cached = orderAccessDenied(error) ? null : await readCachedOrder(id, member);
278
284
  try { await assertOrderMember(member); } catch {
279
- return finish({ ...state, status: "error", emptyText: copyParam("order.signInEmptyText", "Sign in to view this order.") });
285
+ return signInRequired("error");
280
286
  }
281
287
  if (cached) {
282
288
  return finish({ ...state, status: "ready", title: String(cached.title ?? "") || copyTemplate("order.orderTitle", "Order #{number}", { number: id }),
@@ -326,6 +332,8 @@ const svc = defineService<State, {
326
332
  cannotReorder: true,
327
333
  reorderMessage: "",
328
334
  emptyText: "",
335
+ needsSignIn: false,
336
+ noSignIn: true,
329
337
  isLoading: true,
330
338
  notLoading: false,
331
339
  isErrored: false,
@@ -8,7 +8,7 @@
8
8
  // `wix-site-id` header and nothing else, so every read stayed on the baked site while the
9
9
  // UI claimed otherwise. Managing several businesses is Owner Lite's job (account auth, a
10
10
  // real Sites List, and per-call site scope via `site.forSite`).
11
- import { defineService } from "@himalaya/state";
11
+ import { defineService, navigate, type NavDirective } from "@himalaya/state";
12
12
  import { dispatch } from "@himalaya/dispatch";
13
13
  import { searchOrders, type WixOrder } from "@himalaya/wix-ecom";
14
14
  import { guestProfile, loadMemberProfile, strOf, fmtDate, titleCase, type AccountActivityRow } from "../_shared/himi-account";
@@ -21,6 +21,9 @@ interface AuthRouteInput {
21
21
  returnId?: string;
22
22
  }
23
23
 
24
+ // The screen's boot input survives refresh; consuming it must survive too.
25
+ let routeInputConsumed = false;
26
+
24
27
  /** Mid-flow open params land on `himalaya.input` (paramKeys on himi_account). */
25
28
  function routeInput(): AuthRouteInput {
26
29
  const input = (globalThis as { himalaya?: { input?: AuthRouteInput } }).himalaya?.input;
@@ -35,7 +38,7 @@ function strField(arg: unknown, key: string): string {
35
38
 
36
39
  /** Mid-flow auth (UX F3): intent + return path from himi.open / himalaya.input. */
37
40
  function authIntentFromArg(arg: unknown, prev: Pick<S, "authIntent" | "authContextName" | "returnScreenId" | "returnId">): Pick<S, "authIntent" | "authContextName" | "returnScreenId" | "returnId"> {
38
- const route = routeInput();
41
+ const route = routeInputConsumed ? {} : routeInput();
39
42
  return {
40
43
  authIntent: strField(arg, "intent") || route.intent || prev.authIntent || "",
41
44
  authContextName: strField(arg, "contextName") || route.contextName || prev.authContextName || "",
@@ -44,6 +47,42 @@ function authIntentFromArg(arg: unknown, prev: Pick<S, "authIntent" | "authConte
44
47
  };
45
48
  }
46
49
 
50
+ /** Where a successful sign-in returns to, or null. Never Account itself — that would
51
+ * only push a second copy of the screen the member is already on. */
52
+ function resumeTarget(s: Pick<S, "returnScreenId" | "returnId">): NavDirective | null {
53
+ if (!s.returnScreenId || s.returnScreenId === "himi_account") return null;
54
+ return s.returnId ? { screenId: s.returnScreenId, args: { id: s.returnId } } : { screenId: s.returnScreenId };
55
+ }
56
+
57
+ /** Resume the member-only screen that sent the visitor here, once. The return path is
58
+ * consumed so a later refresh cannot fire it again; the host opens the target only if
59
+ * it is linkable, the same check an authored `himi.open` gets. */
60
+ function resumeAfterAuth(next: S): S {
61
+ const target = resumeTarget(next);
62
+ if (!next.isMember || !target) return next;
63
+ routeInputConsumed = true;
64
+ return navigate(derive({ ...next, authIntent: "", authContextName: "", returnScreenId: "", returnId: "" }), target);
65
+ }
66
+
67
+ // Actions are not serialized: two quick Sign in taps both run against the pre-tap
68
+ // state, so without this both would submit credentials and both would resume.
69
+ let authInFlight = false;
70
+
71
+ async function authenticate(s: S, submit: () => Promise<unknown>, notMemberMessage: string, failedMessage: string): Promise<S | undefined> {
72
+ if (authInFlight) return undefined;
73
+ authInFlight = true;
74
+ try {
75
+ await submit();
76
+ const next = await probe(optimisticMember(s, s.email));
77
+ if (!next.isMember) return derive({ ...next, message: notMemberMessage });
78
+ return resumeAfterAuth(derive({ ...next, message: "" }));
79
+ } catch {
80
+ return derive({ ...s, message: failedMessage });
81
+ } finally {
82
+ authInFlight = false;
83
+ }
84
+ }
85
+
47
86
  // Next value of a focus token: monotonic, and never empty once requested. A counter
48
87
  // rather than Date.now() — deterministic under test, and immune to two focus
49
88
  // requests landing inside the same millisecond.
@@ -123,7 +162,8 @@ interface S {
123
162
  authContextName: string;
124
163
  returnScreenId: string;
125
164
  returnId: string;
126
- /** Show Continue after a successful mid-flow sign-in. */
165
+ /** Show Continue when an already-signed-in member opens Account with a return path.
166
+ * A sign-in made here resumes on its own (resumeAfterAuth). */
127
167
  hasReturnPath: boolean;
128
168
  noReturnPath: boolean;
129
169
  returnCta: string;
@@ -296,8 +336,8 @@ const svc = defineService<S, {
296
336
  showSignIn: (s: S) => S;
297
337
  showRecovery: (s: S) => S;
298
338
  resetPassword: (s: S) => Promise<S>;
299
- signIn: (s: S) => Promise<S>;
300
- register: (s: S) => Promise<S>;
339
+ signIn: (s: S) => Promise<S | undefined>;
340
+ register: (s: S) => Promise<S | undefined>;
301
341
  signOut: (s: S) => Promise<S>;
302
342
  }>("himiStoreAccount", {
303
343
  state: derive({
@@ -381,30 +421,29 @@ const svc = defineService<S, {
381
421
  },
382
422
  signIn: async (s) => {
383
423
  if (!s.email || !s.password) return derive({ ...s, message: copyParam("storeAccount.validationEmailPassword", "Enter your email and password.") });
384
- try {
385
- await dispatch("himi.wix.signInDirect", { email: s.email, password: s.password });
386
- const next = await probe(optimisticMember(s, s.email));
387
- return derive({ ...next, message: next.isMember ? "" : copyParam("storeAccount.signInCheckDetails", "Sign in failed. Check your details.") });
388
- } catch {
389
- return derive({ ...s, message: copyParam("storeAccount.signInFailed", "Sign in failed. Try again.") });
390
- }
424
+ return authenticate(
425
+ s,
426
+ () => dispatch("himi.wix.signInDirect", { email: s.email, password: s.password }),
427
+ copyParam("storeAccount.signInCheckDetails", "Sign in failed. Check your details."),
428
+ copyParam("storeAccount.signInFailed", "Sign in failed. Try again."),
429
+ );
391
430
  },
392
431
  register: async (s) => {
393
432
  if (!s.email || !s.password) return derive({ ...s, message: copyParam("storeAccount.validationEmailPassword", "Enter your email and password.") });
394
- try {
395
- await dispatch("himi.wix.registerDirect", {
433
+ return authenticate(
434
+ s,
435
+ () => dispatch("himi.wix.registerDirect", {
396
436
  email: s.email,
397
437
  password: s.password,
398
438
  firstName: s.firstName,
399
439
  lastName: s.lastName,
400
- });
401
- const next = await probe(optimisticMember(s, s.email));
402
- return derive({ ...next, message: next.isMember ? "" : copyParam("storeAccount.registerTrySignIn", "Account creation failed. Try signing in.") });
403
- } catch {
404
- return derive({ ...s, message: copyParam("storeAccount.registerFailed", "Account creation failed. Try another email.") });
405
- }
440
+ }),
441
+ copyParam("storeAccount.registerTrySignIn", "Account creation failed. Try signing in."),
442
+ copyParam("storeAccount.registerFailed", "Account creation failed. Try another email."),
443
+ );
406
444
  },
407
445
  signOut: async (s) => {
446
+ routeInputConsumed = true;
408
447
  try { await dispatch("himi.wix.signOut"); } catch { /* ignore */ }
409
448
  // Do NOT re-probe via getMyData after logout — visitor-scoped my-data can
410
449
  // still return a site nickname and resurrect isMember (BUG-3). Trust the
@@ -10164,7 +10164,8 @@ const SCREENS = runtimeSetting({
10164
10164
  "action": {
10165
10165
  "actionId": "himi.open",
10166
10166
  "params": {
10167
- "screenId": "himi_account"
10167
+ "screenId": "himi_account",
10168
+ "returnScreenId": "himi_orders"
10168
10169
  }
10169
10170
  }
10170
10171
  }
@@ -15312,7 +15313,8 @@ const SCREENS = runtimeSetting({
15312
15313
  "action": {
15313
15314
  "actionId": "himi.open",
15314
15315
  "params": {
15315
- "screenId": "himi_account"
15316
+ "screenId": "himi_account",
15317
+ "returnScreenId": "himi_bookings"
15316
15318
  }
15317
15319
  }
15318
15320
  }
@@ -74098,6 +74100,29 @@ const TEMPLATED: { pattern: string; display: string; liveSeed?: LiveSeed; static
74098
74100
  },
74099
74101
  "hiddenPath": "$service:himiBrandedOrder.noEmpty"
74100
74102
  }
74103
+ },
74104
+ {
74105
+ "id": "himi_order.signin",
74106
+ "body": {
74107
+ "package": "himalaya",
74108
+ "type": "Button",
74109
+ "props": {
74110
+ "title": "Sign in",
74111
+ "style": "primary",
74112
+ "fullWidth": true,
74113
+ "action": {
74114
+ "actionId": "himi.open",
74115
+ "params": {
74116
+ "screenId": "himi_account",
74117
+ "returnScreenId": "himi_order",
74118
+ "returnId": "$service:himiBrandedOrder.id"
74119
+ }
74120
+ }
74121
+ }
74122
+ },
74123
+ "modifiers": {
74124
+ "hiddenPath": "$service:himiBrandedOrder.noSignIn"
74125
+ }
74101
74126
  }
74102
74127
  ]
74103
74128
  }
@@ -13,11 +13,20 @@ import {
13
13
  getMyNotificationPreferences,
14
14
  upsertMyNotificationPreferences,
15
15
  muteStatusFor,
16
- type NotificationTopic,
16
+ readTopics,
17
+ readPreferences,
18
+ isDeliveredNow,
19
+ isLocked,
20
+ preferenceFor,
21
+ type NotificationTopicDefinition,
17
22
  type PreferenceInfo,
18
23
  } from "@himalaya/wix-notification-preferences";
19
24
 
20
- interface Row { id: string; name: string; subtitle: string; on: boolean }
25
+ /** The channel this surface delivers on — read for the row state, written on toggle.
26
+ * One constant, so the read and the write cannot drift apart. */
27
+ const CHANNEL = "MOBILE";
28
+
29
+ interface Row { id: string; name: string; subtitle: string; on: boolean; locked: boolean }
21
30
  interface S {
22
31
  status: "loading" | "ready";
23
32
  topics: Row[]; emptyText: string;
@@ -28,11 +37,20 @@ interface S {
28
37
  notMockEmpty: boolean; notMockUnavailable: boolean;
29
38
  }
30
39
 
31
- /** A topic delivers unless an explicit MUTED preference silences it. The status
32
- * is nested at stateData.state.muteStatus (PreferenceStateData → PreferenceState). */
40
+ /** Whether this topic is actually being DELIVERED — not merely what the recipient
41
+ * asked for. `isDeliveredNow` prefers the server's `granted` verdict, so a topic the
42
+ * member unmuted under a channel-wide mute renders OFF instead of promising a
43
+ * notification that will never arrive. No preference row at all ⇒ the topic's default,
44
+ * which is delivery. */
33
45
  function isOn(topicId: string, prefs: PreferenceInfo[]): boolean {
34
- const p = prefs.find((x) => x.topicId === topicId);
35
- return p?.stateData?.state?.muteStatus !== "MUTED";
46
+ const p = preferenceFor(topicId, prefs, CHANNEL);
47
+ if (!p) return true;
48
+ return isDeliveredNow(p.stateData);
49
+ }
50
+
51
+ /** A row the server says cannot be changed here (a broader rule overrides it). */
52
+ function locked(topicId: string, prefs: PreferenceInfo[]): boolean {
53
+ return isLocked(preferenceFor(topicId, prefs, CHANNEL)?.stateData);
36
54
  }
37
55
 
38
56
  /** Row subtitle doubles as an affordance: current state + how to change it. */
@@ -41,12 +59,17 @@ function subtitleFor(on: boolean): string {
41
59
  }
42
60
 
43
61
  function row(id: string, name: string, on: boolean): Row {
44
- return { id, name, subtitle: subtitleFor(on), on };
62
+ return { id, name, subtitle: subtitleFor(on), on, locked: false };
45
63
  }
46
64
 
47
- function norm(t: NotificationTopic, prefs: PreferenceInfo[]): Row {
65
+ function norm(t: NotificationTopicDefinition, prefs: PreferenceInfo[]): Row {
48
66
  const name = (t.displayName || "Notification").trim() || "Notification";
49
- return row(t.id || name, name, isOn(t.id, prefs));
67
+ const id = t.topicId || name;
68
+ const r = row(id, name, isOn(id, prefs));
69
+ // An overridden row says so instead of offering a toggle that cannot take effect.
70
+ return locked(id, prefs)
71
+ ? { ...r, locked: true, subtitle: "Managed by your channel settings" }
72
+ : r;
50
73
  }
51
74
 
52
75
  const MOCK: Row[] = [
@@ -72,9 +95,9 @@ const svc = defineService<S, {
72
95
  getNotificationTopics(),
73
96
  getMyNotificationPreferences().catch(() => ({} as Awaited<ReturnType<typeof getMyNotificationPreferences>>)),
74
97
  ]);
75
- const prefs = prefsRes.preferences?.preferencesInfo ?? [];
76
- const topics = (topicsRes.topics ?? []).map((t) => norm(t, prefs));
77
- if (topics.length) return { ...s, status: "ready", topics, emptyText: "", isMock: false, notMock: true, notMockEmpty: true, notMockUnavailable: true};
98
+ const prefs = readPreferences(prefsRes);
99
+ const topics = readTopics(topicsRes).map((t) => norm(t, prefs));
100
+ if (topics.length) return { ...s, status: "ready", topics, emptyText: "", isMock: false, notMock: true, notMockEmpty: true, notMockUnavailable: true };
78
101
  return mockState(s, "empty");
79
102
  } catch {
80
103
  return mockState(s, "unavailable");
@@ -84,7 +107,8 @@ const svc = defineService<S, {
84
107
  // upsert is best-effort and a no-op on sample rows.
85
108
  toggle: async (s, p) => {
86
109
  const id = p?.id;
87
- if (!id) return s;
110
+ const target = s.topics.find((r) => r.id === id);
111
+ if (!id || !target || target.locked) return s;
88
112
  let nextOn = true;
89
113
  const topics = s.topics.map((r) => {
90
114
  if (r.id !== id) return r;
@@ -93,7 +117,11 @@ const svc = defineService<S, {
93
117
  });
94
118
  if (!s.isMock && !id.startsWith("sample-")) {
95
119
  try {
96
- await upsertMyNotificationPreferences([{ topicId: id, channel: "MOBILE", stateData: { state: { muteStatus: muteStatusFor(nextOn) } } }]);
120
+ // `stateData.state` is a SCALAR enum — the old nested `{ muteStatus }` was a
121
+ // shape this service does not have, so every write was malformed.
122
+ await upsertMyNotificationPreferences([
123
+ { topicId: id, channel: CHANNEL, stateData: { state: muteStatusFor(nextOn) } },
124
+ ]);
97
125
  } catch { /* keep the optimistic state */ }
98
126
  }
99
127
  return { ...s, topics };