@flamingo-stack/openframe-frontend-core 0.0.689 → 0.0.690-snapshot.20261001124055
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-22RSJ57Z.js → chunk-2YVTGPM7.js} +2 -2
- package/dist/{chunk-O2XJYMZD.js → chunk-4HZXOQRM.js} +5 -5
- package/dist/{chunk-G3MH262S.cjs → chunk-4N2JOPAQ.cjs} +22 -22
- package/dist/{chunk-G3MH262S.cjs.map → chunk-4N2JOPAQ.cjs.map} +1 -1
- package/dist/{chunk-QNWQQ4RT.cjs → chunk-53O6PQ3F.cjs} +7 -7
- package/dist/{chunk-QNWQQ4RT.cjs.map → chunk-53O6PQ3F.cjs.map} +1 -1
- package/dist/{chunk-BN6JXZMA.cjs → chunk-5N2ZSB42.cjs} +18 -18
- package/dist/{chunk-BN6JXZMA.cjs.map → chunk-5N2ZSB42.cjs.map} +1 -1
- package/dist/{chunk-R4V6AU6R.js → chunk-6Z26ZMR4.js} +4 -4
- package/dist/{chunk-HLEXYTOE.js → chunk-7EPGJOKN.js} +4 -4
- package/dist/{chunk-MC5JRMRE.js → chunk-7WYWPELF.js} +11 -11
- package/dist/{chunk-CGMBVDEV.cjs → chunk-BXAGR3PO.cjs} +7 -7
- package/dist/chunk-BXAGR3PO.cjs.map +1 -0
- package/dist/{chunk-FIZJA2MC.cjs → chunk-BXE2RZEV.cjs} +34 -34
- package/dist/{chunk-FIZJA2MC.cjs.map → chunk-BXE2RZEV.cjs.map} +1 -1
- package/dist/{chunk-DLRE5Y3G.js → chunk-C2SVJVEB.js} +2 -2
- package/dist/{chunk-5BZ2FB5K.js → chunk-CMYDGVTZ.js} +2 -2
- package/dist/{chunk-SWOS3DDM.cjs → chunk-CWXRZVDI.cjs} +756 -710
- package/dist/chunk-CWXRZVDI.cjs.map +1 -0
- package/dist/{chunk-R7GU5YSO.js → chunk-DC3G4XGP.js} +6 -6
- package/dist/{chunk-MCHGTS3E.cjs → chunk-DDWLF2JV.cjs} +14 -14
- package/dist/{chunk-MCHGTS3E.cjs.map → chunk-DDWLF2JV.cjs.map} +1 -1
- package/dist/{chunk-NMXL34Z2.cjs → chunk-DVSPRY2V.cjs} +3 -3
- package/dist/{chunk-NMXL34Z2.cjs.map → chunk-DVSPRY2V.cjs.map} +1 -1
- package/dist/{chunk-X2DAEWTQ.js → chunk-DZMDG7PC.js} +3 -3
- package/dist/{chunk-JJLJH4FH.cjs → chunk-ESFPY5FF.cjs} +100 -100
- package/dist/{chunk-JJLJH4FH.cjs.map → chunk-ESFPY5FF.cjs.map} +1 -1
- package/dist/{chunk-7XNS6U7B.js → chunk-FNMQ2J44.js} +5 -5
- package/dist/{chunk-UAKWSR3U.js → chunk-GDZ7IC5B.js} +2 -2
- package/dist/{chunk-OD2WMUAO.cjs → chunk-GZRU2A4L.cjs} +197 -197
- package/dist/{chunk-OD2WMUAO.cjs.map → chunk-GZRU2A4L.cjs.map} +1 -1
- package/dist/{chunk-TOJYEOYP.cjs → chunk-H54RDLVC.cjs} +35 -35
- package/dist/{chunk-TOJYEOYP.cjs.map → chunk-H54RDLVC.cjs.map} +1 -1
- package/dist/{chunk-Q76YVNCQ.js → chunk-HM7ZGABI.js} +2 -2
- package/dist/{chunk-YCKGUQA2.cjs → chunk-I27PWVWE.cjs} +17 -12
- package/dist/chunk-I27PWVWE.cjs.map +1 -0
- package/dist/{chunk-JMD52673.js → chunk-JSG7WZKV.js} +4 -4
- package/dist/{chunk-ZHTZ4ALC.js → chunk-KMW2PXBU.js} +58 -12
- package/dist/chunk-KMW2PXBU.js.map +1 -0
- package/dist/{chunk-3LBEUJUI.js → chunk-KVDLL4LU.js} +4 -4
- package/dist/chunk-KVDLL4LU.js.map +1 -0
- package/dist/{chunk-EAYMYMLX.cjs → chunk-LCENRN2N.cjs} +14 -14
- package/dist/{chunk-EAYMYMLX.cjs.map → chunk-LCENRN2N.cjs.map} +1 -1
- package/dist/{chunk-BJHM2OEY.cjs → chunk-LNKLB7GM.cjs} +17 -17
- package/dist/{chunk-BJHM2OEY.cjs.map → chunk-LNKLB7GM.cjs.map} +1 -1
- package/dist/{chunk-JGVJRUGB.cjs → chunk-MIZU2OTO.cjs} +4 -4
- package/dist/{chunk-JGVJRUGB.cjs.map → chunk-MIZU2OTO.cjs.map} +1 -1
- package/dist/{chunk-NOA7SLDH.js → chunk-MJI5GVT7.js} +11 -11
- package/dist/{chunk-BOM6MMWB.cjs → chunk-N3526CTH.cjs} +3 -3
- package/dist/{chunk-BOM6MMWB.cjs.map → chunk-N3526CTH.cjs.map} +1 -1
- package/dist/{chunk-GQTWZL2M.cjs → chunk-N4S7RBUM.cjs} +3 -3
- package/dist/{chunk-GQTWZL2M.cjs.map → chunk-N4S7RBUM.cjs.map} +1 -1
- package/dist/{chunk-OZKJZUPF.cjs → chunk-SA4KQCNB.cjs} +82 -82
- package/dist/{chunk-OZKJZUPF.cjs.map → chunk-SA4KQCNB.cjs.map} +1 -1
- package/dist/{chunk-RF2EYX3B.js → chunk-SC44YJCF.js} +2 -2
- package/dist/{chunk-2OD2PPNO.cjs → chunk-SDORFSFK.cjs} +37 -37
- package/dist/{chunk-2OD2PPNO.cjs.map → chunk-SDORFSFK.cjs.map} +1 -1
- package/dist/{chunk-VB4MZWNO.js → chunk-TSNGVWQO.js} +6 -6
- package/dist/{chunk-DMXI5D2Q.cjs → chunk-USKQURNF.cjs} +3 -3
- package/dist/{chunk-DMXI5D2Q.cjs.map → chunk-USKQURNF.cjs.map} +1 -1
- package/dist/{chunk-2KILTCND.js → chunk-UVUNBXS6.js} +6 -1
- package/dist/chunk-UVUNBXS6.js.map +1 -0
- package/dist/{chunk-XNJRUSBZ.cjs → chunk-WZYIAKIH.cjs} +7 -7
- package/dist/{chunk-XNJRUSBZ.cjs.map → chunk-WZYIAKIH.cjs.map} +1 -1
- package/dist/{chunk-2V4KPBNZ.js → chunk-XAOAYDGR.js} +3 -3
- package/dist/{chunk-3SJOXM6Y.js → chunk-XBYF4SGD.js} +4 -4
- package/dist/{chunk-G7PNBP6I.cjs → chunk-Y3BC7TOJ.cjs} +26 -26
- package/dist/{chunk-G7PNBP6I.cjs.map → chunk-Y3BC7TOJ.cjs.map} +1 -1
- package/dist/{chunk-O5AHLF4Z.cjs → chunk-Y3Q76RAA.cjs} +37 -37
- package/dist/{chunk-O5AHLF4Z.cjs.map → chunk-Y3Q76RAA.cjs.map} +1 -1
- package/dist/{chunk-4BUPMSLY.js → chunk-Y7ZEVTLC.js} +3 -3
- package/dist/{chunk-T2MHRQZR.js → chunk-Y7ZQZOE6.js} +5 -5
- package/dist/{chunk-45HXQ7RV.js → chunk-Z5FHXCXF.js} +8 -8
- package/dist/{chunk-MNKP6VGT.cjs → chunk-ZLYLHP64.cjs} +9 -9
- package/dist/{chunk-MNKP6VGT.cjs.map → chunk-ZLYLHP64.cjs.map} +1 -1
- package/dist/components/case-studies/index.cjs +20 -20
- package/dist/components/case-studies/index.js +7 -7
- package/dist/components/chat/index.cjs +4 -4
- package/dist/components/chat/index.js +3 -3
- package/dist/components/contact/index.cjs +8 -8
- package/dist/components/contact/index.js +7 -7
- package/dist/components/docs/index.cjs +11 -11
- package/dist/components/docs/index.js +10 -10
- package/dist/components/embeds/index.cjs +8 -8
- package/dist/components/embeds/index.js +7 -7
- package/dist/components/faq/index.cjs +9 -9
- package/dist/components/faq/index.js +8 -8
- package/dist/components/features/index.cjs +7 -7
- package/dist/components/features/index.js +6 -6
- package/dist/components/features/notifications/notification-tile.d.ts.map +1 -1
- package/dist/components/help-center-pages/index.cjs +101 -101
- package/dist/components/help-center-pages/index.js +21 -21
- package/dist/components/index.cjs +65 -65
- package/dist/components/index.js +21 -21
- package/dist/components/meeting-scheduler/index.cjs +58 -58
- package/dist/components/meeting-scheduler/index.js +8 -8
- package/dist/components/navigation/index.cjs +10 -10
- package/dist/components/navigation/index.js +9 -9
- package/dist/components/onboarding-guides/index.cjs +11 -11
- package/dist/components/onboarding-guides/index.js +10 -10
- package/dist/components/related-content/index.cjs +6 -6
- package/dist/components/related-content/index.js +5 -5
- package/dist/components/tickets/index.cjs +12 -12
- package/dist/components/tickets/index.js +11 -11
- package/dist/components/tickets/ticket-live-provider.d.ts.map +1 -1
- package/dist/components/ui/index.cjs +7 -7
- package/dist/components/ui/index.js +6 -6
- package/dist/hooks/index.cjs +4 -4
- package/dist/hooks/index.js +3 -3
- package/dist/index.cjs +12 -12
- package/dist/index.js +10 -10
- package/dist/utils/embed-authed-fetch.d.ts +18 -0
- package/dist/utils/embed-authed-fetch.d.ts.map +1 -1
- package/dist/utils/index.cjs +50 -6
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.js +50 -6
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/sse-subscription.d.ts +29 -11
- package/dist/utils/sse-subscription.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/features/notifications/notification-tile.tsx +13 -1
- package/src/components/tickets/ticket-live-provider.tsx +14 -12
- package/src/utils/embed-authed-fetch.ts +21 -0
- package/src/utils/sse-subscription.ts +107 -20
- package/dist/chunk-2KILTCND.js.map +0 -1
- package/dist/chunk-3LBEUJUI.js.map +0 -1
- package/dist/chunk-CGMBVDEV.cjs.map +0 -1
- package/dist/chunk-SWOS3DDM.cjs.map +0 -1
- package/dist/chunk-YCKGUQA2.cjs.map +0 -1
- package/dist/chunk-ZHTZ4ALC.js.map +0 -1
- /package/dist/{chunk-22RSJ57Z.js.map → chunk-2YVTGPM7.js.map} +0 -0
- /package/dist/{chunk-O2XJYMZD.js.map → chunk-4HZXOQRM.js.map} +0 -0
- /package/dist/{chunk-R4V6AU6R.js.map → chunk-6Z26ZMR4.js.map} +0 -0
- /package/dist/{chunk-HLEXYTOE.js.map → chunk-7EPGJOKN.js.map} +0 -0
- /package/dist/{chunk-MC5JRMRE.js.map → chunk-7WYWPELF.js.map} +0 -0
- /package/dist/{chunk-DLRE5Y3G.js.map → chunk-C2SVJVEB.js.map} +0 -0
- /package/dist/{chunk-5BZ2FB5K.js.map → chunk-CMYDGVTZ.js.map} +0 -0
- /package/dist/{chunk-R7GU5YSO.js.map → chunk-DC3G4XGP.js.map} +0 -0
- /package/dist/{chunk-X2DAEWTQ.js.map → chunk-DZMDG7PC.js.map} +0 -0
- /package/dist/{chunk-7XNS6U7B.js.map → chunk-FNMQ2J44.js.map} +0 -0
- /package/dist/{chunk-UAKWSR3U.js.map → chunk-GDZ7IC5B.js.map} +0 -0
- /package/dist/{chunk-Q76YVNCQ.js.map → chunk-HM7ZGABI.js.map} +0 -0
- /package/dist/{chunk-JMD52673.js.map → chunk-JSG7WZKV.js.map} +0 -0
- /package/dist/{chunk-NOA7SLDH.js.map → chunk-MJI5GVT7.js.map} +0 -0
- /package/dist/{chunk-RF2EYX3B.js.map → chunk-SC44YJCF.js.map} +0 -0
- /package/dist/{chunk-VB4MZWNO.js.map → chunk-TSNGVWQO.js.map} +0 -0
- /package/dist/{chunk-2V4KPBNZ.js.map → chunk-XAOAYDGR.js.map} +0 -0
- /package/dist/{chunk-3SJOXM6Y.js.map → chunk-XBYF4SGD.js.map} +0 -0
- /package/dist/{chunk-4BUPMSLY.js.map → chunk-Y7ZEVTLC.js.map} +0 -0
- /package/dist/{chunk-T2MHRQZR.js.map → chunk-Y7ZQZOE6.js.map} +0 -0
- /package/dist/{chunk-45HXQ7RV.js.map → chunk-Z5FHXCXF.js.map} +0 -0
|
@@ -16,11 +16,26 @@
|
|
|
16
16
|
* (INCLUDING `: keepalive` comment lines — they reset the timer
|
|
17
17
|
* before frame parsing drops them) count as life. Silence beyond
|
|
18
18
|
* `silenceTimeoutMs` (default 45s = 3× keepalive) aborts + reconnects.
|
|
19
|
-
* - Terminal responses
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
19
|
+
* - Terminal responses: any 4xx except 408/429 — the `x-block-layer`
|
|
20
|
+
* header, when readable, is logged for attribution only, never used
|
|
21
|
+
* as a retry gate (proxies may strip it); and 204 → a distinct
|
|
22
|
+
* `no-stream` status (the caller decides when to try again).
|
|
23
|
+
* Backoff-retry is for transport errors, 408/429, and 5xx.
|
|
24
|
+
* - Long-lived streams (`pauseWhenHidden`) never stay terminal, because
|
|
25
|
+
* a page a desktop shell keeps open for days would otherwise stay
|
|
26
|
+
* dead until reloaded:
|
|
27
|
+
* · 401 is retried on a slow timer (30s doubling to 5min, plus
|
|
28
|
+
* jitter). The default fetch already refreshed + retried once, so
|
|
29
|
+
* this is a session the host could not renew yet — and every
|
|
30
|
+
* attempt makes it try again, which rotates a refresh token. So
|
|
31
|
+
* visible / focus do NOT shortcut this timer. What does: a new
|
|
32
|
+
* credential reported by the host (`EmbedAuthAdapter.subscribe`,
|
|
33
|
+
* default fetch only), plus the unconditional reconnect paths
|
|
34
|
+
* (`online`, resuming after a suspend, `reconnectNow()`).
|
|
35
|
+
* · Any other terminal 4xx is retried on visible / window focus, no
|
|
36
|
+
* sooner than 30s after the last connect attempt.
|
|
37
|
+
* Finite streams keep the terminal behavior: their monitors have no
|
|
38
|
+
* auth adapter to recover with and must reach a final state.
|
|
24
39
|
*
|
|
25
40
|
* THE common SSE client for lib + hosts — exported from the `utils`
|
|
26
41
|
* barrel. Consumers: `TicketLiveProvider` (lib) and the hub's
|
|
@@ -31,7 +46,8 @@
|
|
|
31
46
|
* never-terminating reconnect loop re-opens the finished stream.
|
|
32
47
|
*/
|
|
33
48
|
/** Transport-level status. `suspended` = paused by `pauseWhenHidden`
|
|
34
|
-
* after the hidden grace elapsed (resumes automatically on visible).
|
|
49
|
+
* after the hidden grace elapsed (resumes automatically on visible).
|
|
50
|
+
* `terminal` is final only without `pauseWhenHidden`. */
|
|
35
51
|
export type SseTransportStatus = 'connecting' | 'open' | 'reconnecting' | 'no-stream' | 'terminal' | 'suspended' | 'closed';
|
|
36
52
|
export interface SseSubscriptionOptions {
|
|
37
53
|
url: string;
|
|
@@ -59,10 +75,11 @@ export interface SseSubscriptionOptions {
|
|
|
59
75
|
/**
|
|
60
76
|
* Pause the subscription while the tab is hidden (45s grace so
|
|
61
77
|
* Cmd-Tab thrash doesn't churn connections), resume + reconnect on
|
|
62
|
-
* visible, and reconnect on `online`.
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
*
|
|
78
|
+
* visible, and reconnect on `online`. Also makes the stream
|
|
79
|
+
* self-healing after a 401 or terminal 4xx (see the module header).
|
|
80
|
+
* OPT-IN — short-lived streams (workflow/invocation monitors) must
|
|
81
|
+
* keep running in background tabs. Long-lived per-user streams should
|
|
82
|
+
* enable it (scale relief: a hidden tab holds no server invocation).
|
|
66
83
|
*/
|
|
67
84
|
pauseWhenHidden?: boolean;
|
|
68
85
|
/** Silence threshold before the connection is presumed dead. MUST be
|
|
@@ -76,7 +93,8 @@ export interface SseSubscription {
|
|
|
76
93
|
/** Permanently stop — no further reconnects, no callbacks. */
|
|
77
94
|
close: () => void;
|
|
78
95
|
/** Drop the current connection (if any) and reconnect immediately,
|
|
79
|
-
* resetting
|
|
96
|
+
* resetting the transport backoff (a 401 backoff carries over until a
|
|
97
|
+
* successful open). No-op after `close()`. */
|
|
80
98
|
reconnectNow: () => void;
|
|
81
99
|
}
|
|
82
100
|
export declare function createSseSubscription(options: SseSubscriptionOptions): SseSubscription;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sse-subscription.d.ts","sourceRoot":"","sources":["../../src/utils/sse-subscription.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"sse-subscription.d.ts","sourceRoot":"","sources":["../../src/utils/sse-subscription.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AAIH;;0DAE0D;AAC1D,MAAM,MAAM,kBAAkB,GAC5B,YAAY,GAAG,MAAM,GAAG,cAAc,GAAG,WAAW,GAAG,UAAU,GAAG,WAAW,GAAG,QAAQ,CAAC;AAE7F,MAAM,WAAW,sBAAsB;IACrC,GAAG,EAAE,MAAM,CAAC;IACZ,sEAAsE;IACtE,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAC;IACnE;;;2EAGuE;IACvE,OAAO,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,IAAI,CAAC;IACpD,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,kBAAkB,KAAK,IAAI,CAAC;IACtD;;;;;;;;;;;OAWG;IACH,iBAAiB,CAAC,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,CAAC;IACjD;;;;;;;;OAQG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;2DAEuD;IACvD,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,MAAM,WAAW,eAAe;IAC9B,8DAA8D;IAC9D,KAAK,EAAE,MAAM,IAAI,CAAC;IAClB;;mDAE+C;IAC/C,YAAY,EAAE,MAAM,IAAI,CAAC;CAC1B;AA0BD,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,GAAG,eAAe,CA2atF"}
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@ import { cn } from '../../../utils/cn';
|
|
|
6
6
|
import { formatTicketRelativeTime } from '../../../utils/date-utils';
|
|
7
7
|
import { CheckCircleIcon } from '../../icons-v2-generated/signs-and-symbols/check-circle-icon';
|
|
8
8
|
import { XmarkIcon } from '../../icons-v2-generated/signs-and-symbols/xmark-icon';
|
|
9
|
-
import { dotColorByVariant, progressColorByVariant } from '../../ui/toaster';
|
|
9
|
+
import { dotColorByVariant, progressColorByVariant as toastProgressColorByVariant } from '../../ui/toaster';
|
|
10
10
|
import type { Notification, NotificationSeverity, NotificationVariant } from './types';
|
|
11
11
|
|
|
12
12
|
/** Backend severity → tile color variant; overrides `notification.variant` when present. */
|
|
@@ -26,6 +26,18 @@ const typeColorByVariant: Record<NotificationVariant, string> = {
|
|
|
26
26
|
error: 'text-ods-error',
|
|
27
27
|
};
|
|
28
28
|
|
|
29
|
+
/**
|
|
30
|
+
* The live countdown bar. The attention variants keep their colour; the neutral card's bar
|
|
31
|
+
* is the brand accent (Figma `notification-card`: `open-colors/yellow`), not the grey the
|
|
32
|
+
* toast draws. A toast's bar only times out; a card's says "new, still live" in a drawer of
|
|
33
|
+
* settled grey rows, so it needs the accent to read at all. The dot keeps the toast colours.
|
|
34
|
+
*/
|
|
35
|
+
const progressColorByVariant: Record<NotificationVariant, string> = {
|
|
36
|
+
...toastProgressColorByVariant,
|
|
37
|
+
default: 'bg-ods-accent',
|
|
38
|
+
info: 'bg-ods-accent',
|
|
39
|
+
};
|
|
40
|
+
|
|
29
41
|
const headerControlClass =
|
|
30
42
|
'absolute inset-0 flex items-center justify-center text-ods-text-secondary transition-opacity duration-200 hover:text-ods-text-primary';
|
|
31
43
|
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
/**
|
|
4
4
|
* TicketLiveProvider — the ONE client home for support-ticket realtime.
|
|
5
5
|
*
|
|
6
|
-
* DOMAIN logic only — connection lifecycle
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
6
|
+
* DOMAIN logic only — connection lifecycle is owned entirely by the
|
|
7
|
+
* common SSE client (`createSseSubscription`; its module header lists
|
|
8
|
+
* the policies); this provider consumes its consolidated
|
|
9
|
+
* `onConnectedChange` signal.
|
|
10
10
|
*
|
|
11
11
|
* Owns:
|
|
12
12
|
* - the unread summary — delivered EXCLUSIVELY by the stream
|
|
@@ -20,8 +20,9 @@
|
|
|
20
20
|
* - the ticket-contract `no-stream` (204) retry policy.
|
|
21
21
|
*
|
|
22
22
|
* There is NO polling anywhere and NO summary endpoint. Hosts whose
|
|
23
|
-
* stream endpoint 404s
|
|
24
|
-
*
|
|
23
|
+
* stream endpoint 404s or is absent get no unread indication — the
|
|
24
|
+
* indication IS a realtime feature (a 404ing endpoint is re-probed on
|
|
25
|
+
* presence, rate-limited by the client).
|
|
25
26
|
*
|
|
26
27
|
* Invalidation semantics on events — deliberately `invalidateQueries`,
|
|
27
28
|
* NOT `setQueryData` patches: the ticket hooks run `gcTime: 0`, so
|
|
@@ -286,11 +287,10 @@ export function TicketLiveProvider({ children, enabled = true }: TicketLiveProvi
|
|
|
286
287
|
};
|
|
287
288
|
|
|
288
289
|
const handleStatus = (status: SseTransportStatus) => {
|
|
289
|
-
// The client owns connection lifecycle
|
|
290
|
-
//
|
|
291
|
-
//
|
|
292
|
-
//
|
|
293
|
-
// signal (own create_ticket, window focus) can retry.
|
|
290
|
+
// The client owns connection lifecycle. The only transport status
|
|
291
|
+
// with DOMAIN meaning is the ticket contract's `no-stream` (204 =
|
|
292
|
+
// zero owned tickets): remember it so a domain signal (own
|
|
293
|
+
// create_ticket, window focus) can retry.
|
|
294
294
|
if (status === 'open') noStreamRef.current = false;
|
|
295
295
|
if (status === 'no-stream') noStreamRef.current = true;
|
|
296
296
|
};
|
|
@@ -324,7 +324,9 @@ export function TicketLiveProvider({ children, enabled = true }: TicketLiveProvi
|
|
|
324
324
|
});
|
|
325
325
|
|
|
326
326
|
const retryIfIdle = () => {
|
|
327
|
-
// After a 204 (no-stream), a focus signal is the retry trigger.
|
|
327
|
+
// After a 204 (no-stream), a focus signal is the retry trigger. Only
|
|
328
|
+
// 204 — the client's contract leaves that retry to the caller; it
|
|
329
|
+
// retries terminal / 401 states on its own.
|
|
328
330
|
if (noStreamRef.current) {
|
|
329
331
|
noStreamRef.current = false;
|
|
330
332
|
subscriptionRef.current?.reconnectNow();
|
|
@@ -99,6 +99,16 @@ export interface EmbedAuthAdapter {
|
|
|
99
99
|
* remains the rule, this is the narrow exception.
|
|
100
100
|
*/
|
|
101
101
|
allowedOrigins?: string[];
|
|
102
|
+
/**
|
|
103
|
+
* Optional: call `listener` whenever `getHeaders()` starts returning a NEW
|
|
104
|
+
* credential (a rotation the host ran on its own — e.g. a native shell's
|
|
105
|
+
* background refresh). Returns an unsubscribe. Lets a long-lived surface
|
|
106
|
+
* that stopped after a 401 retry as soon as a usable credential exists,
|
|
107
|
+
* instead of on its next backoff step. Fire only on a real change: a
|
|
108
|
+
* listener may respond with a request, and through `refresh` that request
|
|
109
|
+
* can lead the host to notify again.
|
|
110
|
+
*/
|
|
111
|
+
subscribe?: (listener: () => void) => () => void;
|
|
102
112
|
}
|
|
103
113
|
|
|
104
114
|
/**
|
|
@@ -156,6 +166,17 @@ export function hasEmbedAuthAdapter(): boolean {
|
|
|
156
166
|
return getRegisteredAuthAdapter() !== null;
|
|
157
167
|
}
|
|
158
168
|
|
|
169
|
+
/**
|
|
170
|
+
* Subscribe to the registered adapter's credential changes
|
|
171
|
+
* (`EmbedAuthAdapter.subscribe`). A no-op when no adapter is registered, or
|
|
172
|
+
* the adapter doesn't report changes. Reads the adapter once, at call time:
|
|
173
|
+
* an adapter registered (or replaced) after a subscriber starts is not
|
|
174
|
+
* picked up — register it before the surfaces that need it mount.
|
|
175
|
+
*/
|
|
176
|
+
export function subscribeEmbedCredentialChange(listener: () => void): () => void {
|
|
177
|
+
return getRegisteredAuthAdapter()?.subscribe?.(listener) ?? (() => {});
|
|
178
|
+
}
|
|
179
|
+
|
|
159
180
|
/**
|
|
160
181
|
* Whether `url` is an asset the browser CANNOT load natively because its
|
|
161
182
|
* auth rides in request headers.
|
|
@@ -16,11 +16,26 @@
|
|
|
16
16
|
* (INCLUDING `: keepalive` comment lines — they reset the timer
|
|
17
17
|
* before frame parsing drops them) count as life. Silence beyond
|
|
18
18
|
* `silenceTimeoutMs` (default 45s = 3× keepalive) aborts + reconnects.
|
|
19
|
-
* - Terminal responses
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
19
|
+
* - Terminal responses: any 4xx except 408/429 — the `x-block-layer`
|
|
20
|
+
* header, when readable, is logged for attribution only, never used
|
|
21
|
+
* as a retry gate (proxies may strip it); and 204 → a distinct
|
|
22
|
+
* `no-stream` status (the caller decides when to try again).
|
|
23
|
+
* Backoff-retry is for transport errors, 408/429, and 5xx.
|
|
24
|
+
* - Long-lived streams (`pauseWhenHidden`) never stay terminal, because
|
|
25
|
+
* a page a desktop shell keeps open for days would otherwise stay
|
|
26
|
+
* dead until reloaded:
|
|
27
|
+
* · 401 is retried on a slow timer (30s doubling to 5min, plus
|
|
28
|
+
* jitter). The default fetch already refreshed + retried once, so
|
|
29
|
+
* this is a session the host could not renew yet — and every
|
|
30
|
+
* attempt makes it try again, which rotates a refresh token. So
|
|
31
|
+
* visible / focus do NOT shortcut this timer. What does: a new
|
|
32
|
+
* credential reported by the host (`EmbedAuthAdapter.subscribe`,
|
|
33
|
+
* default fetch only), plus the unconditional reconnect paths
|
|
34
|
+
* (`online`, resuming after a suspend, `reconnectNow()`).
|
|
35
|
+
* · Any other terminal 4xx is retried on visible / window focus, no
|
|
36
|
+
* sooner than 30s after the last connect attempt.
|
|
37
|
+
* Finite streams keep the terminal behavior: their monitors have no
|
|
38
|
+
* auth adapter to recover with and must reach a final state.
|
|
24
39
|
*
|
|
25
40
|
* THE common SSE client for lib + hosts — exported from the `utils`
|
|
26
41
|
* barrel. Consumers: `TicketLiveProvider` (lib) and the hub's
|
|
@@ -31,10 +46,11 @@
|
|
|
31
46
|
* never-terminating reconnect loop re-opens the finished stream.
|
|
32
47
|
*/
|
|
33
48
|
|
|
34
|
-
import { embedAuthedFetch } from './embed-authed-fetch';
|
|
49
|
+
import { embedAuthedFetch, subscribeEmbedCredentialChange } from './embed-authed-fetch';
|
|
35
50
|
|
|
36
51
|
/** Transport-level status. `suspended` = paused by `pauseWhenHidden`
|
|
37
|
-
* after the hidden grace elapsed (resumes automatically on visible).
|
|
52
|
+
* after the hidden grace elapsed (resumes automatically on visible).
|
|
53
|
+
* `terminal` is final only without `pauseWhenHidden`. */
|
|
38
54
|
export type SseTransportStatus =
|
|
39
55
|
'connecting' | 'open' | 'reconnecting' | 'no-stream' | 'terminal' | 'suspended' | 'closed';
|
|
40
56
|
|
|
@@ -64,10 +80,11 @@ export interface SseSubscriptionOptions {
|
|
|
64
80
|
/**
|
|
65
81
|
* Pause the subscription while the tab is hidden (45s grace so
|
|
66
82
|
* Cmd-Tab thrash doesn't churn connections), resume + reconnect on
|
|
67
|
-
* visible, and reconnect on `online`.
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
83
|
+
* visible, and reconnect on `online`. Also makes the stream
|
|
84
|
+
* self-healing after a 401 or terminal 4xx (see the module header).
|
|
85
|
+
* OPT-IN — short-lived streams (workflow/invocation monitors) must
|
|
86
|
+
* keep running in background tabs. Long-lived per-user streams should
|
|
87
|
+
* enable it (scale relief: a hidden tab holds no server invocation).
|
|
71
88
|
*/
|
|
72
89
|
pauseWhenHidden?: boolean;
|
|
73
90
|
/** Silence threshold before the connection is presumed dead. MUST be
|
|
@@ -82,7 +99,8 @@ export interface SseSubscription {
|
|
|
82
99
|
/** Permanently stop — no further reconnects, no callbacks. */
|
|
83
100
|
close: () => void;
|
|
84
101
|
/** Drop the current connection (if any) and reconnect immediately,
|
|
85
|
-
* resetting
|
|
102
|
+
* resetting the transport backoff (a 401 backoff carries over until a
|
|
103
|
+
* successful open). No-op after `close()`. */
|
|
86
104
|
reconnectNow: () => void;
|
|
87
105
|
}
|
|
88
106
|
|
|
@@ -102,6 +120,13 @@ const SERVER_RETRY_GRACE_MS = 90_000;
|
|
|
102
120
|
const FAILED_RECONNECT_DELAY_MS = 30_000;
|
|
103
121
|
/** Grace before a hidden tab's subscription is suspended. */
|
|
104
122
|
const HIDDEN_GRACE_MS = 45_000;
|
|
123
|
+
/** 401 retry backoff for long-lived streams — slow on purpose, see the
|
|
124
|
+
* module header. */
|
|
125
|
+
const AUTH_RETRY_INITIAL_MS = 30_000;
|
|
126
|
+
const AUTH_RETRY_MAX_MS = 300_000;
|
|
127
|
+
/** Minimum time since the last connect attempt before a presence signal
|
|
128
|
+
* retries a terminal stream — focus can fire many times a minute. */
|
|
129
|
+
const PRESENCE_RETRY_MIN_INTERVAL_MS = 30_000;
|
|
105
130
|
|
|
106
131
|
export function createSseSubscription(options: SseSubscriptionOptions): SseSubscription {
|
|
107
132
|
const {
|
|
@@ -119,6 +144,18 @@ export function createSseSubscription(options: SseSubscriptionOptions): SseSubsc
|
|
|
119
144
|
let closed = false;
|
|
120
145
|
let suspended = false;
|
|
121
146
|
let attempt = 0;
|
|
147
|
+
let authAttempt = 0;
|
|
148
|
+
/** Stopped on a terminal response — what a presence signal retries.
|
|
149
|
+
* Cleared by every connect(). */
|
|
150
|
+
let stalled = false;
|
|
151
|
+
/** A 401 retry timer is pending — the only state a host credential change
|
|
152
|
+
* acts on, so routine rotations never tear down a live stream. Cleared by
|
|
153
|
+
* every connect(): a change reported while a request is in flight is
|
|
154
|
+
* indistinguishable from the default fetch's own refresh, so it is not
|
|
155
|
+
* acted on (a 401 that follows waits for the next backoff step) — acting
|
|
156
|
+
* on it would let a 401 → refresh → notify cycle loop. */
|
|
157
|
+
let awaitingAuth = false;
|
|
158
|
+
let lastConnectAt = 0;
|
|
122
159
|
/** Connection generation — bumped by each connect() and by
|
|
123
160
|
* reconnectNow(). A stale loop (aborted, still unwinding) compares
|
|
124
161
|
* its captured generation before scheduling a reconnect, so an
|
|
@@ -223,7 +260,8 @@ export function createSseSubscription(options: SseSubscriptionOptions): SseSubsc
|
|
|
223
260
|
confirmTimerId = clearLifecycleTimer(confirmTimerId);
|
|
224
261
|
serverGraceTimerId = clearLifecycleTimer(serverGraceTimerId);
|
|
225
262
|
failedDelayTimerId = clearLifecycleTimer(failedDelayTimerId);
|
|
226
|
-
|
|
263
|
+
// NOT the hidden-grace timer: it tracks the page's visibility, not this
|
|
264
|
+
// connection, and a reconnect while hidden must still suspend on time.
|
|
227
265
|
};
|
|
228
266
|
|
|
229
267
|
const armSilenceTimer = () => {
|
|
@@ -235,16 +273,29 @@ export function createSseSubscription(options: SseSubscriptionOptions): SseSubsc
|
|
|
235
273
|
}, silenceTimeoutMs);
|
|
236
274
|
};
|
|
237
275
|
|
|
238
|
-
|
|
276
|
+
/** `delayMs` overrides the transport backoff (auth-failure pacing). */
|
|
277
|
+
const scheduleReconnect = (delayMs?: number) => {
|
|
239
278
|
if (closed || suspended || retryTimerId) return;
|
|
240
|
-
|
|
241
|
-
|
|
279
|
+
if (failedDelayTimerId) {
|
|
280
|
+
// A server `reconnect_failed` already scheduled the next attempt at the
|
|
281
|
+
// no-stampede delay. A transport retry here would jump that queue, and
|
|
282
|
+
// the pending timer would then abort the connection it opened.
|
|
283
|
+
setStatus('reconnecting');
|
|
284
|
+
return;
|
|
285
|
+
}
|
|
286
|
+
let backoff = delayMs;
|
|
287
|
+
if (backoff === undefined) {
|
|
288
|
+
backoff = Math.min(maxBackoffMs, initialBackoffMs * 2 ** attempt);
|
|
289
|
+
attempt += 1;
|
|
290
|
+
}
|
|
242
291
|
const jitter = backoff * 0.25 * Math.random();
|
|
243
|
-
attempt += 1;
|
|
244
292
|
retryTimerId = setTimeout(() => {
|
|
245
293
|
retryTimerId = null;
|
|
246
294
|
void connect();
|
|
247
295
|
}, backoff + jitter);
|
|
296
|
+
// After arming: a status callback that calls reconnectNow() must find
|
|
297
|
+
// the timer to clear, or it would later fire behind a live stream.
|
|
298
|
+
setStatus('reconnecting');
|
|
248
299
|
};
|
|
249
300
|
|
|
250
301
|
const parseFrame = (rawFrame: string) => {
|
|
@@ -285,6 +336,9 @@ export function createSseSubscription(options: SseSubscriptionOptions): SseSubsc
|
|
|
285
336
|
async function connect(): Promise<void> {
|
|
286
337
|
if (closed || suspended) return;
|
|
287
338
|
const gen = ++generation;
|
|
339
|
+
stalled = false;
|
|
340
|
+
awaitingAuth = false;
|
|
341
|
+
lastConnectAt = Date.now();
|
|
288
342
|
setStatus('connecting');
|
|
289
343
|
abortController = new AbortController();
|
|
290
344
|
|
|
@@ -316,12 +370,23 @@ export function createSseSubscription(options: SseSubscriptionOptions): SseSubsc
|
|
|
316
370
|
scheduleReconnect();
|
|
317
371
|
return;
|
|
318
372
|
}
|
|
319
|
-
//
|
|
320
|
-
//
|
|
373
|
+
// x-block-layer (proxy surface block) is logged for attribution
|
|
374
|
+
// when readable — never gates the decision.
|
|
321
375
|
const blockLayer = response.headers.get('x-block-layer');
|
|
376
|
+
const blockNote = blockLayer ? ` (x-block-layer: ${blockLayer})` : '';
|
|
377
|
+
if (response.status === 401 && pauseWhenHidden) {
|
|
378
|
+
const delayMs = Math.min(AUTH_RETRY_MAX_MS, AUTH_RETRY_INITIAL_MS * 2 ** authAttempt);
|
|
379
|
+
authAttempt += 1;
|
|
380
|
+
console.warn(`[sse-subscription] 401 for ${url}${blockNote} — retrying in ~${Math.round(delayMs / 1000)}s`);
|
|
381
|
+
awaitingAuth = true;
|
|
382
|
+
scheduleReconnect(delayMs);
|
|
383
|
+
return;
|
|
384
|
+
}
|
|
322
385
|
console.warn(
|
|
323
|
-
`[sse-subscription] terminal ${response.status} for ${url}${
|
|
386
|
+
`[sse-subscription] terminal ${response.status} for ${url}${blockNote} — ${pauseWhenHidden ? 'retrying on presence' : 'not retrying'}`,
|
|
324
387
|
);
|
|
388
|
+
// Before the status callback, which may re-enter via reconnectNow().
|
|
389
|
+
stalled = pauseWhenHidden;
|
|
325
390
|
setStatus('terminal');
|
|
326
391
|
return;
|
|
327
392
|
}
|
|
@@ -332,6 +397,7 @@ export function createSseSubscription(options: SseSubscriptionOptions): SseSubsc
|
|
|
332
397
|
|
|
333
398
|
// Successful open — reset backoff, start liveness accounting.
|
|
334
399
|
attempt = 0;
|
|
400
|
+
authAttempt = 0;
|
|
335
401
|
setStatus('open');
|
|
336
402
|
armSilenceTimer();
|
|
337
403
|
// Transport open ≠ connected: require the server's `subscribed`
|
|
@@ -418,6 +484,12 @@ export function createSseSubscription(options: SseSubscriptionOptions): SseSubsc
|
|
|
418
484
|
abortController?.abort();
|
|
419
485
|
setStatus('suspended');
|
|
420
486
|
};
|
|
487
|
+
/** A person is back at the page: the moment a fixed backend or a
|
|
488
|
+
* restored permission can be noticed without a reload. */
|
|
489
|
+
const retryIfStalled = () => {
|
|
490
|
+
if (!stalled || Date.now() - lastConnectAt < PRESENCE_RETRY_MIN_INTERVAL_MS) return;
|
|
491
|
+
doReconnect();
|
|
492
|
+
};
|
|
421
493
|
const onVisibilityChange = () => {
|
|
422
494
|
if (document.visibilityState === 'hidden') {
|
|
423
495
|
if (!hiddenGraceTimerId) {
|
|
@@ -435,15 +507,27 @@ export function createSseSubscription(options: SseSubscriptionOptions): SseSubsc
|
|
|
435
507
|
if (suspended) {
|
|
436
508
|
suspended = false;
|
|
437
509
|
void connect();
|
|
510
|
+
return;
|
|
438
511
|
}
|
|
512
|
+
retryIfStalled();
|
|
439
513
|
};
|
|
440
514
|
const onOnline = () => {
|
|
441
515
|
if (!suspended) doReconnect();
|
|
442
516
|
};
|
|
517
|
+
// Only requests that carry the adapter's credentials can be rescued by a
|
|
518
|
+
// new one, and only long-lived streams ever wait out a 401. Subscribed
|
|
519
|
+
// before the DOM listeners, so a throwing host adapter leaks none of them.
|
|
520
|
+
const unsubscribeCredentials =
|
|
521
|
+
pauseWhenHidden && fetchImpl === embedAuthedFetch
|
|
522
|
+
? subscribeEmbedCredentialChange(() => {
|
|
523
|
+
if (awaitingAuth) doReconnect();
|
|
524
|
+
})
|
|
525
|
+
: null;
|
|
443
526
|
const listenersActive = pauseWhenHidden && typeof document !== 'undefined' && typeof window !== 'undefined';
|
|
444
527
|
if (listenersActive) {
|
|
445
528
|
document.addEventListener('visibilitychange', onVisibilityChange);
|
|
446
529
|
window.addEventListener('online', onOnline);
|
|
530
|
+
window.addEventListener('focus', retryIfStalled);
|
|
447
531
|
}
|
|
448
532
|
|
|
449
533
|
void connect();
|
|
@@ -454,11 +538,14 @@ export function createSseSubscription(options: SseSubscriptionOptions): SseSubsc
|
|
|
454
538
|
closed = true;
|
|
455
539
|
generation += 1;
|
|
456
540
|
clearTimers();
|
|
541
|
+
hiddenGraceTimerId = clearLifecycleTimer(hiddenGraceTimerId);
|
|
457
542
|
abortController?.abort();
|
|
458
543
|
if (listenersActive) {
|
|
459
544
|
document.removeEventListener('visibilitychange', onVisibilityChange);
|
|
460
545
|
window.removeEventListener('online', onOnline);
|
|
546
|
+
window.removeEventListener('focus', retryIfStalled);
|
|
461
547
|
}
|
|
548
|
+
unsubscribeCredentials?.();
|
|
462
549
|
setConnected(false);
|
|
463
550
|
onStatusChange?.('closed');
|
|
464
551
|
},
|