@wix/himalaya-cli 0.1678.0 → 0.1680.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 (80) hide show
  1. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/sdk/l10n/src/locale.d.ts +31 -0
  2. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/serve-runtime/src/wix-bridge.d.ts +12 -13
  3. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/_types/core/ts/src/legacy-import.d.ts +51 -2
  4. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/core.mjs +37 -2
  5. package/dist/authoring-runtime/node_modules/@wix/himalaya/dist/l10n/locale.mjs +54 -0
  6. package/dist/authoring-runtime/node_modules/@wix/himalaya/package.json +4 -0
  7. package/dist/browser-plane/assets.json +5 -5
  8. package/dist/browser-plane/preview-deferred/{4a260ef73a6f9f421a9119eac3d67bb9978e67b44c66a870038d189e6c77a0bd.bin → 4f58be42c5c8007715860f364adb1cdcb02156d76672fa38ba7ea412ee8fac2a.bin} +1 -1
  9. package/dist/browser-plane/sw.js +8 -8
  10. package/dist/cli.mjs +507 -382
  11. package/dist/preview-assets.generated.bin +0 -0
  12. package/package.json +2 -2
  13. package/templates/beauty-salon/dev/index.ts +1 -0
  14. package/templates/beauty-salon/tier5-src/_shared/wix-bi.ts +85 -0
  15. package/templates/beauty-salon/tier5-src/himi-branded-lite-cart/index.ts +9 -0
  16. package/templates/beauty-salon-owner/dev/index.ts +2 -1
  17. package/templates/beauty-salon-owner/tier5-src/_shared/wix-bi.ts +85 -0
  18. package/templates/beauty-salon-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +6 -2
  19. package/templates/branded-lite/dev/index.ts +9 -4
  20. package/templates/branded-lite/tier5-src/_shared/wix-bi.ts +85 -0
  21. package/templates/branded-lite/tier5-src/business-chat/index.ts +8 -0
  22. package/templates/branded-lite/tier5-src/himi-branded-lite-cart/index.ts +9 -0
  23. package/templates/branded-lite/tier5-src/himi-store-product/index.ts +14 -0
  24. package/templates/branded-lite/tier5-src/wix-spaces-chat-thread/index.ts +3 -1
  25. package/templates/branded-lite/tier5-src/wix-spaces-food-orders/index.ts +15 -0
  26. package/templates/branded-lite/tier5-src/wix-spaces-forum/index.ts +22 -1
  27. package/templates/community-club-owner/dev/index.ts +2 -1
  28. package/templates/community-club-owner/tier5-src/_shared/wix-bi.ts +85 -0
  29. package/templates/community-club-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +6 -2
  30. package/templates/conference/dev/index.ts +2 -1
  31. package/templates/conference/tier5-src/_shared/wix-bi.ts +85 -0
  32. package/templates/conference/tier5-src/business-chat/index.ts +8 -0
  33. package/templates/events-meetups-owner/dev/index.ts +2 -1
  34. package/templates/events-meetups-owner/tier5-src/_shared/wix-bi.ts +85 -0
  35. package/templates/events-meetups-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +6 -2
  36. package/templates/gym-fitness/dev/index.ts +1 -0
  37. package/templates/gym-fitness/tier5-src/_shared/wix-bi.ts +85 -0
  38. package/templates/gym-fitness/tier5-src/himi-branded-lite-cart/index.ts +9 -0
  39. package/templates/gym-fitness-owner/dev/index.ts +2 -1
  40. package/templates/gym-fitness-owner/tier5-src/_shared/wix-bi.ts +85 -0
  41. package/templates/gym-fitness-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +6 -2
  42. package/templates/nonprofit-cause-owner/dev/index.ts +2 -1
  43. package/templates/nonprofit-cause-owner/tier5-src/_shared/wix-bi.ts +85 -0
  44. package/templates/nonprofit-cause-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +6 -2
  45. package/templates/owner-lite/dev/index.ts +2 -1
  46. package/templates/owner-lite/tier5-src/_shared/wix-bi.ts +85 -0
  47. package/templates/owner-lite/tier5-src/himi-owner-lite-inbox-thread/index.ts +6 -2
  48. package/templates/podcast-creator-owner/dev/index.ts +2 -1
  49. package/templates/podcast-creator-owner/tier5-src/_shared/wix-bi.ts +85 -0
  50. package/templates/podcast-creator-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +6 -2
  51. package/templates/portfolio-creative/dev/index.ts +1 -0
  52. package/templates/portfolio-creative/tier5-src/_shared/wix-bi.ts +85 -0
  53. package/templates/portfolio-creative/tier5-src/himi-branded-lite-cart/index.ts +9 -0
  54. package/templates/portfolio-creative-owner/dev/index.ts +2 -1
  55. package/templates/portfolio-creative-owner/tier5-src/_shared/wix-bi.ts +85 -0
  56. package/templates/portfolio-creative-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +6 -2
  57. package/templates/restaurant/dev/index.ts +2 -1
  58. package/templates/restaurant/tier5-src/_shared/wix-bi.ts +85 -0
  59. package/templates/restaurant/tier5-src/wix-spaces-food-orders/index.ts +15 -0
  60. package/templates/restaurant-owner/dev/index.ts +2 -1
  61. package/templates/restaurant-owner/tier5-src/_shared/wix-bi.ts +85 -0
  62. package/templates/restaurant-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +6 -2
  63. package/templates/retail-store/dev/index.ts +1 -0
  64. package/templates/retail-store/tier5-src/_shared/wix-bi.ts +85 -0
  65. package/templates/retail-store/tier5-src/himi-branded-lite-cart/index.ts +9 -0
  66. package/templates/retail-store/tier5-src/himi-store-product/index.ts +14 -0
  67. package/templates/retail-store-owner/dev/index.ts +2 -1
  68. package/templates/retail-store-owner/tier5-src/_shared/wix-bi.ts +85 -0
  69. package/templates/retail-store-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +6 -2
  70. package/templates/salon-spa/dev/index.ts +2 -1
  71. package/templates/salon-spa/tier5-src/_shared/wix-bi.ts +85 -0
  72. package/templates/salon-spa/tier5-src/business-chat/index.ts +8 -0
  73. package/templates/wholesale-store/dev/index.ts +3 -1
  74. package/templates/wholesale-store/tier5-src/_shared/wix-bi.ts +85 -0
  75. package/templates/wholesale-store/tier5-src/business-chat/index.ts +8 -0
  76. package/templates/wholesale-store/tier5-src/himi-branded-lite-cart/index.ts +9 -0
  77. package/templates/wholesale-store/tier5-src/himi-store-product/index.ts +14 -0
  78. package/templates/yoga-studio-owner/dev/index.ts +2 -1
  79. package/templates/yoga-studio-owner/tier5-src/_shared/wix-bi.ts +85 -0
  80. package/templates/yoga-studio-owner/tier5-src/himi-owner-lite-inbox-thread/index.ts +6 -2
@@ -0,0 +1,85 @@
1
+ // RN BI events whose fields exist only in a worker (epic #4973). The platform maps send every
2
+ // other RN event; these go through `wixPlatform.bi.log`, built inline with RN's own field names
3
+ // rather than by bundling a `@wix/bi-logger-*` package. The host owns every identity and common
4
+ // field (msid, uuid, installationId, contactId, _lv, ...), so none is named here.
5
+ import { bi, type BiLogEvent } from "@himalaya/wix-platform";
6
+
7
+ /** Sends one event without waiting for it and never throws: BI must not change a screen. A
8
+ * screen whose descriptor does not declare `wix_platform` is refused by the host, which is
9
+ * swallowed here like any other BI failure. */
10
+ export function logBi(event: BiLogEvent): void {
11
+ try {
12
+ void Promise.resolve(bi.log(event)).catch(() => undefined);
13
+ } catch {
14
+ /* BI is best-effort */
15
+ }
16
+ }
17
+
18
+ /** The HTTP status a Wix SDK error carries (`HTTP 429: ...`, or a `status` field), else 0. */
19
+ export function wixErrorStatus(error: unknown): number {
20
+ const own = Number((error as { status?: unknown; statusCode?: unknown } | null)?.status ?? (error as { statusCode?: unknown } | null)?.statusCode);
21
+ if (Number.isFinite(own) && own > 0) return own;
22
+ const match = /\bHTTP (\d{3})\b/.exec(String((error as Error | null)?.message ?? error ?? ""));
23
+ return match ? Number(match[1]) : 0;
24
+ }
25
+
26
+ function applicationErrorCode(body: unknown): string {
27
+ const o = body as { details?: { applicationError?: { code?: unknown } }; applicationError?: { code?: unknown }; code?: unknown } | null;
28
+ const code = o?.details?.applicationError?.code ?? o?.applicationError?.code ?? o?.code;
29
+ return typeof code === "string" ? code : "";
30
+ }
31
+
32
+ /** The code both native bridges put in an application error's message: `HTTP 400 [CODE]: description`
33
+ * (iOS JSWorker.swift `WixApiCapability.Error.application`, Android WebViewJSWorker.kt `Error.Application`). */
34
+ const BRIDGE_APPLICATION_CODE = /\bHTTP \d{3} \[([A-Za-z0-9_.:-]+)\]/;
35
+
36
+ /** The Wix application error code of a failed call (RN's `serializeError(e).code`): read from the
37
+ * error itself, else from the `[CODE]` the native bridges put after `HTTP <status> `, else from the
38
+ * JSON body after `HTTP <status>: ` (the bridges' raw-status arm and the web host's wixCall). ""
39
+ * when there is none. */
40
+ export function wixErrorCode(error: unknown): string {
41
+ const own = applicationErrorCode(error);
42
+ if (own) return own;
43
+ const message = String((error as Error | null)?.message ?? error ?? "");
44
+ const bracketed = BRIDGE_APPLICATION_CODE.exec(message);
45
+ if (bracketed) return bracketed[1];
46
+ const start = message.indexOf("{");
47
+ if (start < 0) return "";
48
+ try {
49
+ return applicationErrorCode(JSON.parse(message.slice(start)));
50
+ } catch {
51
+ return "";
52
+ }
53
+ }
54
+
55
+ // RN's `ErrorIndicationType` (mobile-apps-inbox services/errorIndications/errorIndications.type.ts).
56
+ const ERROR_INDICATIONS = new Set([
57
+ "ACCESS_TOKEN_EXPIRED", "ALLOWED_MESSAGING_TIME_WINDOW_EXPIRED", "ATTACHMENT_SIZE_EXCEEDS_ALLOWED_LIMIT", "CAMPAIGN_SUSPENDED",
58
+ "FACEBOOK_ALLOWED_WINDOW_EXPIRED", "GMAIL_ADV_PROTECTION", "INSTAGRAM_ALLOWED_WINDOW_EXPIRED", "INVALID_CHARACTERS",
59
+ "INVALID_PHONE_NUMBER", "INVALID_RECIPIENT_ADDRESS", "LANDLINE_OR_UNREACHABLE_CARRIER", "MESSAGE_FILTERED",
60
+ "MMS_NOT_SUPPORTED_RECEIVING_PHONE_NUMBER", "NETWORK_ISSUE", "NO_MATCHING_RECIPIENT_FOUND", "POLICY_VIOLATION", "QUOTA_EXCEEDED",
61
+ "RATE_LIMIT", "RATE_LIMIT_ERROR", "RECIPIENT_BLOCKED_MESSAGES", "RECIPIENT_NOT_AVAILABLE", "SERVICE_UNAVAILABLE",
62
+ "TELCO_LANDLINE_OR_UNREACHABLE_CARRIER", "TELCO_MEDIA_EXCEEDS_MESSAGING_PROVIDER_SIZE_LIMIT",
63
+ "TELCO_MESSAGE_DELIVERY_UNKNOWN_DESTINATION_HANDSET", "TELCO_MESSAGE_FILTERED", "TELCO_MESSAGE_FROM_NUMBER_STILL_BEING_CONFIGURED",
64
+ "TELCO_MESSAGE_FROM_UNREGISTERED_NUMBER", "TELCO_UNKNOWN_ERROR", "TELCO_UNREACHABLE_DESTINATION_HANDSET", "TOO_MANY_REQUESTS",
65
+ "TOTAL_ATTACHMENTS_SIZE_EXCEEDS_ALLOWED_LIMIT", "UNEXPECTED_ERROR_RETRY_LATER", "UNKNOWN_FAILED_CODE", "UNSUPPORTED",
66
+ "UNSUPPORTED_MESSAGE_TYPE", "USER_RATE_LIMIT",
67
+ ]);
68
+
69
+ /** 5:1604 inboxSendMessageErrorMsgShown (`@wix/bi-logger-crm-data` v2, endpoint ''), for a chat
70
+ * send that failed and said so. RN's `errorReason` is the failed message's indication code, and
71
+ * RN reports a code it does not know as UNSUPPORTED (`getErrorIndicationFromCode`); a send that
72
+ * never left the device is NETWORK_ISSUE and a 429 is RATE_LIMIT. */
73
+ export function logChatSendError(input: { chatroomId: string; contactId?: string; error: unknown; offline: boolean }): void {
74
+ const code = wixErrorCode(input.error);
75
+ const errorReason = input.offline ? "NETWORK_ISSUE"
76
+ : ERROR_INDICATIONS.has(code) ? code
77
+ : wixErrorStatus(input.error) === 429 ? "RATE_LIMIT"
78
+ : "UNSUPPORTED";
79
+ logBi({
80
+ evid: 1604,
81
+ src: 5,
82
+ endpoint: "",
83
+ params: { origin: "native", chatroomId: input.chatroomId, ...(input.contactId ? { contact_id: input.contactId } : {}), errorReason },
84
+ });
85
+ }
@@ -39,6 +39,7 @@ import { hostedCheckoutOpener, hostedSitePageOpener, isHostedWorker } from "../_
39
39
  import { assertOrderMember, orderAccessDenied, orderMember, ownedOrderCache, type OrderMember } from "../_shared/member-orders.js";
40
40
  import { formatDateMedium, formatWeekdayDateTime } from "../_shared/engine-intl.js";
41
41
  import { copyParam, copyTemplate, stashCopy } from "../_shared/himi-copy.js";
42
+ import { logBi } from "../_shared/wix-bi.js";
42
43
 
43
44
  interface LineRow {
44
45
  id: string;
@@ -511,6 +512,19 @@ async function refreshOrderingFor(cart: WixCartV2): Promise<boolean> {
511
512
  }
512
513
  }
513
514
 
515
+ /** The restaurants member module's cart events (`@wix/bi-logger-olo-members-view`, src 61), sent once
516
+ * Wix confirmed the change: 61:910 cartRemoveDish for a dish that left the order, 61:909
517
+ * cartDishQuantitiesUpdate for a new quantity (wix-one-app-restaurants-member
518
+ * screens/DishScreen/useHooks.ts:153 and :170). `dishId` is the menu item, as RN's `itemId`. RN's
519
+ * restaurant defaults (restaurantId, locationGuid, oloSessionId) have no Himi source. A minus that
520
+ * empties the line removes it, so it is a removal here, where RN's stepper sends 909 at 0 first. */
521
+ function logDishChange(line: WixCartV2LineItem, deleted: boolean, delta: number, quantity: number): void {
522
+ const dishId = line.source?.catalogReference?.catalogItemId ?? "";
523
+ if (!dishId) return;
524
+ if (deleted) logBi({ evid: 910, src: 61, endpoint: "olo-members-view", params: { dishId } });
525
+ else logBi({ evid: 909, src: 61, endpoint: "olo-members-view", params: { dishId, action: delta < 0 ? "decrease" : "increase", quantity } });
526
+ }
527
+
514
528
  function changeQuantity(id: string, delta: number, remove = false): Promise<S> {
515
529
  // Actions can overlap. Serialize writes and calculate from Wix's current quantity,
516
530
  // so two rapid taps never both send the same absolute newQuantity.
@@ -530,6 +544,7 @@ function changeQuantity(id: string, delta: number, remove = false): Promise<S> {
530
544
  ? await removeLineItemsFromCurrentCartV2([id])
531
545
  : await updateLineItemsInCurrentCartV2([{ lineItemId: id, quantity: next }]);
532
546
  const cart = response.cart ?? await getCurrentCartV2();
547
+ if (isRestaurantLine(line)) logDishChange(line, deleted, delta, next);
533
548
  const hint = deleted ? copyParam("foodOrders.itemRemoved", "Removed from your order.") : "";
534
549
  // The write already landed: a failed ordering refresh must not hide the updated cart.
535
550
  const refreshFailed = await refreshOrderingFor(cart);
@@ -66242,7 +66242,8 @@ const SCREENS = runtimeSetting({
66242
66242
  "integrity": "",
66243
66243
  "contentType": "application/javascript+ts-bundle",
66244
66244
  "declaredCapabilities": [
66245
- "wix_api"
66245
+ "wix_api",
66246
+ "wix_platform"
66246
66247
  ],
66247
66248
  "minBinaryVersion": "0.1.0",
66248
66249
  "bundleVersion": "0.0.1"
@@ -0,0 +1,85 @@
1
+ // RN BI events whose fields exist only in a worker (epic #4973). The platform maps send every
2
+ // other RN event; these go through `wixPlatform.bi.log`, built inline with RN's own field names
3
+ // rather than by bundling a `@wix/bi-logger-*` package. The host owns every identity and common
4
+ // field (msid, uuid, installationId, contactId, _lv, ...), so none is named here.
5
+ import { bi, type BiLogEvent } from "@himalaya/wix-platform";
6
+
7
+ /** Sends one event without waiting for it and never throws: BI must not change a screen. A
8
+ * screen whose descriptor does not declare `wix_platform` is refused by the host, which is
9
+ * swallowed here like any other BI failure. */
10
+ export function logBi(event: BiLogEvent): void {
11
+ try {
12
+ void Promise.resolve(bi.log(event)).catch(() => undefined);
13
+ } catch {
14
+ /* BI is best-effort */
15
+ }
16
+ }
17
+
18
+ /** The HTTP status a Wix SDK error carries (`HTTP 429: ...`, or a `status` field), else 0. */
19
+ export function wixErrorStatus(error: unknown): number {
20
+ const own = Number((error as { status?: unknown; statusCode?: unknown } | null)?.status ?? (error as { statusCode?: unknown } | null)?.statusCode);
21
+ if (Number.isFinite(own) && own > 0) return own;
22
+ const match = /\bHTTP (\d{3})\b/.exec(String((error as Error | null)?.message ?? error ?? ""));
23
+ return match ? Number(match[1]) : 0;
24
+ }
25
+
26
+ function applicationErrorCode(body: unknown): string {
27
+ const o = body as { details?: { applicationError?: { code?: unknown } }; applicationError?: { code?: unknown }; code?: unknown } | null;
28
+ const code = o?.details?.applicationError?.code ?? o?.applicationError?.code ?? o?.code;
29
+ return typeof code === "string" ? code : "";
30
+ }
31
+
32
+ /** The code both native bridges put in an application error's message: `HTTP 400 [CODE]: description`
33
+ * (iOS JSWorker.swift `WixApiCapability.Error.application`, Android WebViewJSWorker.kt `Error.Application`). */
34
+ const BRIDGE_APPLICATION_CODE = /\bHTTP \d{3} \[([A-Za-z0-9_.:-]+)\]/;
35
+
36
+ /** The Wix application error code of a failed call (RN's `serializeError(e).code`): read from the
37
+ * error itself, else from the `[CODE]` the native bridges put after `HTTP <status> `, else from the
38
+ * JSON body after `HTTP <status>: ` (the bridges' raw-status arm and the web host's wixCall). ""
39
+ * when there is none. */
40
+ export function wixErrorCode(error: unknown): string {
41
+ const own = applicationErrorCode(error);
42
+ if (own) return own;
43
+ const message = String((error as Error | null)?.message ?? error ?? "");
44
+ const bracketed = BRIDGE_APPLICATION_CODE.exec(message);
45
+ if (bracketed) return bracketed[1];
46
+ const start = message.indexOf("{");
47
+ if (start < 0) return "";
48
+ try {
49
+ return applicationErrorCode(JSON.parse(message.slice(start)));
50
+ } catch {
51
+ return "";
52
+ }
53
+ }
54
+
55
+ // RN's `ErrorIndicationType` (mobile-apps-inbox services/errorIndications/errorIndications.type.ts).
56
+ const ERROR_INDICATIONS = new Set([
57
+ "ACCESS_TOKEN_EXPIRED", "ALLOWED_MESSAGING_TIME_WINDOW_EXPIRED", "ATTACHMENT_SIZE_EXCEEDS_ALLOWED_LIMIT", "CAMPAIGN_SUSPENDED",
58
+ "FACEBOOK_ALLOWED_WINDOW_EXPIRED", "GMAIL_ADV_PROTECTION", "INSTAGRAM_ALLOWED_WINDOW_EXPIRED", "INVALID_CHARACTERS",
59
+ "INVALID_PHONE_NUMBER", "INVALID_RECIPIENT_ADDRESS", "LANDLINE_OR_UNREACHABLE_CARRIER", "MESSAGE_FILTERED",
60
+ "MMS_NOT_SUPPORTED_RECEIVING_PHONE_NUMBER", "NETWORK_ISSUE", "NO_MATCHING_RECIPIENT_FOUND", "POLICY_VIOLATION", "QUOTA_EXCEEDED",
61
+ "RATE_LIMIT", "RATE_LIMIT_ERROR", "RECIPIENT_BLOCKED_MESSAGES", "RECIPIENT_NOT_AVAILABLE", "SERVICE_UNAVAILABLE",
62
+ "TELCO_LANDLINE_OR_UNREACHABLE_CARRIER", "TELCO_MEDIA_EXCEEDS_MESSAGING_PROVIDER_SIZE_LIMIT",
63
+ "TELCO_MESSAGE_DELIVERY_UNKNOWN_DESTINATION_HANDSET", "TELCO_MESSAGE_FILTERED", "TELCO_MESSAGE_FROM_NUMBER_STILL_BEING_CONFIGURED",
64
+ "TELCO_MESSAGE_FROM_UNREGISTERED_NUMBER", "TELCO_UNKNOWN_ERROR", "TELCO_UNREACHABLE_DESTINATION_HANDSET", "TOO_MANY_REQUESTS",
65
+ "TOTAL_ATTACHMENTS_SIZE_EXCEEDS_ALLOWED_LIMIT", "UNEXPECTED_ERROR_RETRY_LATER", "UNKNOWN_FAILED_CODE", "UNSUPPORTED",
66
+ "UNSUPPORTED_MESSAGE_TYPE", "USER_RATE_LIMIT",
67
+ ]);
68
+
69
+ /** 5:1604 inboxSendMessageErrorMsgShown (`@wix/bi-logger-crm-data` v2, endpoint ''), for a chat
70
+ * send that failed and said so. RN's `errorReason` is the failed message's indication code, and
71
+ * RN reports a code it does not know as UNSUPPORTED (`getErrorIndicationFromCode`); a send that
72
+ * never left the device is NETWORK_ISSUE and a 429 is RATE_LIMIT. */
73
+ export function logChatSendError(input: { chatroomId: string; contactId?: string; error: unknown; offline: boolean }): void {
74
+ const code = wixErrorCode(input.error);
75
+ const errorReason = input.offline ? "NETWORK_ISSUE"
76
+ : ERROR_INDICATIONS.has(code) ? code
77
+ : wixErrorStatus(input.error) === 429 ? "RATE_LIMIT"
78
+ : "UNSUPPORTED";
79
+ logBi({
80
+ evid: 1604,
81
+ src: 5,
82
+ endpoint: "",
83
+ params: { origin: "native", chatroomId: input.chatroomId, ...(input.contactId ? { contact_id: input.contactId } : {}), errorReason },
84
+ });
85
+ }
@@ -22,7 +22,8 @@ import { defineService, navigate, type NavDirective, type PollDirective, type St
22
22
  import { getMessages, sendChatMessage, listChatrooms, markChatroomRead, getChatToken, type ChatMessage } from "@himalaya/wix-chat-web";
23
23
  import { formatMonthDayTime } from "../_shared/engine-intl.js";
24
24
  import { presence, presenceAfterError, detailInputId, type PresenceFlags } from "../_shared/detail-presence.js";
25
- import { ownerLoadError, ownerWriteError, writeMayHaveLanded } from "../_shared/owner-load-error.js";
25
+ import { isOfflineFailure, ownerLoadError, ownerWriteError, writeMayHaveLanded } from "../_shared/owner-load-error.js";
26
+ import { logChatSendError } from "../_shared/wix-bi.js";
26
27
  import { stashCopy, copyParam } from "../_shared/himi-copy.js";
27
28
  import { chatRealtimeConfig, createReloadGate, createSendIntents, createVisitToken, liveDirectives, postWithVisitToken, liveFallback, type ChatLiveMode, type ChatRealtimeConfig } from "../_shared/chat-live.js";
28
29
 
@@ -280,7 +281,10 @@ const svc = defineService<ThreadState, {
280
281
  } catch (e) {
281
282
  // The draft stays: the owner should not have to type it again. A send that may
282
283
  // have landed says so, so a retry does not post it twice unknowingly.
283
- return { ...live(), sendHint: writeMayHaveLanded(e) ? ownerWriteError(e) : `${copyParam("ownerInbox.sendFailed", "Couldn’t send")} — ${ownerWriteError(e)}` };
284
+ if (writeMayHaveLanded(e)) return { ...live(), sendHint: ownerWriteError(e) };
285
+ const { id, kind } = input();
286
+ logChatSendError({ chatroomId: s.chatroomId, contactId: kind === "contact" ? id : "", error: e, offline: isOfflineFailure(e) });
287
+ return { ...live(), sendHint: `${copyParam("ownerInbox.sendFailed", "Couldn’t send")} — ${ownerWriteError(e)}` };
284
288
  }
285
289
  // Clear the composer only if it still holds what was sent — the owner may already be
286
290
  // typing the next message — judged on the state AFTER the re-read's await.
@@ -23603,6 +23603,7 @@ const TEMPLATED: { pattern: string; display: string; liveSeed?: LiveSeed; static
23603
23603
  "share",
23604
23604
  "local_database",
23605
23605
  "open_url",
23606
+ "wix_platform",
23606
23607
  "iap",
23607
23608
  "app_info"
23608
23609
  ],
@@ -0,0 +1,85 @@
1
+ // RN BI events whose fields exist only in a worker (epic #4973). The platform maps send every
2
+ // other RN event; these go through `wixPlatform.bi.log`, built inline with RN's own field names
3
+ // rather than by bundling a `@wix/bi-logger-*` package. The host owns every identity and common
4
+ // field (msid, uuid, installationId, contactId, _lv, ...), so none is named here.
5
+ import { bi, type BiLogEvent } from "@himalaya/wix-platform";
6
+
7
+ /** Sends one event without waiting for it and never throws: BI must not change a screen. A
8
+ * screen whose descriptor does not declare `wix_platform` is refused by the host, which is
9
+ * swallowed here like any other BI failure. */
10
+ export function logBi(event: BiLogEvent): void {
11
+ try {
12
+ void Promise.resolve(bi.log(event)).catch(() => undefined);
13
+ } catch {
14
+ /* BI is best-effort */
15
+ }
16
+ }
17
+
18
+ /** The HTTP status a Wix SDK error carries (`HTTP 429: ...`, or a `status` field), else 0. */
19
+ export function wixErrorStatus(error: unknown): number {
20
+ const own = Number((error as { status?: unknown; statusCode?: unknown } | null)?.status ?? (error as { statusCode?: unknown } | null)?.statusCode);
21
+ if (Number.isFinite(own) && own > 0) return own;
22
+ const match = /\bHTTP (\d{3})\b/.exec(String((error as Error | null)?.message ?? error ?? ""));
23
+ return match ? Number(match[1]) : 0;
24
+ }
25
+
26
+ function applicationErrorCode(body: unknown): string {
27
+ const o = body as { details?: { applicationError?: { code?: unknown } }; applicationError?: { code?: unknown }; code?: unknown } | null;
28
+ const code = o?.details?.applicationError?.code ?? o?.applicationError?.code ?? o?.code;
29
+ return typeof code === "string" ? code : "";
30
+ }
31
+
32
+ /** The code both native bridges put in an application error's message: `HTTP 400 [CODE]: description`
33
+ * (iOS JSWorker.swift `WixApiCapability.Error.application`, Android WebViewJSWorker.kt `Error.Application`). */
34
+ const BRIDGE_APPLICATION_CODE = /\bHTTP \d{3} \[([A-Za-z0-9_.:-]+)\]/;
35
+
36
+ /** The Wix application error code of a failed call (RN's `serializeError(e).code`): read from the
37
+ * error itself, else from the `[CODE]` the native bridges put after `HTTP <status> `, else from the
38
+ * JSON body after `HTTP <status>: ` (the bridges' raw-status arm and the web host's wixCall). ""
39
+ * when there is none. */
40
+ export function wixErrorCode(error: unknown): string {
41
+ const own = applicationErrorCode(error);
42
+ if (own) return own;
43
+ const message = String((error as Error | null)?.message ?? error ?? "");
44
+ const bracketed = BRIDGE_APPLICATION_CODE.exec(message);
45
+ if (bracketed) return bracketed[1];
46
+ const start = message.indexOf("{");
47
+ if (start < 0) return "";
48
+ try {
49
+ return applicationErrorCode(JSON.parse(message.slice(start)));
50
+ } catch {
51
+ return "";
52
+ }
53
+ }
54
+
55
+ // RN's `ErrorIndicationType` (mobile-apps-inbox services/errorIndications/errorIndications.type.ts).
56
+ const ERROR_INDICATIONS = new Set([
57
+ "ACCESS_TOKEN_EXPIRED", "ALLOWED_MESSAGING_TIME_WINDOW_EXPIRED", "ATTACHMENT_SIZE_EXCEEDS_ALLOWED_LIMIT", "CAMPAIGN_SUSPENDED",
58
+ "FACEBOOK_ALLOWED_WINDOW_EXPIRED", "GMAIL_ADV_PROTECTION", "INSTAGRAM_ALLOWED_WINDOW_EXPIRED", "INVALID_CHARACTERS",
59
+ "INVALID_PHONE_NUMBER", "INVALID_RECIPIENT_ADDRESS", "LANDLINE_OR_UNREACHABLE_CARRIER", "MESSAGE_FILTERED",
60
+ "MMS_NOT_SUPPORTED_RECEIVING_PHONE_NUMBER", "NETWORK_ISSUE", "NO_MATCHING_RECIPIENT_FOUND", "POLICY_VIOLATION", "QUOTA_EXCEEDED",
61
+ "RATE_LIMIT", "RATE_LIMIT_ERROR", "RECIPIENT_BLOCKED_MESSAGES", "RECIPIENT_NOT_AVAILABLE", "SERVICE_UNAVAILABLE",
62
+ "TELCO_LANDLINE_OR_UNREACHABLE_CARRIER", "TELCO_MEDIA_EXCEEDS_MESSAGING_PROVIDER_SIZE_LIMIT",
63
+ "TELCO_MESSAGE_DELIVERY_UNKNOWN_DESTINATION_HANDSET", "TELCO_MESSAGE_FILTERED", "TELCO_MESSAGE_FROM_NUMBER_STILL_BEING_CONFIGURED",
64
+ "TELCO_MESSAGE_FROM_UNREGISTERED_NUMBER", "TELCO_UNKNOWN_ERROR", "TELCO_UNREACHABLE_DESTINATION_HANDSET", "TOO_MANY_REQUESTS",
65
+ "TOTAL_ATTACHMENTS_SIZE_EXCEEDS_ALLOWED_LIMIT", "UNEXPECTED_ERROR_RETRY_LATER", "UNKNOWN_FAILED_CODE", "UNSUPPORTED",
66
+ "UNSUPPORTED_MESSAGE_TYPE", "USER_RATE_LIMIT",
67
+ ]);
68
+
69
+ /** 5:1604 inboxSendMessageErrorMsgShown (`@wix/bi-logger-crm-data` v2, endpoint ''), for a chat
70
+ * send that failed and said so. RN's `errorReason` is the failed message's indication code, and
71
+ * RN reports a code it does not know as UNSUPPORTED (`getErrorIndicationFromCode`); a send that
72
+ * never left the device is NETWORK_ISSUE and a 429 is RATE_LIMIT. */
73
+ export function logChatSendError(input: { chatroomId: string; contactId?: string; error: unknown; offline: boolean }): void {
74
+ const code = wixErrorCode(input.error);
75
+ const errorReason = input.offline ? "NETWORK_ISSUE"
76
+ : ERROR_INDICATIONS.has(code) ? code
77
+ : wixErrorStatus(input.error) === 429 ? "RATE_LIMIT"
78
+ : "UNSUPPORTED";
79
+ logBi({
80
+ evid: 1604,
81
+ src: 5,
82
+ endpoint: "",
83
+ params: { origin: "native", chatroomId: input.chatroomId, ...(input.contactId ? { contact_id: input.contactId } : {}), errorReason },
84
+ });
85
+ }
@@ -11,6 +11,7 @@ import { createRedirectSession } from "@himalaya/wix-redirects";
11
11
  import { isPaymentSetupFailure, payCashierOrder } from "@himalaya/checkout";
12
12
  import { hostedCheckoutOpener, isHostedWorker } from "../_shared/hosted-checkout.js";
13
13
  import { formatCurrency } from "../_shared/engine-intl.js";
14
+ import { logBi, wixErrorCode } from "../_shared/wix-bi.js";
14
15
 
15
16
  /** Wix Stores appDefId — the vertical that owns a cart/ecom order, and therefore the
16
17
  * `appId` its cashier order is paid under. (Same constant Wix's own tooling uses.) */
@@ -458,6 +459,14 @@ const svc = defineService<State, {
458
459
  const mayHaveLanded = added || writeMayHaveLanded(error);
459
460
  const refreshed = mayHaveLanded ? await refresh(state).catch(() => null) : null;
460
461
  if (refreshed?.appliedCode === code) return derive({ ...refreshed, promoBusy: false, promoCode: "", promoError: "" });
462
+ // 130:117 couponApplyingFailed (ecom-platform bi/storefront.ts:448, sent from cartActions.ts:345 when
463
+ // the add-coupon call throws). errorCode is RN's serializeError(e).code, the Wix application error code.
464
+ // Only the add-coupon call itself: once it answered, the coupon is on the cart, and a later step that
465
+ // throws (the cart refresh) is not a coupon that failed to apply.
466
+ if (!added) {
467
+ const errorCode = wixErrorCode(error);
468
+ logBi({ evid: 117, src: 130, endpoint: "ec-site", params: { origin: "checkout", couponCode: code, ...(errorCode ? { errorCode } : {}) } });
469
+ }
461
470
  return derive({ ...state, promoBusy: false, promoError: mayHaveLanded
462
471
  ? copyParam("cart.promoUnconfirmed", "Could not confirm the promo code. Refresh your cart.")
463
472
  : isOfflineFailure(error)
@@ -17,6 +17,7 @@ import { getStoreProduct, plainText, productImage, productPrice, wixMediaUrl, pr
17
17
  import { cleanTitle } from "../_shared/himi-text.js";
18
18
  import { stashCopy, copyParam, copyTemplate } from "../_shared/himi-copy.js";
19
19
  import { isBridgeUnavailable } from "../_shared/owner-load-error.js";
20
+ import { logBi } from "../_shared/wix-bi.js";
20
21
  import { isProductSaved, toggleSavedProduct } from "../_shared/himi-store-saved.js";
21
22
  import { openRichLink } from "../_shared/rich-content-link.js";
22
23
  import { descriptionBody } from "../_shared/rich-body.js";
@@ -129,6 +130,18 @@ function outOfStockPick(groups: StoreOption[], selection: StoreOptionSelection):
129
130
  }
130
131
 
131
132
  /** What to say under the picker: the groups still unchosen, else the choice made. */
133
+ /** 10:183 addToCartError (wix-store-merchant-app features/front/bi/index.ts:117, sent from
134
+ * ProductViewScreen when Add to cart fails validation). RN's `field` joins the failed checks by
135
+ * its own names: a required option left unchosen is `product_options`, a chosen combination with
136
+ * no stock left is `quantity`. Himi has no custom text fields, so `custom_field` never appears. */
137
+ function logAddToCartError(productId: string, groups: StoreOption[], selection: StoreOptionSelection): void {
138
+ const field = [
139
+ ...(groups.some((g) => !selection[g.id]) ? ["product_options"] : []),
140
+ ...(outOfStockPick(groups, selection) ? ["quantity"] : []),
141
+ ].join(",");
142
+ if (field) logBi({ evid: 183, src: 10, endpoint: "ec-sf", params: { productId, message: "validation error", field } });
143
+ }
144
+
132
145
  function optionsHint(groups: StoreOption[], selection: StoreOptionSelection): string {
133
146
  const missing = groups.filter((g) => !selection[g.id]).map((g) => g.name);
134
147
  if (!missing.length) {
@@ -792,6 +805,7 @@ const svc = onlineService<S, {
792
805
  if (s.adding) return s;
793
806
  // Missing choices show field errors; unavailable products still fail closed.
794
807
  if (s.optionsIncomplete) {
808
+ if (!s.optionsUnknown) logAddToCartError(id, s.optionGroups, s.selection);
795
809
  // With no groups in hand there is nothing for `optionsHint` to name, so the
796
810
  // offline case needs its own reason rather than an empty string.
797
811
  return derive({ ...s, showOptionErrors: true, optionValidationTarget: s.optionGroups.find(g => !s.selection[g.id])?.id ?? "", optionValidationRequest: (s.optionValidationRequest || 0) + 1, cartHint: s.optionsUnknown
@@ -66078,7 +66078,8 @@ const SCREENS = runtimeSetting({
66078
66078
  "integrity": "",
66079
66079
  "contentType": "application/javascript+ts-bundle",
66080
66080
  "declaredCapabilities": [
66081
- "wix_api"
66081
+ "wix_api",
66082
+ "wix_platform"
66082
66083
  ],
66083
66084
  "minBinaryVersion": "0.1.0",
66084
66085
  "bundleVersion": "0.0.1"
@@ -0,0 +1,85 @@
1
+ // RN BI events whose fields exist only in a worker (epic #4973). The platform maps send every
2
+ // other RN event; these go through `wixPlatform.bi.log`, built inline with RN's own field names
3
+ // rather than by bundling a `@wix/bi-logger-*` package. The host owns every identity and common
4
+ // field (msid, uuid, installationId, contactId, _lv, ...), so none is named here.
5
+ import { bi, type BiLogEvent } from "@himalaya/wix-platform";
6
+
7
+ /** Sends one event without waiting for it and never throws: BI must not change a screen. A
8
+ * screen whose descriptor does not declare `wix_platform` is refused by the host, which is
9
+ * swallowed here like any other BI failure. */
10
+ export function logBi(event: BiLogEvent): void {
11
+ try {
12
+ void Promise.resolve(bi.log(event)).catch(() => undefined);
13
+ } catch {
14
+ /* BI is best-effort */
15
+ }
16
+ }
17
+
18
+ /** The HTTP status a Wix SDK error carries (`HTTP 429: ...`, or a `status` field), else 0. */
19
+ export function wixErrorStatus(error: unknown): number {
20
+ const own = Number((error as { status?: unknown; statusCode?: unknown } | null)?.status ?? (error as { statusCode?: unknown } | null)?.statusCode);
21
+ if (Number.isFinite(own) && own > 0) return own;
22
+ const match = /\bHTTP (\d{3})\b/.exec(String((error as Error | null)?.message ?? error ?? ""));
23
+ return match ? Number(match[1]) : 0;
24
+ }
25
+
26
+ function applicationErrorCode(body: unknown): string {
27
+ const o = body as { details?: { applicationError?: { code?: unknown } }; applicationError?: { code?: unknown }; code?: unknown } | null;
28
+ const code = o?.details?.applicationError?.code ?? o?.applicationError?.code ?? o?.code;
29
+ return typeof code === "string" ? code : "";
30
+ }
31
+
32
+ /** The code both native bridges put in an application error's message: `HTTP 400 [CODE]: description`
33
+ * (iOS JSWorker.swift `WixApiCapability.Error.application`, Android WebViewJSWorker.kt `Error.Application`). */
34
+ const BRIDGE_APPLICATION_CODE = /\bHTTP \d{3} \[([A-Za-z0-9_.:-]+)\]/;
35
+
36
+ /** The Wix application error code of a failed call (RN's `serializeError(e).code`): read from the
37
+ * error itself, else from the `[CODE]` the native bridges put after `HTTP <status> `, else from the
38
+ * JSON body after `HTTP <status>: ` (the bridges' raw-status arm and the web host's wixCall). ""
39
+ * when there is none. */
40
+ export function wixErrorCode(error: unknown): string {
41
+ const own = applicationErrorCode(error);
42
+ if (own) return own;
43
+ const message = String((error as Error | null)?.message ?? error ?? "");
44
+ const bracketed = BRIDGE_APPLICATION_CODE.exec(message);
45
+ if (bracketed) return bracketed[1];
46
+ const start = message.indexOf("{");
47
+ if (start < 0) return "";
48
+ try {
49
+ return applicationErrorCode(JSON.parse(message.slice(start)));
50
+ } catch {
51
+ return "";
52
+ }
53
+ }
54
+
55
+ // RN's `ErrorIndicationType` (mobile-apps-inbox services/errorIndications/errorIndications.type.ts).
56
+ const ERROR_INDICATIONS = new Set([
57
+ "ACCESS_TOKEN_EXPIRED", "ALLOWED_MESSAGING_TIME_WINDOW_EXPIRED", "ATTACHMENT_SIZE_EXCEEDS_ALLOWED_LIMIT", "CAMPAIGN_SUSPENDED",
58
+ "FACEBOOK_ALLOWED_WINDOW_EXPIRED", "GMAIL_ADV_PROTECTION", "INSTAGRAM_ALLOWED_WINDOW_EXPIRED", "INVALID_CHARACTERS",
59
+ "INVALID_PHONE_NUMBER", "INVALID_RECIPIENT_ADDRESS", "LANDLINE_OR_UNREACHABLE_CARRIER", "MESSAGE_FILTERED",
60
+ "MMS_NOT_SUPPORTED_RECEIVING_PHONE_NUMBER", "NETWORK_ISSUE", "NO_MATCHING_RECIPIENT_FOUND", "POLICY_VIOLATION", "QUOTA_EXCEEDED",
61
+ "RATE_LIMIT", "RATE_LIMIT_ERROR", "RECIPIENT_BLOCKED_MESSAGES", "RECIPIENT_NOT_AVAILABLE", "SERVICE_UNAVAILABLE",
62
+ "TELCO_LANDLINE_OR_UNREACHABLE_CARRIER", "TELCO_MEDIA_EXCEEDS_MESSAGING_PROVIDER_SIZE_LIMIT",
63
+ "TELCO_MESSAGE_DELIVERY_UNKNOWN_DESTINATION_HANDSET", "TELCO_MESSAGE_FILTERED", "TELCO_MESSAGE_FROM_NUMBER_STILL_BEING_CONFIGURED",
64
+ "TELCO_MESSAGE_FROM_UNREGISTERED_NUMBER", "TELCO_UNKNOWN_ERROR", "TELCO_UNREACHABLE_DESTINATION_HANDSET", "TOO_MANY_REQUESTS",
65
+ "TOTAL_ATTACHMENTS_SIZE_EXCEEDS_ALLOWED_LIMIT", "UNEXPECTED_ERROR_RETRY_LATER", "UNKNOWN_FAILED_CODE", "UNSUPPORTED",
66
+ "UNSUPPORTED_MESSAGE_TYPE", "USER_RATE_LIMIT",
67
+ ]);
68
+
69
+ /** 5:1604 inboxSendMessageErrorMsgShown (`@wix/bi-logger-crm-data` v2, endpoint ''), for a chat
70
+ * send that failed and said so. RN's `errorReason` is the failed message's indication code, and
71
+ * RN reports a code it does not know as UNSUPPORTED (`getErrorIndicationFromCode`); a send that
72
+ * never left the device is NETWORK_ISSUE and a 429 is RATE_LIMIT. */
73
+ export function logChatSendError(input: { chatroomId: string; contactId?: string; error: unknown; offline: boolean }): void {
74
+ const code = wixErrorCode(input.error);
75
+ const errorReason = input.offline ? "NETWORK_ISSUE"
76
+ : ERROR_INDICATIONS.has(code) ? code
77
+ : wixErrorStatus(input.error) === 429 ? "RATE_LIMIT"
78
+ : "UNSUPPORTED";
79
+ logBi({
80
+ evid: 1604,
81
+ src: 5,
82
+ endpoint: "",
83
+ params: { origin: "native", chatroomId: input.chatroomId, ...(input.contactId ? { contact_id: input.contactId } : {}), errorReason },
84
+ });
85
+ }
@@ -22,7 +22,8 @@ import { defineService, navigate, type NavDirective, type PollDirective, type St
22
22
  import { getMessages, sendChatMessage, listChatrooms, markChatroomRead, getChatToken, type ChatMessage } from "@himalaya/wix-chat-web";
23
23
  import { formatMonthDayTime } from "../_shared/engine-intl.js";
24
24
  import { presence, presenceAfterError, detailInputId, type PresenceFlags } from "../_shared/detail-presence.js";
25
- import { ownerLoadError, ownerWriteError, writeMayHaveLanded } from "../_shared/owner-load-error.js";
25
+ import { isOfflineFailure, ownerLoadError, ownerWriteError, writeMayHaveLanded } from "../_shared/owner-load-error.js";
26
+ import { logChatSendError } from "../_shared/wix-bi.js";
26
27
  import { stashCopy, copyParam } from "../_shared/himi-copy.js";
27
28
  import { chatRealtimeConfig, createReloadGate, createSendIntents, createVisitToken, liveDirectives, postWithVisitToken, liveFallback, type ChatLiveMode, type ChatRealtimeConfig } from "../_shared/chat-live.js";
28
29
 
@@ -280,7 +281,10 @@ const svc = defineService<ThreadState, {
280
281
  } catch (e) {
281
282
  // The draft stays: the owner should not have to type it again. A send that may
282
283
  // have landed says so, so a retry does not post it twice unknowingly.
283
- return { ...live(), sendHint: writeMayHaveLanded(e) ? ownerWriteError(e) : `${copyParam("ownerInbox.sendFailed", "Couldn’t send")} — ${ownerWriteError(e)}` };
284
+ if (writeMayHaveLanded(e)) return { ...live(), sendHint: ownerWriteError(e) };
285
+ const { id, kind } = input();
286
+ logChatSendError({ chatroomId: s.chatroomId, contactId: kind === "contact" ? id : "", error: e, offline: isOfflineFailure(e) });
287
+ return { ...live(), sendHint: `${copyParam("ownerInbox.sendFailed", "Couldn’t send")} — ${ownerWriteError(e)}` };
284
288
  }
285
289
  // Clear the composer only if it still holds what was sent — the owner may already be
286
290
  // typing the next message — judged on the state AFTER the re-read's await.
@@ -13658,7 +13658,8 @@ const SCREENS = runtimeSetting({
13658
13658
  "declaredCapabilities": [
13659
13659
  "wix_api",
13660
13660
  "wix_chat",
13661
- "open_url"
13661
+ "open_url",
13662
+ "wix_platform"
13662
13663
  ],
13663
13664
  "minBinaryVersion": "0.1.0",
13664
13665
  "bundleVersion": "0.1.0"
@@ -0,0 +1,85 @@
1
+ // RN BI events whose fields exist only in a worker (epic #4973). The platform maps send every
2
+ // other RN event; these go through `wixPlatform.bi.log`, built inline with RN's own field names
3
+ // rather than by bundling a `@wix/bi-logger-*` package. The host owns every identity and common
4
+ // field (msid, uuid, installationId, contactId, _lv, ...), so none is named here.
5
+ import { bi, type BiLogEvent } from "@himalaya/wix-platform";
6
+
7
+ /** Sends one event without waiting for it and never throws: BI must not change a screen. A
8
+ * screen whose descriptor does not declare `wix_platform` is refused by the host, which is
9
+ * swallowed here like any other BI failure. */
10
+ export function logBi(event: BiLogEvent): void {
11
+ try {
12
+ void Promise.resolve(bi.log(event)).catch(() => undefined);
13
+ } catch {
14
+ /* BI is best-effort */
15
+ }
16
+ }
17
+
18
+ /** The HTTP status a Wix SDK error carries (`HTTP 429: ...`, or a `status` field), else 0. */
19
+ export function wixErrorStatus(error: unknown): number {
20
+ const own = Number((error as { status?: unknown; statusCode?: unknown } | null)?.status ?? (error as { statusCode?: unknown } | null)?.statusCode);
21
+ if (Number.isFinite(own) && own > 0) return own;
22
+ const match = /\bHTTP (\d{3})\b/.exec(String((error as Error | null)?.message ?? error ?? ""));
23
+ return match ? Number(match[1]) : 0;
24
+ }
25
+
26
+ function applicationErrorCode(body: unknown): string {
27
+ const o = body as { details?: { applicationError?: { code?: unknown } }; applicationError?: { code?: unknown }; code?: unknown } | null;
28
+ const code = o?.details?.applicationError?.code ?? o?.applicationError?.code ?? o?.code;
29
+ return typeof code === "string" ? code : "";
30
+ }
31
+
32
+ /** The code both native bridges put in an application error's message: `HTTP 400 [CODE]: description`
33
+ * (iOS JSWorker.swift `WixApiCapability.Error.application`, Android WebViewJSWorker.kt `Error.Application`). */
34
+ const BRIDGE_APPLICATION_CODE = /\bHTTP \d{3} \[([A-Za-z0-9_.:-]+)\]/;
35
+
36
+ /** The Wix application error code of a failed call (RN's `serializeError(e).code`): read from the
37
+ * error itself, else from the `[CODE]` the native bridges put after `HTTP <status> `, else from the
38
+ * JSON body after `HTTP <status>: ` (the bridges' raw-status arm and the web host's wixCall). ""
39
+ * when there is none. */
40
+ export function wixErrorCode(error: unknown): string {
41
+ const own = applicationErrorCode(error);
42
+ if (own) return own;
43
+ const message = String((error as Error | null)?.message ?? error ?? "");
44
+ const bracketed = BRIDGE_APPLICATION_CODE.exec(message);
45
+ if (bracketed) return bracketed[1];
46
+ const start = message.indexOf("{");
47
+ if (start < 0) return "";
48
+ try {
49
+ return applicationErrorCode(JSON.parse(message.slice(start)));
50
+ } catch {
51
+ return "";
52
+ }
53
+ }
54
+
55
+ // RN's `ErrorIndicationType` (mobile-apps-inbox services/errorIndications/errorIndications.type.ts).
56
+ const ERROR_INDICATIONS = new Set([
57
+ "ACCESS_TOKEN_EXPIRED", "ALLOWED_MESSAGING_TIME_WINDOW_EXPIRED", "ATTACHMENT_SIZE_EXCEEDS_ALLOWED_LIMIT", "CAMPAIGN_SUSPENDED",
58
+ "FACEBOOK_ALLOWED_WINDOW_EXPIRED", "GMAIL_ADV_PROTECTION", "INSTAGRAM_ALLOWED_WINDOW_EXPIRED", "INVALID_CHARACTERS",
59
+ "INVALID_PHONE_NUMBER", "INVALID_RECIPIENT_ADDRESS", "LANDLINE_OR_UNREACHABLE_CARRIER", "MESSAGE_FILTERED",
60
+ "MMS_NOT_SUPPORTED_RECEIVING_PHONE_NUMBER", "NETWORK_ISSUE", "NO_MATCHING_RECIPIENT_FOUND", "POLICY_VIOLATION", "QUOTA_EXCEEDED",
61
+ "RATE_LIMIT", "RATE_LIMIT_ERROR", "RECIPIENT_BLOCKED_MESSAGES", "RECIPIENT_NOT_AVAILABLE", "SERVICE_UNAVAILABLE",
62
+ "TELCO_LANDLINE_OR_UNREACHABLE_CARRIER", "TELCO_MEDIA_EXCEEDS_MESSAGING_PROVIDER_SIZE_LIMIT",
63
+ "TELCO_MESSAGE_DELIVERY_UNKNOWN_DESTINATION_HANDSET", "TELCO_MESSAGE_FILTERED", "TELCO_MESSAGE_FROM_NUMBER_STILL_BEING_CONFIGURED",
64
+ "TELCO_MESSAGE_FROM_UNREGISTERED_NUMBER", "TELCO_UNKNOWN_ERROR", "TELCO_UNREACHABLE_DESTINATION_HANDSET", "TOO_MANY_REQUESTS",
65
+ "TOTAL_ATTACHMENTS_SIZE_EXCEEDS_ALLOWED_LIMIT", "UNEXPECTED_ERROR_RETRY_LATER", "UNKNOWN_FAILED_CODE", "UNSUPPORTED",
66
+ "UNSUPPORTED_MESSAGE_TYPE", "USER_RATE_LIMIT",
67
+ ]);
68
+
69
+ /** 5:1604 inboxSendMessageErrorMsgShown (`@wix/bi-logger-crm-data` v2, endpoint ''), for a chat
70
+ * send that failed and said so. RN's `errorReason` is the failed message's indication code, and
71
+ * RN reports a code it does not know as UNSUPPORTED (`getErrorIndicationFromCode`); a send that
72
+ * never left the device is NETWORK_ISSUE and a 429 is RATE_LIMIT. */
73
+ export function logChatSendError(input: { chatroomId: string; contactId?: string; error: unknown; offline: boolean }): void {
74
+ const code = wixErrorCode(input.error);
75
+ const errorReason = input.offline ? "NETWORK_ISSUE"
76
+ : ERROR_INDICATIONS.has(code) ? code
77
+ : wixErrorStatus(input.error) === 429 ? "RATE_LIMIT"
78
+ : "UNSUPPORTED";
79
+ logBi({
80
+ evid: 1604,
81
+ src: 5,
82
+ endpoint: "",
83
+ params: { origin: "native", chatroomId: input.chatroomId, ...(input.contactId ? { contact_id: input.contactId } : {}), errorReason },
84
+ });
85
+ }