@wix/himalaya-cli 0.1852.0 → 0.1854.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 (153) hide show
  1. package/dist/cli.mjs +1104 -711
  2. package/guides/himi-json-output.md +8 -2
  3. package/guides/iap-products.md +4 -0
  4. package/guides/one-app-section-mappings.md +2 -2
  5. package/guides/one-app-to-himi-app.md +28 -12
  6. package/guides/push-cli-onboarding.md +20 -0
  7. package/package.json +2 -2
  8. package/template-icons/bare-fashion.png +0 -0
  9. package/templates/bare-fashion/README.md +52 -0
  10. package/templates/bare-fashion/config.ts +474 -0
  11. package/templates/bare-fashion/dev/index.ts +16526 -0
  12. package/templates/bare-fashion/himalaya.content.json +70 -0
  13. package/templates/bare-fashion/himalaya.template.json +18 -0
  14. package/templates/bare-fashion/icon.png +0 -0
  15. package/templates/bare-fashion/platforms.json +3 -0
  16. package/templates/bare-fashion/tier5-src/_shared/app-locale.ts +70 -0
  17. package/templates/bare-fashion/tier5-src/_shared/bare-fashion-address-book.ts +116 -0
  18. package/templates/bare-fashion/tier5-src/_shared/bare-fashion-address-countries.ts +261 -0
  19. package/templates/bare-fashion/tier5-src/_shared/bare-fashion-bag-count.ts +24 -0
  20. package/templates/bare-fashion/tier5-src/_shared/bare-fashion-categories.ts +48 -0
  21. package/templates/bare-fashion/tier5-src/_shared/bare-fashion-facets.ts +265 -0
  22. package/templates/bare-fashion/tier5-src/_shared/bare-fashion-load-error.ts +38 -0
  23. package/templates/bare-fashion/tier5-src/_shared/bare-fashion-product-card.ts +136 -0
  24. package/templates/bare-fashion/tier5-src/_shared/bare-fashion-store-options.ts +129 -0
  25. package/templates/bare-fashion/tier5-src/_shared/branded-lite-hosted.ts +282 -0
  26. package/templates/bare-fashion/tier5-src/_shared/collection-contract.ts +228 -0
  27. package/templates/bare-fashion/tier5-src/_shared/collection-query.ts +201 -0
  28. package/templates/bare-fashion/tier5-src/_shared/collection-service.ts +429 -0
  29. package/templates/bare-fashion/tier5-src/_shared/engine-intl.ts +529 -0
  30. package/templates/bare-fashion/tier5-src/_shared/himi-account.ts +209 -0
  31. package/templates/bare-fashion/tier5-src/_shared/himi-copy.ts +123 -0
  32. package/templates/bare-fashion/tier5-src/_shared/himi-layouts.ts +142 -0
  33. package/templates/bare-fashion/tier5-src/_shared/himi-store-categories.ts +108 -0
  34. package/templates/bare-fashion/tier5-src/_shared/himi-store-saved.ts +57 -0
  35. package/templates/bare-fashion/tier5-src/_shared/himi-store.ts +7 -0
  36. package/templates/bare-fashion/tier5-src/_shared/himi-text.ts +24 -0
  37. package/templates/bare-fashion/tier5-src/_shared/hosted-checkout.ts +70 -0
  38. package/templates/bare-fashion/tier5-src/_shared/live-session.ts +172 -0
  39. package/templates/bare-fashion/tier5-src/_shared/local-preferences.ts +38 -0
  40. package/templates/bare-fashion/tier5-src/_shared/member-access.ts +63 -0
  41. package/templates/bare-fashion/tier5-src/_shared/member-avatar.ts +76 -0
  42. package/templates/bare-fashion/tier5-src/_shared/member-orders.ts +8 -0
  43. package/templates/bare-fashion/tier5-src/_shared/online-actions.ts +76 -0
  44. package/templates/bare-fashion/tier5-src/_shared/owner-load-error.ts +348 -0
  45. package/templates/bare-fashion/tier5-src/himi-bare-fashion-account/index.ts +127 -0
  46. package/templates/bare-fashion/tier5-src/himi-bare-fashion-address-form/index.ts +367 -0
  47. package/templates/bare-fashion/tier5-src/himi-bare-fashion-addresses/index.ts +202 -0
  48. package/templates/bare-fashion/tier5-src/himi-bare-fashion-appearance/index.ts +73 -0
  49. package/templates/bare-fashion/tier5-src/himi-bare-fashion-cart/index.ts +540 -0
  50. package/templates/bare-fashion/tier5-src/himi-bare-fashion-collection/index.ts +111 -0
  51. package/templates/bare-fashion/tier5-src/himi-bare-fashion-home/index.ts +241 -0
  52. package/templates/bare-fashion/tier5-src/himi-bare-fashion-nav/index.ts +56 -0
  53. package/templates/bare-fashion/tier5-src/himi-bare-fashion-order/index.ts +437 -0
  54. package/templates/bare-fashion/tier5-src/himi-bare-fashion-product/index.ts +650 -0
  55. package/templates/bare-fashion/tier5-src/himi-bare-fashion-products/index.ts +142 -0
  56. package/templates/bare-fashion/tier5-src/himi-bare-fashion-saved/index.ts +45 -0
  57. package/templates/bare-fashion/tier5-src/himi-bare-fashion-search/index.ts +199 -0
  58. package/templates/bare-fashion/tier5-src/himi-bare-fashion-shop/index.ts +79 -0
  59. package/templates/bare-fashion/tier5-src/himi-bare-fashion-sign-in/index.ts +269 -0
  60. package/templates/bare-fashion/tier5-src/himi-bare-fashion-wallet/index.ts +224 -0
  61. package/templates/bare-fashion/tier5-src/himi-branded-lite-info/index.ts +209 -0
  62. package/templates/bare-fashion/tier5-src/himi-branded-lite-orders/index.ts +327 -0
  63. package/templates/bare-fashion/tier5-src/wix-spaces-collections/index.ts +48 -0
  64. package/templates/bare-fashion/tier5-src/wix-spaces-delete-account/index.ts +59 -0
  65. package/templates/bare-fashion/tier5-src/wix-spaces-view-profile/index.ts +119 -0
  66. package/templates/bare-fashion/tokens.json +348 -0
  67. package/templates/beauty-salon/tier5-src/_shared/collection-query.ts +8 -0
  68. package/templates/beauty-salon/tier5-src/_shared/collection-service.ts +7 -1
  69. package/templates/beauty-salon-owner/tier5-src/_shared/collection-query.ts +8 -0
  70. package/templates/beauty-salon-owner/tier5-src/_shared/collection-service.ts +7 -1
  71. package/templates/branded-lite/recipes/upcoming-bookings.json +118 -6
  72. package/templates/branded-lite/tier5-src/_shared/announcement-section.ts +6 -14
  73. package/templates/branded-lite/tier5-src/_shared/collection-query-legacy.ts +7 -0
  74. package/templates/branded-lite/tier5-src/_shared/collection-query.ts +7 -0
  75. package/templates/branded-lite/tier5-src/_shared/collection-service.ts +7 -1
  76. package/templates/branded-lite/tier5-src/_shared/draft-content.ts +66 -0
  77. package/templates/branded-lite/tier5-src/_shared/events-inline-options.ts +55 -3
  78. package/templates/branded-lite/tier5-src/_shared/events-inline.ts +5 -3
  79. package/templates/branded-lite/tier5-src/_shared/upcoming-bookings-section.ts +15 -4
  80. package/templates/branded-lite/tier5-src/himi-events-list/index.ts +17 -0
  81. package/templates/brandy/tier5-src/_shared/collection-query-legacy.ts +7 -0
  82. package/templates/brandy/tier5-src/_shared/collection-query.ts +7 -0
  83. package/templates/brandy/tier5-src/_shared/collection-service.ts +7 -1
  84. package/templates/community-club/tier5-src/_shared/collection-query.ts +8 -0
  85. package/templates/community-club/tier5-src/_shared/collection-service.ts +7 -1
  86. package/templates/community-club/tier5-src/_shared/events-inline-options.ts +77 -0
  87. package/templates/community-club/tier5-src/himi-events-list/index.ts +17 -0
  88. package/templates/community-club-owner/tier5-src/_shared/collection-query.ts +8 -0
  89. package/templates/community-club-owner/tier5-src/_shared/collection-service.ts +7 -1
  90. package/templates/conference/tier5-src/_shared/collection-query.ts +8 -0
  91. package/templates/conference/tier5-src/_shared/collection-service.ts +7 -1
  92. package/templates/conference/tier5-src/_shared/events-inline-options.ts +77 -0
  93. package/templates/conference/tier5-src/himi-events-list/index.ts +17 -0
  94. package/templates/events-meetups/tier5-src/_shared/collection-query.ts +8 -0
  95. package/templates/events-meetups/tier5-src/_shared/collection-service.ts +7 -1
  96. package/templates/events-meetups/tier5-src/_shared/events-inline-options.ts +77 -0
  97. package/templates/events-meetups/tier5-src/himi-events-list/index.ts +17 -0
  98. package/templates/events-meetups-owner/tier5-src/_shared/collection-query.ts +8 -0
  99. package/templates/events-meetups-owner/tier5-src/_shared/collection-service.ts +7 -1
  100. package/templates/fitness-gym/tier5-src/_shared/collection-query.ts +8 -0
  101. package/templates/fitness-gym/tier5-src/_shared/collection-service.ts +7 -1
  102. package/templates/gym-fitness/tier5-src/_shared/collection-query.ts +8 -0
  103. package/templates/gym-fitness/tier5-src/_shared/collection-service.ts +7 -1
  104. package/templates/gym-fitness/tier5-src/_shared/events-inline-options.ts +77 -0
  105. package/templates/gym-fitness/tier5-src/himi-events-list/index.ts +17 -0
  106. package/templates/gym-fitness-owner/tier5-src/_shared/collection-query.ts +8 -0
  107. package/templates/gym-fitness-owner/tier5-src/_shared/collection-service.ts +7 -1
  108. package/templates/medical-services/tier5-src/_shared/collection-query.ts +8 -0
  109. package/templates/medical-services/tier5-src/_shared/collection-service.ts +7 -1
  110. package/templates/nonprofit-cause/tier5-src/_shared/collection-query.ts +8 -0
  111. package/templates/nonprofit-cause/tier5-src/_shared/collection-service.ts +7 -1
  112. package/templates/nonprofit-cause/tier5-src/_shared/events-inline-options.ts +77 -0
  113. package/templates/nonprofit-cause/tier5-src/himi-events-list/index.ts +17 -0
  114. package/templates/nonprofit-cause-owner/tier5-src/_shared/collection-query.ts +8 -0
  115. package/templates/nonprofit-cause-owner/tier5-src/_shared/collection-service.ts +7 -1
  116. package/templates/owner-lite/tier5-src/_shared/collection-query.ts +8 -0
  117. package/templates/owner-lite/tier5-src/_shared/collection-service.ts +7 -1
  118. package/templates/personal-fitness-trainer/tier5-src/_shared/collection-query.ts +8 -0
  119. package/templates/personal-fitness-trainer/tier5-src/_shared/collection-service.ts +7 -1
  120. package/templates/podcast-creator/tier5-src/_shared/collection-query.ts +8 -0
  121. package/templates/podcast-creator/tier5-src/_shared/collection-service.ts +7 -1
  122. package/templates/podcast-creator/tier5-src/_shared/events-inline-options.ts +77 -0
  123. package/templates/podcast-creator/tier5-src/himi-events-list/index.ts +17 -0
  124. package/templates/podcast-creator-owner/tier5-src/_shared/collection-query.ts +8 -0
  125. package/templates/podcast-creator-owner/tier5-src/_shared/collection-service.ts +7 -1
  126. package/templates/portfolio-creative/tier5-src/_shared/collection-query.ts +8 -0
  127. package/templates/portfolio-creative/tier5-src/_shared/collection-service.ts +7 -1
  128. package/templates/portfolio-creative/tier5-src/_shared/events-inline-options.ts +77 -0
  129. package/templates/portfolio-creative/tier5-src/himi-events-list/index.ts +17 -0
  130. package/templates/portfolio-creative-owner/tier5-src/_shared/collection-query.ts +8 -0
  131. package/templates/portfolio-creative-owner/tier5-src/_shared/collection-service.ts +7 -1
  132. package/templates/restaurant/tier5-src/_shared/collection-query.ts +8 -0
  133. package/templates/restaurant/tier5-src/_shared/collection-service.ts +7 -1
  134. package/templates/restaurant/tier5-src/_shared/events-inline-options.ts +77 -0
  135. package/templates/restaurant/tier5-src/himi-events-list/index.ts +17 -0
  136. package/templates/restaurant-owner/tier5-src/_shared/collection-query.ts +8 -0
  137. package/templates/restaurant-owner/tier5-src/_shared/collection-service.ts +7 -1
  138. package/templates/retail-store/tier5-src/_shared/collection-query-legacy.ts +7 -0
  139. package/templates/retail-store/tier5-src/_shared/collection-query.ts +7 -0
  140. package/templates/retail-store/tier5-src/_shared/collection-service.ts +7 -1
  141. package/templates/retail-store-owner/tier5-src/_shared/collection-query.ts +8 -0
  142. package/templates/retail-store-owner/tier5-src/_shared/collection-service.ts +7 -1
  143. package/templates/salon-spa/tier5-src/_shared/collection-query.ts +8 -0
  144. package/templates/salon-spa/tier5-src/_shared/collection-service.ts +7 -1
  145. package/templates/wholesale-store/tier5-src/_shared/collection-query-legacy.ts +7 -0
  146. package/templates/wholesale-store/tier5-src/_shared/collection-query.ts +7 -0
  147. package/templates/wholesale-store/tier5-src/_shared/collection-service.ts +7 -1
  148. package/templates/yoga-studio/tier5-src/_shared/collection-query.ts +8 -0
  149. package/templates/yoga-studio/tier5-src/_shared/collection-service.ts +7 -1
  150. package/templates/yoga-studio/tier5-src/_shared/events-inline-options.ts +77 -0
  151. package/templates/yoga-studio/tier5-src/himi-events-list/index.ts +17 -0
  152. package/templates/yoga-studio-owner/tier5-src/_shared/collection-query.ts +8 -0
  153. package/templates/yoga-studio-owner/tier5-src/_shared/collection-service.ts +7 -1
@@ -0,0 +1,348 @@
1
+ import { copyParam } from "./himi-copy.js";
2
+
3
+ /** Host-owned preview input. Absent on native and older hosts.
4
+ *
5
+ * `"sample"` — the built-in demo records; `"live"` — the viewer's own business over the
6
+ * owner rung; `"fixtures"` — a DEV web host over a sealed hermetic gateway, where
7
+ * the dev fixtures are the sample data. `"fixtures"` is neither live nor demo, so a
8
+ * worker READS through the bridge as it does on a device; it is still a preview host
9
+ * (`isOwnerPreviewHost`), so failure copy may name the web preview. */
10
+ function ownerPreviewMode(): unknown {
11
+ return (globalThis as unknown as { himalaya?: { input?: Record<string, unknown> } }).himalaya?.input?.__himiOwnerPreview;
12
+ }
13
+
14
+ export function isOwnerPreviewLive(): boolean {
15
+ return ownerPreviewMode() === "live";
16
+ }
17
+
18
+ /**
19
+ * Whether we are in the web preview AT ALL — i.e. the host declared a mode.
20
+ *
21
+ * `isBridgeUnavailable` cannot answer this: it reads "not live" as "preview",
22
+ * and on NATIVE there is no input at all, so `undefined` satisfies it. That is
23
+ * left alone for the other apps that use it to pick a demo fallback or to queue
24
+ * a write. Owner-lite reads ask `ownerDemoFallback` instead. It is NOT
25
+ * harmless for choosing COPY: native workers format their failures the same way (`"HTTP \(code): \(body)"`, JSWorker.swift;
26
+ * `"HTTP ${e.code}: ..."`, WebViewJSWorker.kt), so a transient `HTTP 503` on a
27
+ * phone would otherwise be answered with "open this app on a device" — on the
28
+ * device. Callers that pick a SENTENCE ask this instead.
29
+ */
30
+ export function isOwnerPreviewHost(): boolean {
31
+ return ownerPreviewMode() !== undefined;
32
+ }
33
+
34
+ export function isOwnerPreviewDemo(): boolean {
35
+ return ownerPreviewMode() === "sample";
36
+ }
37
+
38
+ /** Legacy hosts can still request the old demo fallback. An explicit live
39
+ * preview must never replace an authentication failure or outage with samples. */
40
+ export function isBridgeUnavailable(e: unknown): boolean {
41
+ if (ownerPreviewMode() === "live") return false;
42
+ return /HTTP (405|501|502|503)\b/.test(String((e as Error)?.message ?? e));
43
+ }
44
+
45
+ /**
46
+ * Whether a failed owner-lite READ may answer with the built-in demo records.
47
+ *
48
+ * Only where a demo was asked for: a web preview host that is not live. On a phone no
49
+ * mode is injected, so `isBridgeUnavailable` alone is `true` for a transient Wix
50
+ * `HTTP 503` — and the owner was shown sample appointments, orders and sites as if
51
+ * they were their business. Native falls through to the screen's error state.
52
+ * `isBridgeUnavailable` keeps its semantics: other apps' callers depend on it.
53
+ */
54
+ export function ownerDemoFallback(e: unknown): boolean {
55
+ return isOwnerPreviewHost() && !isOwnerPreviewLive() && isBridgeUnavailable(e);
56
+ }
57
+
58
+ /**
59
+ * The sentence for an owner WRITE that failed because the device could not reach Wix at
60
+ * all (a transport failure). Nothing replays a queued write on any platform — every host's
61
+ * `drain` passes an empty closure — so the honest answer is that nothing was saved.
62
+ * Copy-as-configuration under `ownerCommon.`, which every owner screen forwards.
63
+ */
64
+ export function ownerOfflineNotSaved(): string {
65
+ return copyParam(
66
+ "ownerCommon.offlineNotSaved",
67
+ "You’re offline — nothing was saved. Try again when you reconnect.",
68
+ );
69
+ }
70
+
71
+ /** The sentence for an owner WRITE that Wix answered with an unavailable status: the
72
+ * device is online, so it is not "offline" — but nothing was saved all the same. */
73
+ /**
74
+ * Whether a failed WRITE may have landed on Wix anyway, so the user must not be told it
75
+ * was not saved: a transport failure mid-request (timeout, reset, fetch rejection), the web
76
+ * host's after-send envelope (`HTTP 502 {…"sent":true}`), the serve bridge's mid-request
77
+ * `webwix_bridge_upstream_failed`, or a gateway status (502/503/504) that can arrive after
78
+ * the backend already ran. Only connect-time failures (`isOfflineFailure`) and the designed
79
+ * 405/501 bridge refusals prove nothing happened.
80
+ */
81
+ export function writeMayHaveLanded(e: unknown): boolean {
82
+ if (isOfflineFailure(e)) return false;
83
+ if (isTransportFailure(e)) return true;
84
+ const msg = String((e as Error)?.message ?? e ?? "");
85
+ if (/"sent"\s*:\s*true/.test(msg)) return true;
86
+ // The web host's own envelope WITHOUT `sent: true` failed before the request left it, and
87
+ // a disabled owner rung / bridge refuses by design without sending anything.
88
+ if (/\bwebwix_(?:direct_failed|owner_disabled|bridge_disabled)\b/.test(msg)) return false;
89
+ // `webwix_bridge_upstream_failed` stays ambiguous: the same code covers a lookup that failed
90
+ // before sending and a serve-bridge failure mid-request, and nothing in it says which.
91
+ return /\bwebwix_bridge_upstream_failed\b/.test(msg) || /HTTP (502|503|504)\b/.test(msg);
92
+ }
93
+
94
+ /** Wix answered that the record does not exist (`HTTP 404`). A detail must not fall back to
95
+ * its cached row then: that row is what a delete whose reply was lost leaves behind. */
96
+ export function isNotFound(e: unknown): boolean {
97
+ if (/HTTP 404\b/.test(String((e as Error)?.message ?? e ?? ""))) return true;
98
+ // An SDK that answers a 404 with its own "not found" error keeps the HTTP one as `cause`
99
+ // (the blog SDK's getPost, after its query fallback also finds nothing).
100
+ const cause = (e as { cause?: unknown } | null | undefined)?.cause;
101
+ return cause !== undefined && cause !== e && /HTTP 404\b/.test(String((cause as Error)?.message ?? cause));
102
+ }
103
+
104
+ export function ownerUnavailableNotSaved(): string {
105
+ return copyParam(
106
+ "ownerCommon.unavailableNotSaved",
107
+ "Wix isn’t available right now — nothing was saved. Try again in a moment.",
108
+ );
109
+ }
110
+
111
+ /** The sentence for an owner WRITE that may have landed (`writeMayHaveLanded`): it can't
112
+ * be called saved or not saved. */
113
+ export function ownerWriteUnconfirmed(): string {
114
+ return copyParam(
115
+ "ownerCommon.writeUnconfirmed",
116
+ "Wix didn’t confirm this, so it may or may not have been saved. Check before trying again.",
117
+ );
118
+ }
119
+
120
+ /** Display copy for a failed owner write: `ownerOfflineNotSaved` when the request never
121
+ * left the device, `ownerWriteUnconfirmed` when it may have landed, `ownerUnavailableNotSaved`
122
+ * for the designed 405/501 bridge refusals outside a live preview, else `ownerLoadError`. */
123
+ export function ownerWriteError(e: unknown): string {
124
+ if (isOfflineFailure(e)) return ownerOfflineNotSaved();
125
+ if (writeMayHaveLanded(e)) return ownerWriteUnconfirmed();
126
+ if (!isOwnerPreviewLive() && /HTTP (405|501)\b/.test(String((e as Error)?.message ?? e))) return ownerUnavailableNotSaved();
127
+ return ownerLoadError(e);
128
+ }
129
+
130
+ /** `HTTP 403: …` → "403", when the message carries a status at all. */
131
+ const STATUS = /HTTP (\d{3})\b/;
132
+ /** A wire body that is an HTML DOCUMENT, not a message. */
133
+ const HTML_BODY = /<!DOCTYPE html|<html[\s>]|<head[\s>]/i;
134
+ /** A wire body that is a JSON ENVELOPE, not a message. The serve bridge answers
135
+ * its typed refusals this way — `HTTP 501: {"error":"webwix_owner_no_session",
136
+ * "app":"…"}` — and it is short enough to slip under MAX_RAW, so truncation
137
+ * never caught it and the owner read the machine's word for it. */
138
+ const JSON_BODY = /HTTP \d{3}:\s*[[{]/;
139
+ /** `HTTP <status> [SERVICE_CODE]: message` — the shape a Wix service uses when
140
+ * it refuses with a named reason. */
141
+ const CODED = /HTTP (\d{3}) \[([A-Z0-9_]+)\]/;
142
+ /**
143
+ * The codes that all mean one thing to an owner: the session cannot address this
144
+ * business. Found on a real session whose account did not own the business the app
145
+ * had persisted — Home rendered
146
+ * `HTTP 428 [MISSING_METASITE_ID]: Couldn't extract metasiteId from the request
147
+ * context` where "6 orders" belongs.
148
+ */
149
+ const SITE_CONTEXT_CODES = ["MISSING_METASITE_ID", "MISSING_REQUEST_SITE_CONTEXT", "MISSING_SITE_CONTEXT"];
150
+ /** Longest raw upstream text worth showing. Beyond this it stops being a
151
+ * message and starts being a payload dump. */
152
+ const MAX_RAW = 200;
153
+
154
+ /**
155
+ * A TRANSPORT failure: the request never got an HTTP answer at all.
156
+ *
157
+ * Each host describes one in its own platform's words, and every one of them is a
158
+ * diagnostic dump rather than a message. iOS's JSWorker hands a worker the Swift
159
+ * description of the `NSError` —
160
+ * `Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server."
161
+ * UserInfo={… NSErrorFailingURLStringKey=http://127.0.0.1:8178/__dev/wix/proxy, …}`
162
+ * — which Aria painted verbatim: the domain, the code, and the local server's
163
+ * own URL. Android's bridge carries the `java.net` exception text, and a browser's
164
+ * fetch rejects with "Failed to fetch" / "Load failed" / "NetworkError …".
165
+ *
166
+ * Only a message with NO HTTP status qualifies: a status means Wix answered, and
167
+ * that case keeps its own reductions below.
168
+ */
169
+ const TRANSPORT = [
170
+ /\bError Domain=\w+/, // any Cocoa NSError description
171
+ /\bNSURLErrorDomain\b/,
172
+ /\bjava\.(?:net|io)\.\w+(?:Exception|Error)\b/,
173
+ /\b(?:UnknownHost|Connect|SocketTimeout|NoRouteToHost|SSLHandshake)Exception\b/,
174
+ // Android's WebViewJSWorker bridges `e.message ?: e.javaClass.simpleName`, so
175
+ // the class name is usually absent and only OkHttp's own message arrives.
176
+ /^Failed to connect to \S/,
177
+ /^Unable to resolve host\b/,
178
+ /\b(?:Connection refused|Network is unreachable|Software caused connection abort)\b/,
179
+ // OkHttp / HttpURLConnection messages a dropped connection produces mid-request, which
180
+ // Android's bridge forwards without the exception class.
181
+ /\b(?:Connection reset|ECONNRESET|ETIMEDOUT|EPIPE|Broken pipe|stream was reset)\b/,
182
+ /^unexpected end of stream\b/i,
183
+ /^(?:timeout|Read timed out|connect timed out)$/i,
184
+ /\bFailed to fetch\b/,
185
+ /\bNetworkError when attempting to fetch\b/,
186
+ /^(?:TypeError: )?Load failed$/,
187
+ /\bnet::ERR_[A-Z_]+/,
188
+ ];
189
+
190
+ /** Did this failure happen below HTTP — no answer from Wix at all? */
191
+ export function isTransportFailure(e: unknown): boolean {
192
+ const msg = String((e as Error)?.message ?? e ?? "");
193
+ if (STATUS.test(msg)) return false;
194
+ return TRANSPORT.some((re) => re.test(msg));
195
+ }
196
+
197
+ /** A failed READ says nothing about the record's existence when Wix is
198
+ * unreachable, overloaded or failing. Unlike the legacy bridge predicate this
199
+ * is independent of preview mode; a live preview's gateway failure is one too. */
200
+ export function readWasUnreachable(e: unknown): boolean {
201
+ const msg = String((e as Error)?.message ?? e ?? "");
202
+ return isTransportFailure(e) || /HTTP (?:408|429|5\d{2})\b/.test(msg);
203
+ }
204
+
205
+ /** Transport failures that happen while CONNECTING — no connection, no route, no such host,
206
+ * connection refused — so the request provably never left the device. Every other
207
+ * transport failure (a timeout, a reset, a bad or truncated response, a browser's fetch
208
+ * rejection, which says nothing about when it failed) may come after Wix took the write. */
209
+ const NEVER_SENT = [
210
+ /\bNSURLErrorDomain Code=-10(?:09|04|03|06|20|18)\b/, // not connected / cannot connect / no host / DNS / data not allowed / roaming off
211
+ /\b(?:UnknownHost|Connect|NoRouteToHost)Exception\b/,
212
+ /^Failed to connect to \S/,
213
+ /^Unable to resolve host\b/,
214
+ /\b(?:Connection refused|Network is unreachable)\b/,
215
+ /\bnet::ERR_(?:INTERNET_DISCONNECTED|NAME_NOT_RESOLVED|CONNECTION_REFUSED|ADDRESS_UNREACHABLE|NETWORK_ACCESS_DENIED)\b/,
216
+ ];
217
+
218
+ /** No HTTP answer, and the request provably never left the device: the user is offline, and
219
+ * a write certainly did not happen. Anything else may have landed (see `NEVER_SENT`). */
220
+ export function isOfflineFailure(e: unknown): boolean {
221
+ if (!isTransportFailure(e)) return false;
222
+ const msg = String((e as Error)?.message ?? e ?? "");
223
+ return NEVER_SENT.some((re) => re.test(msg));
224
+ }
225
+
226
+ /** The one sentence for a transport failure. Copy-as-configuration: the key is
227
+ * under `ownerCommon.`, which every owner screen (Aria included) forwards. */
228
+ export function ownerTransportFailureText(): string {
229
+ return copyParam(
230
+ "ownerCommon.networkUnreachable",
231
+ "Couldn’t reach Wix. Check your connection and try again.",
232
+ );
233
+ }
234
+
235
+ /**
236
+ * Reduce a wire failure to something a PERSON can read.
237
+ *
238
+ * Wix's edge answers some failures with a full HTML error page rather than JSON
239
+ * — a `403 Error: Forbidden | Wix.com` document. `ownerLoadError` used to return
240
+ * the raw body, so the Orders screen rendered an entire `<!DOCTYPE html>…<head>…`
241
+ * document as its error message (seen on iOS, and the same worker code runs on
242
+ * every surface). Keep the STATUS, which is the diagnosable part, and drop the
243
+ * markup; a long non-HTML body is truncated for the same reason.
244
+ */
245
+ function humanWireError(msg: string): string {
246
+ if (isTransportFailure(msg)) return ownerTransportFailureText();
247
+ const status = STATUS.exec(msg)?.[1];
248
+ // A JSON ENVELOPE or a NAMED REASON CODE is the machine's word for it, and the
249
+ // owner gets neither. Both reductions used to live in `ownerDisplayError` only,
250
+ // on the belief that this function's output was parsed downstream — see the note
251
+ // on `ownerLoadError`, which records why that was wrong and how it was checked.
252
+ if (JSON_BODY.test(msg) && status) {
253
+ return copyParam(
254
+ "ownerCommon.upstreamStatus",
255
+ `Wix returned an error (HTTP ${status}). Try again in a moment.`,
256
+ );
257
+ }
258
+ const coded = CODED.exec(msg);
259
+ if (coded) {
260
+ if (SITE_CONTEXT_CODES.includes(coded[2])) {
261
+ return copyParam(
262
+ "ownerCommon.noSiteContext",
263
+ "This business isn’t available to your Wix account right now. Switch business, or sign in again as its owner.",
264
+ );
265
+ }
266
+ return copyParam(
267
+ "ownerCommon.upstreamStatus",
268
+ `Wix returned an error (HTTP ${coded[1]}). Try again in a moment.`,
269
+ );
270
+ }
271
+ if (HTML_BODY.test(msg)) {
272
+ if (status === "403") {
273
+ return copyParam(
274
+ "ownerCommon.forbidden",
275
+ "This account isn’t permitted to read that. Check the site’s permissions for your Wix user, then try again.",
276
+ );
277
+ }
278
+ return copyParam(
279
+ "ownerCommon.upstreamHtml",
280
+ status ? `Wix returned an error (HTTP ${status}). Try again in a moment.` : "Wix returned an unreadable error. Try again in a moment.",
281
+ );
282
+ }
283
+ return msg.length > MAX_RAW ? `${msg.slice(0, MAX_RAW).trimEnd()}…` : msg;
284
+ }
285
+
286
+ /**
287
+ * The one sentence every owner screen gives for the DESIGNED bridge boundary.
288
+ *
289
+ * Copy-as-configuration (himi-copy): the key lives under the `ownerCommon.`
290
+ * prefix the dev module forwards to all owner screens, so one pack retitles it
291
+ * everywhere. With no pack this returns the stock copy verbatim.
292
+ */
293
+ export function ownerPreviewUnavailable(): string {
294
+ return copyParam(
295
+ "ownerCommon.bridgeUnavailable",
296
+ "Owner data isn’t available in the web preview — open this app on a device (▦ Open on phone) and sign in as the site owner.",
297
+ );
298
+ }
299
+
300
+ /**
301
+ * `ownerLoadError` for a screen that does nothing but RENDER the string.
302
+ *
303
+ * One difference left, and it is about WHERE the app is rather than what the
304
+ * error says: this names the web preview when there IS one. `isBridgeUnavailable`
305
+ * reads "not live" as "preview", and native injects no mode at all, so the
306
+ * default would answer a device-side `HTTP 503` with "open this app on a device"
307
+ * — on the device. That predicate is deliberately left alone: other apps'
308
+ * demo and write-queue decisions depend on exactly it.
309
+ *
310
+ * The reductions this used to add are now in `humanWireError`, so every owner
311
+ * screen gets them rather than the two that happened to call this.
312
+ */
313
+ export function ownerDisplayError(e: unknown): string {
314
+ if (isOwnerPreviewHost() && isBridgeUnavailable(e)) return ownerPreviewUnavailable();
315
+ return humanWireError(String((e as Error)?.message ?? e));
316
+ }
317
+
318
+ /**
319
+ * The default. Reduces the same shapes as `ownerDisplayError`.
320
+ *
321
+ * It used to reduce LESS, on the stated grounds that its output is parsed
322
+ * downstream — "the products worker matches `CATALOG_V3_CALLING_CATALOG_V1_API`
323
+ * in it to choose its v1 fallback". **That was not true**, and it cost 17 owner
324
+ * screens their error copy: they printed `HTTP 428 [MISSING_METASITE_ID]: …`
325
+ * verbatim for a contract that does not exist.
326
+ *
327
+ * Checked before changing it, and worth recording so nobody restores the belief:
328
+ *
329
+ * • the catalog v1/v3 decision is made INSIDE the Wix stores SDK, on the RAW
330
+ * thrown error — its `catalogVersionFromMismatch` reads the error's own
331
+ * `message`, and only that module calls it. It never sees this function's
332
+ * output.
333
+ * • `CATALOG_V3_CALLING_CATALOG_V1_API` appears nowhere else in the codebase
334
+ * outside comments, tests and that one SDK module.
335
+ * • the collection framework's `clearOnError` is handed the RAW error
336
+ * (`error => /401|403|forbidden/i.test(String(error))`), separately from
337
+ * `errorMessage: ownerLoadError` — so the one place that does match on a
338
+ * failure is unaffected by what this returns.
339
+ *
340
+ * So: the raw error remains available to logic everywhere it was; this function's
341
+ * result is display copy, and now reads like it.
342
+ */
343
+ export function ownerLoadError(e: unknown): string {
344
+ const msg = String((e as Error)?.message ?? e);
345
+ // Same host guard as `ownerDisplayError`: on a phone, "open this app on a device" is false.
346
+ if (isOwnerPreviewHost() && isBridgeUnavailable(e)) return ownerPreviewUnavailable();
347
+ return humanWireError(msg);
348
+ }
@@ -0,0 +1,127 @@
1
+ // Tier-5 bundle: himi-store — visitor/member account state.
2
+ //
3
+ // SINGLE-SITE BY DESIGN. A Branded Lite build talks to exactly one Wix site, and the
4
+ // binding is the baked Headless `clientId` itself:
5
+ // there is no metaSiteId to move and Wix will not route a consumer token minted for one
6
+ // client at another site. This worker therefore has no site picker — Profile used to carry
7
+ // a "Your sites" list that dispatched `branded_lite.select_site`, which changed the
8
+ // `wix-site-id` header and nothing else, so every read stayed on the baked site while the
9
+ // UI claimed otherwise. Managing several businesses is Owner Lite's job (account auth, a
10
+ // real Sites List, and per-call site scope via `site.forSite`).
11
+ //
12
+ // The Account tab is a greeting and a menu. The sign-in, sign-up and reset form is its own
13
+ // screen (himi_sign_in, bundle himi-store-sign-in), because a screen cannot bind to another
14
+ // screen's service. That screen changes the session while this one stays mounted, and iOS
15
+ // does not re-fire `onAppear` on a Back or a tab return — so a `_poll` re-reads the session.
16
+ import { defineService, navigate } from "@himalaya/state";
17
+ import { dispatch } from "@himalaya/dispatch";
18
+ import { guestProfile, loadMemberProfile, signedInEmail, type AccountProfile } from "../_shared/himi-account";
19
+ import { stashCopy, copyParam, copyTemplate } from "../_shared/himi-copy.js";
20
+
21
+ // A tick reads only the session (`himi.wix.memberIdentity`). The profile is fetched again
22
+ // only when the signed-in email changes, so an idle tick costs no profile read.
23
+ const MEMBER_SCREENS = new Set(["himi_orders", "himi_addresses", "himi_wallet"]);
24
+ const IDENTITY_POLL = { id: "himi-account-identity", intervalMs: 1500, action: "bareFashionAccount.sync" };
25
+
26
+ interface S {
27
+ /** "error": the session could not be read; the screen shows the guest menu (Sign in still works)
28
+ * and keeps checking, rather than a skeleton that never ends. */
29
+ status: "loading" | "ready" | "error";
30
+ isMember: boolean;
31
+ memberName: string;
32
+ memberEmail: string;
33
+ greeting: string;
34
+ /** Guest header: hidden for a member and while the first session check runs. */
35
+ hideGuest: boolean;
36
+ /** Member header, My account row and the Sign out footer. */
37
+ hideMember: boolean;
38
+ /** Loading skeleton: hidden once the session check finishes. */
39
+ hideLoading: boolean;
40
+ }
41
+
42
+ /** "Hey, <name>" wants a name. A profile with no display name carries the email instead. */
43
+ function greetingName(profile: AccountProfile): string {
44
+ const name = profile.memberName.trim();
45
+ return name.includes("@") ? name.slice(0, name.indexOf("@")) : name;
46
+ }
47
+
48
+ function derive(s: S): S {
49
+ const loading = s.status === "loading";
50
+ return { ...s, hideGuest: loading || s.isMember, hideMember: loading || !s.isMember, hideLoading: !loading };
51
+ }
52
+
53
+ function fromProfile(s: S, profile: AccountProfile): S {
54
+ const name = greetingName(profile);
55
+ return derive({
56
+ ...s,
57
+ status: "ready",
58
+ isMember: profile.isMember,
59
+ memberName: profile.memberName,
60
+ memberEmail: profile.memberEmail,
61
+ greeting: profile.isMember && name
62
+ ? copyTemplate("storeAccount.greetingMember", "Hey, {name}", { name })
63
+ : copyParam("storeAccount.greetingGuest", "Hey, guest"),
64
+ });
65
+ }
66
+
67
+ async function probe(s: S): Promise<S> {
68
+ try {
69
+ const profile = await loadMemberProfile("");
70
+ return { ...fromProfile(s, profile), _poll: { ...IDENTITY_POLL } } as S;
71
+ } catch {
72
+ return { ...fromProfile(s, guestProfile("")), status: "error", _poll: { ...IDENTITY_POLL } } as S;
73
+ }
74
+ }
75
+
76
+ const svc = defineService<S, {
77
+ load: (s: S, arg?: unknown) => Promise<S>;
78
+ refresh: (s: S, arg?: unknown) => Promise<S>;
79
+ sync: (s: S) => Promise<S | undefined>;
80
+ openOrders: (s: S) => Promise<S>;
81
+ openMember: (s: S, arg?: unknown) => Promise<S>;
82
+ signOut: (s: S) => Promise<S>;
83
+ }>("bareFashionAccount", {
84
+ state: derive({
85
+ status: "loading",
86
+ isMember: false,
87
+ memberName: "",
88
+ memberEmail: "",
89
+ greeting: "Hey, guest",
90
+ hideGuest: true,
91
+ hideMember: true,
92
+ hideLoading: true,
93
+ }),
94
+ actions: {
95
+ load: (s, arg) => { stashCopy(arg); return probe(s); },
96
+ refresh: (s, arg) => { stashCopy(arg); return probe(s); },
97
+ // Idle ticks return undefined, so an unchanged session costs no re-render.
98
+ sync: async (s) => {
99
+ const email = await signedInEmail();
100
+ return email === s.memberEmail ? undefined : probe(s);
101
+ },
102
+ // A guest is asked to sign in first, then lands on My orders (the sign-in screen
103
+ // replaces itself with it), so Back from My orders returns here.
104
+ openOrders: async (s) => {
105
+ if (await signedInEmail()) return navigate(s, { screenId: "himi_orders" });
106
+ return navigate(s, { screenId: "himi_sign_in", args: { mode: "signin", returnScreenId: "himi_orders" } });
107
+ },
108
+ // The same for My addresses and My wallet. Only these member screens are allowed.
109
+ openMember: async (s, arg) => {
110
+ const id = arg && typeof arg === "object" ? (arg as { screenId?: unknown }).screenId : arg;
111
+ const screenId = typeof id === "string" && MEMBER_SCREENS.has(id) ? id : "";
112
+ if (!screenId) return s;
113
+ if (await signedInEmail()) return navigate(s, { screenId });
114
+ return navigate(s, { screenId: "himi_sign_in", args: { mode: "signin", returnScreenId: screenId } });
115
+ },
116
+ signOut: async (s) => {
117
+ try { await dispatch("himi.wix.signOut"); } catch { /* ignore */ }
118
+ // Do NOT re-probe via getMyData after logout — visitor-scoped my-data can
119
+ // still return a site nickname and resurrect isMember (BUG-3). Trust the
120
+ // cleared session and paint the guest state immediately.
121
+ return { ...fromProfile(s, guestProfile("")), _poll: { ...IDENTITY_POLL } } as S;
122
+ },
123
+ },
124
+ });
125
+
126
+ svc.load();
127
+ export { svc };