@wix/himalaya-cli 0.1808.0 → 0.1810.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.
@@ -15,6 +15,11 @@ export interface HostIdentitySource {
15
15
  * when the host installed no session source: iOS publishes the bridge (`identityBound`) to
16
16
  * every worker that has `wix_api`, with or without one. */
17
17
  site(): string | null;
18
+ /** Whether the host's session clock has settled: the native runtime has restored (or confirmed) who is signed in,
19
+ * so `current().kind` is final rather than the provisional `signedOut` a clock reports while it is still restoring.
20
+ * True when the host has no authenticated clock: none published, or the web host's stub (`identityBound: false`, never
21
+ * ready). Nothing restores there, so its first answer stands. */
22
+ settled(): boolean;
18
23
  }
19
24
  export interface HostSessionProvider extends SessionProvider, HostIdentitySource {
20
25
  }
@@ -25,6 +30,9 @@ export declare function createHostSession(source: {
25
30
  identityBound: boolean;
26
31
  current(): unknown;
27
32
  subscribe(listener: () => void): () => void;
33
+ /** Whether the host has (or is about to bind) a session clock to wait for; read on every `settled()` call, because a
34
+ * native clock binds after the worker starts. False means `settled()` is always true. Default true. */
35
+ hasClock?: boolean | (() => boolean);
28
36
  }): HostSessionProvider;
29
37
  /** The session on `globalThis.himalaya`. Web publishes `identityBound: false`. */
30
38
  export declare function hostSessionFromGlobal(): HostSessionProvider;
@@ -1038,6 +1038,11 @@ function createHostSession(source) {
1038
1038
  const snap = pull();
1039
1039
  return snap.ready ? snap.siteId : null;
1040
1040
  },
1041
+ settled() {
1042
+ const hasClock = typeof source.hasClock === "function" ? source.hasClock() : source.hasClock !== false;
1043
+ if (!hasClock) return true;
1044
+ return pull().ready;
1045
+ },
1041
1046
  subscribe(listener) {
1042
1047
  return source.subscribe(() => {
1043
1048
  const before = seen;
@@ -1052,12 +1057,13 @@ function hostSessionFromGlobal() {
1052
1057
  const session = api?.session;
1053
1058
  if (!session || typeof session.current !== "function" || typeof session.subscribe !== "function") {
1054
1059
  return createHostSession({ identityBound: false, current: () => SIGNED_OUT, subscribe: () => () => {
1055
- } });
1060
+ }, hasClock: false });
1056
1061
  }
1057
1062
  return createHostSession({
1058
1063
  identityBound: api?.identityBound === true,
1059
1064
  current: () => session.current(),
1060
- subscribe: (listener) => session.subscribe(listener)
1065
+ subscribe: (listener) => session.subscribe(listener),
1066
+ hasClock: () => wixApiGlobal()?.identityBound === true || typeof nativeSessionFunction() === "function"
1061
1067
  });
1062
1068
  }
1063
1069
  function memberIdentityOf(source) {
@@ -1086,6 +1092,9 @@ function parseSession(raw) {
1086
1092
  epoch: typeof value.epoch === "number" ? value.epoch : 0
1087
1093
  };
1088
1094
  }
1095
+ function nativeSessionFunction() {
1096
+ return globalThis.__himalaya_native_session_current;
1097
+ }
1089
1098
  function wixApiGlobal() {
1090
1099
  return globalThis.himalaya?.wixApi;
1091
1100
  }
@@ -1042,6 +1042,11 @@ function createHostSession(source) {
1042
1042
  const snap = pull();
1043
1043
  return snap.ready ? snap.siteId : null;
1044
1044
  },
1045
+ settled() {
1046
+ const hasClock = typeof source.hasClock === "function" ? source.hasClock() : source.hasClock !== false;
1047
+ if (!hasClock) return true;
1048
+ return pull().ready;
1049
+ },
1045
1050
  subscribe(listener) {
1046
1051
  return source.subscribe(() => {
1047
1052
  const before = seen;
@@ -1056,12 +1061,13 @@ function hostSessionFromGlobal() {
1056
1061
  const session = api?.session;
1057
1062
  if (!session || typeof session.current !== "function" || typeof session.subscribe !== "function") {
1058
1063
  return createHostSession({ identityBound: false, current: () => SIGNED_OUT, subscribe: () => () => {
1059
- } });
1064
+ }, hasClock: false });
1060
1065
  }
1061
1066
  return createHostSession({
1062
1067
  identityBound: api?.identityBound === true,
1063
1068
  current: () => session.current(),
1064
- subscribe: (listener) => session.subscribe(listener)
1069
+ subscribe: (listener) => session.subscribe(listener),
1070
+ hasClock: () => wixApiGlobal()?.identityBound === true || typeof nativeSessionFunction() === "function"
1065
1071
  });
1066
1072
  }
1067
1073
  function memberIdentityOf(source) {
@@ -1090,6 +1096,9 @@ function parseSession(raw) {
1090
1096
  epoch: typeof value.epoch === "number" ? value.epoch : 0
1091
1097
  };
1092
1098
  }
1099
+ function nativeSessionFunction() {
1100
+ return globalThis.__himalaya_native_session_current;
1101
+ }
1093
1102
  function wixApiGlobal() {
1094
1103
  return globalThis.himalaya?.wixApi;
1095
1104
  }
@@ -4325,6 +4325,11 @@ function createHostSession(source) {
4325
4325
  const snap = pull();
4326
4326
  return snap.ready ? snap.siteId : null;
4327
4327
  },
4328
+ settled() {
4329
+ const hasClock = typeof source.hasClock === "function" ? source.hasClock() : source.hasClock !== false;
4330
+ if (!hasClock) return true;
4331
+ return pull().ready;
4332
+ },
4328
4333
  subscribe(listener) {
4329
4334
  return source.subscribe(() => {
4330
4335
  const before = seen;
@@ -4339,12 +4344,13 @@ function hostSessionFromGlobal() {
4339
4344
  const session = api?.session;
4340
4345
  if (!session || typeof session.current !== "function" || typeof session.subscribe !== "function") {
4341
4346
  return createHostSession({ identityBound: false, current: () => SIGNED_OUT, subscribe: () => () => {
4342
- } });
4347
+ }, hasClock: false });
4343
4348
  }
4344
4349
  return createHostSession({
4345
4350
  identityBound: api?.identityBound === true,
4346
4351
  current: () => session.current(),
4347
- subscribe: (listener) => session.subscribe(listener)
4352
+ subscribe: (listener) => session.subscribe(listener),
4353
+ hasClock: () => wixApiGlobal()?.identityBound === true || typeof nativeSessionFunction() === "function"
4348
4354
  });
4349
4355
  }
4350
4356
  function memberIdentityOf(source) {
@@ -4373,6 +4379,9 @@ function parseSession(raw) {
4373
4379
  epoch: typeof value.epoch === "number" ? value.epoch : 0
4374
4380
  };
4375
4381
  }
4382
+ function nativeSessionFunction() {
4383
+ return globalThis.__himalaya_native_session_current;
4384
+ }
4376
4385
  function wixApiGlobal() {
4377
4386
  return globalThis.himalaya?.wixApi;
4378
4387
  }
package/dist/cli.mjs CHANGED
@@ -42326,7 +42326,6 @@ function shouldRevealError(args) {
42326
42326
  var EMAIL_RE, URL_HOST_RE, INTEGER_RE, NUMBER_RE, AUTHORED_PATTERN_LIMIT, authoredPatterns;
42327
42327
  var init_validation = __esm({
42328
42328
  "../../core/ts/src/validation.ts"() {
42329
- "use strict";
42330
42329
  init_define_HHP_CATALOG();
42331
42330
  EMAIL_RE = /^[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}$/;
42332
42331
  URL_HOST_RE = /^[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*(:[0-9]+)?$/;
@@ -3175,7 +3175,7 @@
3175
3175
  "name": "HostIdentitySource",
3176
3176
  "kind": "interface",
3177
3177
  "jsdoc": "/** A session provider that can also name the principal captured for one generation. */",
3178
- "decl": "export interface HostIdentitySource {\n readonly identityBound: boolean;\n identity(session: SessionSnapshot): HostCallExpectation | null;\n /** The site the native bridge fences protected calls to, from the latest ready snapshot. Null\n * when the host installed no session source: iOS publishes the bridge (`identityBound`) to\n * every worker that has `wix_api`, with or without one. */\n site(): string | null;\n}",
3178
+ "decl": "export interface HostIdentitySource {\n readonly identityBound: boolean;\n identity(session: SessionSnapshot): HostCallExpectation | null;\n /** The site the native bridge fences protected calls to, from the latest ready snapshot. Null\n * when the host installed no session source: iOS publishes the bridge (`identityBound`) to\n * every worker that has `wix_api`, with or without one. */\n site(): string | null;\n /** Whether the host's session clock has settled: the native runtime has restored (or confirmed) who is signed in,\n * so `current().kind` is final rather than the provisional `signedOut` a clock reports while it is still restoring.\n * True when the host has no authenticated clock: none published, or the web host's stub (`identityBound: false`, never\n * ready). Nothing restores there, so its first answer stands. */\n settled(): boolean;\n}",
3179
3179
  "verificationChecked": true
3180
3180
  },
3181
3181
  {
@@ -3189,7 +3189,7 @@
3189
3189
  "name": "createHostSession",
3190
3190
  "kind": "function",
3191
3191
  "jsdoc": "/** Wraps a host session clock as the session provider the delivery coordinator and the wix-iap\n * client share. Ignores a generation older than the last one read, and keeps the first member\n * expectation captured for each generation for `identity()`. */",
3192
- "decl": "export function createHostSession(source: {\n identityBound: boolean;\n current(): unknown;\n subscribe(listener: () => void): () => void;\n}): HostSessionProvider;",
3192
+ "decl": "export function createHostSession(source: {\n identityBound: boolean;\n current(): unknown;\n subscribe(listener: () => void): () => void;\n /** Whether the host has (or is about to bind) a session clock to wait for; read on every `settled()` call, because a\n * native clock binds after the worker starts. False means `settled()` is always true. Default true. */\n hasClock?: boolean | (() => boolean);\n}): HostSessionProvider;",
3193
3193
  "verificationChecked": true
3194
3194
  },
3195
3195
  {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/himalaya-cli",
3
- "version": "0.1808.0",
3
+ "version": "0.1810.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": [
@@ -82,5 +82,5 @@
82
82
  "artifactId": "himalaya-cli"
83
83
  }
84
84
  },
85
- "falconPackageHash": "7e486167dde2258c4a3d4198efbf0e07bea6d0d928d7befacfa1560d"
85
+ "falconPackageHash": "fd73fe0f39dcd14974589ef5fa6eb001190de3cc6de710998d463bf2"
86
86
  }
@@ -14,8 +14,8 @@ import { HEADER_BADGE_KEYS, headerBadges, type HeaderBadgeActionSignatures, type
14
14
 
15
15
  /** `memberCartHidden` / `visitorCartHidden`: which of a site shell's two cart icons shows
16
16
  * — the native member cart for a signed-in member, the website's cart page for anyone else. Read from
17
- * the host session clock, the same identity the cart count and the cart screen follow. A host with no clock reads
18
- * signed out, so it shows the website's cart. */
17
+ * the host session clock, the same identity the cart count and the cart screen follow, once that clock has settled
18
+ * (neither shows before). A host with no clock reads signed out, so it shows the website's cart. */
19
19
  /** `memberCartBadge`: `cartBadge` for a signed-in member, null for anyone else, for a cart icon that opens a members-only
20
20
  * cart. A visitor's own cart count is a different cart, and must not ride an icon whose tap asks them to sign in. */
21
21
  type State = HeaderBadgeState & { memberCartHidden: boolean; visitorCartHidden: boolean; memberCartBadge: number | null };
@@ -24,7 +24,23 @@ const session = hostSessionFromGlobal();
24
24
  /** A web host has no session clock (the stub reads signed out): its sign-in arrives through `onIdentityChange`. */
25
25
  let webSignedIn = false;
26
26
  const isMember = (): boolean => session.current().kind === "member" || webSignedIn;
27
- const memberFlags = () => { const member = isMember(); return { memberCartHidden: !member, visitorCartHidden: member }; };
27
+ /** Both icons stay hidden until the native clock has settled: while it restores a session it reads `signedOut`, so
28
+ * deciding then would flash the website's cart for a member and then swap it for the native one. The web host has
29
+ * no clock (`settled()` is always true there) and signs in through `onIdentityChange`. The session subscription at
30
+ * the bottom re-runs `syncMember` when the clock settles.
31
+ *
32
+ * The wait is bounded: a native host with no session source looks, at launch, exactly like one whose clock has not
33
+ * bound yet (the native session reader is installed either way), and it would never settle. After
34
+ * SETTLE_GRACE_MS the icons follow the session as it reads then. A worker has no timers, so the bound is a one-shot
35
+ * `_poll` armed by `onLaunch` and stopped by the tick it fires (`settleGrace`). */
36
+ const SETTLE_GRACE_MS = 3000;
37
+ const SETTLE_POLL_ID = "header-badges-settle";
38
+ let settleGraceOver = false;
39
+ const memberFlags = () => {
40
+ if (!session.settled() && !webSignedIn && !settleGraceOver) return { memberCartHidden: true, visitorCartHidden: true };
41
+ const member = isMember();
42
+ return { memberCartHidden: !member, visitorCartHidden: member };
43
+ };
28
44
 
29
45
  /** Recomputed after every update, so a count or a session change both reach it. */
30
46
  function withMemberCartBadge(s: State): State {
@@ -44,6 +60,8 @@ const badges: HeaderBadges<State> = headerBadges<State>(updateInOrder, () => svc
44
60
 
45
61
  const svc = defineService<State, HeaderBadgeActionSignatures<State> & {
46
62
  syncMember: (s: State) => Promise<State>;
63
+ onLaunch: (s: State) => Promise<State>;
64
+ settleGrace: (s: State) => Promise<State>;
47
65
  onIdentityChange: (s: State, change?: unknown) => Promise<State>;
48
66
  }>("brandedLiteNav", {
49
67
  // Every count unavailable until the first read lands, and no failure to report.
@@ -54,6 +72,18 @@ const svc = defineService<State, HeaderBadgeActionSignatures<State> & {
54
72
  actions: {
55
73
  ...badges.actions,
56
74
  syncMember: async (s) => updateInOrder(s, async (current) => ({ ...current, ...memberFlags() })),
75
+ // The bounded wait above: while the clock has not settled, arm one tick SETTLE_GRACE_MS out. `_poll` is a host
76
+ // directive, added after the queue so no later update carries it again.
77
+ onLaunch: async (s) => {
78
+ const next = await updateInOrder(s, async (current) => ({ ...current, ...memberFlags() }));
79
+ if (session.settled() || webSignedIn || settleGraceOver) return next;
80
+ return { ...next, _poll: { id: SETTLE_POLL_ID, intervalMs: SETTLE_GRACE_MS, action: "brandedLiteNav.settleGrace", immediate: false } } as State;
81
+ },
82
+ settleGrace: async (s) => {
83
+ settleGraceOver = true;
84
+ const next = await updateInOrder(s, async (current) => ({ ...current, ...memberFlags() }));
85
+ return { ...next, _poll: { id: SETTLE_POLL_ID, stop: true } } as State;
86
+ },
57
87
  // The web host's identity hook: record who is signed in BEFORE the shared piece drops and re-reads the counts,
58
88
  // so the cart icons' visibility and the member count follow it as they follow the native clock.
59
89
  onIdentityChange: async (s: State, change?: unknown) => {
@@ -14,8 +14,8 @@ import { HEADER_BADGE_KEYS, headerBadges, type HeaderBadgeActionSignatures, type
14
14
 
15
15
  /** `memberCartHidden` / `visitorCartHidden`: which of a site shell's two cart icons shows
16
16
  * — the native member cart for a signed-in member, the website's cart page for anyone else. Read from
17
- * the host session clock, the same identity the cart count and the cart screen follow. A host with no clock reads
18
- * signed out, so it shows the website's cart. */
17
+ * the host session clock, the same identity the cart count and the cart screen follow, once that clock has settled
18
+ * (neither shows before). A host with no clock reads signed out, so it shows the website's cart. */
19
19
  /** `memberCartBadge`: `cartBadge` for a signed-in member, null for anyone else, for a cart icon that opens a members-only
20
20
  * cart. A visitor's own cart count is a different cart, and must not ride an icon whose tap asks them to sign in. */
21
21
  type State = HeaderBadgeState & { memberCartHidden: boolean; visitorCartHidden: boolean; memberCartBadge: number | null };
@@ -24,7 +24,23 @@ const session = hostSessionFromGlobal();
24
24
  /** A web host has no session clock (the stub reads signed out): its sign-in arrives through `onIdentityChange`. */
25
25
  let webSignedIn = false;
26
26
  const isMember = (): boolean => session.current().kind === "member" || webSignedIn;
27
- const memberFlags = () => { const member = isMember(); return { memberCartHidden: !member, visitorCartHidden: member }; };
27
+ /** Both icons stay hidden until the native clock has settled: while it restores a session it reads `signedOut`, so
28
+ * deciding then would flash the website's cart for a member and then swap it for the native one. The web host has
29
+ * no clock (`settled()` is always true there) and signs in through `onIdentityChange`. The session subscription at
30
+ * the bottom re-runs `syncMember` when the clock settles.
31
+ *
32
+ * The wait is bounded: a native host with no session source looks, at launch, exactly like one whose clock has not
33
+ * bound yet (the native session reader is installed either way), and it would never settle. After
34
+ * SETTLE_GRACE_MS the icons follow the session as it reads then. A worker has no timers, so the bound is a one-shot
35
+ * `_poll` armed by `onLaunch` and stopped by the tick it fires (`settleGrace`). */
36
+ const SETTLE_GRACE_MS = 3000;
37
+ const SETTLE_POLL_ID = "header-badges-settle";
38
+ let settleGraceOver = false;
39
+ const memberFlags = () => {
40
+ if (!session.settled() && !webSignedIn && !settleGraceOver) return { memberCartHidden: true, visitorCartHidden: true };
41
+ const member = isMember();
42
+ return { memberCartHidden: !member, visitorCartHidden: member };
43
+ };
28
44
 
29
45
  /** Recomputed after every update, so a count or a session change both reach it. */
30
46
  function withMemberCartBadge(s: State): State {
@@ -44,6 +60,8 @@ const badges: HeaderBadges<State> = headerBadges<State>(updateInOrder, () => svc
44
60
 
45
61
  const svc = defineService<State, HeaderBadgeActionSignatures<State> & {
46
62
  syncMember: (s: State) => Promise<State>;
63
+ onLaunch: (s: State) => Promise<State>;
64
+ settleGrace: (s: State) => Promise<State>;
47
65
  onIdentityChange: (s: State, change?: unknown) => Promise<State>;
48
66
  }>("brandedLiteNav", {
49
67
  // Every count unavailable until the first read lands, and no failure to report.
@@ -54,6 +72,18 @@ const svc = defineService<State, HeaderBadgeActionSignatures<State> & {
54
72
  actions: {
55
73
  ...badges.actions,
56
74
  syncMember: async (s) => updateInOrder(s, async (current) => ({ ...current, ...memberFlags() })),
75
+ // The bounded wait above: while the clock has not settled, arm one tick SETTLE_GRACE_MS out. `_poll` is a host
76
+ // directive, added after the queue so no later update carries it again.
77
+ onLaunch: async (s) => {
78
+ const next = await updateInOrder(s, async (current) => ({ ...current, ...memberFlags() }));
79
+ if (session.settled() || webSignedIn || settleGraceOver) return next;
80
+ return { ...next, _poll: { id: SETTLE_POLL_ID, intervalMs: SETTLE_GRACE_MS, action: "brandedLiteNav.settleGrace", immediate: false } } as State;
81
+ },
82
+ settleGrace: async (s) => {
83
+ settleGraceOver = true;
84
+ const next = await updateInOrder(s, async (current) => ({ ...current, ...memberFlags() }));
85
+ return { ...next, _poll: { id: SETTLE_POLL_ID, stop: true } } as State;
86
+ },
57
87
  // The web host's identity hook: record who is signed in BEFORE the shared piece drops and re-reads the counts,
58
88
  // so the cart icons' visibility and the member count follow it as they follow the native clock.
59
89
  onIdentityChange: async (s: State, change?: unknown) => {