@24city/web-console 0.3.13 → 0.3.14

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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.3.14
4
+
5
+ **修复:离开页面前还在排队的访客来访和行为事件会丢**(`@24city/web-console/account`)
6
+
7
+ - 原先排队的上报只在攒满 2 秒或 20 条、或者 `pagehide` 时发出。手机上页面转入后台后可能被系统直接回收,不会再有
8
+ `pagehide`,看一眼就走的访客这一页(连同带来的推广来源)就丢了。现在页面一转入后台(`visibilitychange` 变为 hidden)
9
+ 就立即发出。在 Chrome 里模拟“转入后台约 0.2 秒后被回收”:改前 3 次全丢,改后 3 次全到;直接关标签页或跳去别的网站,
10
+ 改前改后都能送到。
11
+ - 页面关闭和转入后台时的这一批改用浏览器 fetch 的 keepalive 发出,页面关掉后请求仍会发完。请求照样经过产品 axios 客户端的
12
+ 拦截器(CSRF 头、基础路径),也不会带上 axios 自带 fetch 适配器加的 `User-Agent: axios/…`,统一中心记的浏览器和设备不受影响。
13
+ - `AccountApi.reportVisits`、`reportBehaviorEvents` 新增可选的第二个参数 `options?: ReportOptions`(`{ keepalive?: boolean }`),
14
+ `VisitorTracker.flush` 也接受它。自己实现 AccountApi 的产品不改也能编译,只是页面关闭时仍按原来的方式发送。
15
+ - 积压超过 20 条时各批同时发出,不再等上一批的回应。
16
+
3
17
  ## 0.3.13
4
18
 
5
19
  **新增:没登录访客的来访**(`@24city/web-console/account`,统一账号中心 API 1.27.0;运营在统一中心「访客运营」里看产品站点
package/README.md CHANGED
@@ -179,7 +179,8 @@ const customization: ConsoleCustomization = {
179
179
  生成完成这类关键动作以服务端为准,用 account-client 的 `Account.Track` 在业务成功后记。
180
180
 
181
181
  上报经产品自己的 `POST /api/account/events`(account-client 0.9.0 起由 ginaccount 提供,用户与空间按会话补上),
182
- 2 秒或 20 条一批;会话恢复前先排队,确认已登录才发;失败不提示,后端还没有这个接口(404)时本次会话不再上报。
182
+ 2 秒或 20 条一批;页面关闭或转入后台时,排队的立即用 keepalive 发出(页面关掉后请求仍会发完);会话恢复前先排队,
183
+ 确认已登录才发;失败不提示,后端还没有这个接口(404)时本次会话不再上报。没登录访客的来访按同样的方式发送。
183
184
 
184
185
  ### 访客来访
185
186
 
@@ -17,6 +17,13 @@ export interface VisitorPageViewInput {
17
17
  export interface StartLoginOptions {
18
18
  entry?: string;
19
19
  }
20
+ /**
21
+ * 上报的发送方式。keepalive:页面正在关闭(关标签页、跳去别的网站、切到后台),请求要在页面关掉后继续发完
22
+ * (浏览器 fetch 的 keepalive);普通请求在页面关掉后可能被浏览器取消。
23
+ */
24
+ export interface ReportOptions {
25
+ keepalive?: boolean;
26
+ }
20
27
  /** 浏览器上报的一条行为事件;用户与空间由产品服务端按会话补上(统一中心 docs/用户行为事件.md)。 */
21
28
  export interface BehaviorEventInput {
22
29
  eventId: string;
@@ -52,14 +59,15 @@ export interface AccountApi {
52
59
  claimShownPrompts?: (keys: readonly string[]) => Promise<string[]>;
53
60
  /**
54
61
  * 上报当前用户的行为事件(`POST /api/account/events`,account-client 0.9.0 起由 ginaccount 提供)。可选:
55
- * 自己实现 AccountApi 的产品不写也能编译,只是 `useTrack` 不上报。
62
+ * 自己实现 AccountApi 的产品不写也能编译,只是 `useTrack` 不上报。页面关闭时 `useTrack` 传 `{ keepalive: true }`,
63
+ * 自己实现的要让这次请求在页面关掉后仍能发完,否则离开前的最后一批会丢。
56
64
  */
57
- reportBehaviorEvents?: (events: BehaviorEventInput[]) => Promise<void>;
65
+ reportBehaviorEvents?: (events: BehaviorEventInput[], options?: ReportOptions) => Promise<void>;
58
66
  /**
59
67
  * 上报没登录访客看过的页面(`POST /api/account/visits`,account-client 0.10.0 起由 ginaccount 提供)。可选:
60
- * 自己实现 AccountApi 的产品不写也能编译,只是没登录的浏览不记。
68
+ * 自己实现 AccountApi 的产品不写也能编译,只是没登录的浏览不记。`options.keepalive` 同 `reportBehaviorEvents`。
61
69
  */
62
- reportVisits?: (pageViews: VisitorPageViewInput[]) => Promise<void>;
70
+ reportVisits?: (pageViews: VisitorPageViewInput[], options?: ReportOptions) => Promise<void>;
63
71
  }
64
72
  export declare const createAccountApi: (client: AxiosInstance, apiBaseUrl: string) => AccountApi;
65
73
  /** 会话与空间列表一起读;两边的当前空间不一致时重读一次会话,仍不一致则视为服务端状态异常。 */
@@ -1,7 +1,7 @@
1
- import { A as s, a as t, c as o, b as r, i as n, d as i, l as u, n as c, r as l, e as g, f as p, u as A, g as S, w as P } from "../chunks/logout-signal-XyvlxcEc.js";
2
- import { A as d, a as C, C as h, L as f, P as m, b as T, c as y, Q as E, R as N, S as O, d as b, T as w, U, e as _, p as v, f as F, g as R, h as x, u as B, y as I } from "../chunks/use-show-once-DQHhTzlT.js";
3
- import { A as D, a as M, b as V, E as q, F as K, P as Q, c as G, d as H, e as W, U as Y, f as X, W as j, g as z, h as J, i as Z, j as $, k as aa, l as ea, m as sa, n as ta, o as oa, p as ra, q as na, r as ia, s as ua, t as ca, u as la, v as ga, w as pa, x as Aa, y as Sa, z as Pa, B as La, C as da, D as Ca, G as ha, H as fa, I as ma, J as Ta, K as ya, L as Ea, M as Na, N as Oa, O as ba, Q as wa, R as Ua, S as _a, T as va, V as Fa, X as Ra, Y as xa, Z as Ba } from "../chunks/wallet-badge-DIJeoyjn.js";
4
- import { A as ka } from "../chunks/auth-provider-DAxku5aX.js";
1
+ import { A as s, a as t, c as o, b as r, i as n, d as i, l as u, n as c, r as l, e as g, f as p, u as A, g as S, w as P } from "../chunks/logout-signal-DtOS9Rse.js";
2
+ import { A as d, a as C, C as h, L as f, P as m, b as T, c as y, Q as E, R as N, S as O, d as b, T as w, U, e as _, p as v, f as F, g as R, h as x, u as B, y as I } from "../chunks/use-show-once-BMTl8DL7.js";
3
+ import { A as D, a as M, b as V, E as q, F as K, P as Q, c as G, d as H, e as W, U as Y, f as X, W as j, g as z, h as J, i as Z, j as $, k as aa, l as ea, m as sa, n as ta, o as oa, p as ra, q as na, r as ia, s as ua, t as ca, u as la, v as ga, w as pa, x as Aa, y as Sa, z as Pa, B as La, C as da, D as Ca, G as ha, H as fa, I as ma, J as Ta, K as ya, L as Ea, M as Na, N as Oa, O as ba, Q as wa, R as Ua, S as _a, T as va, V as Fa, X as Ra, Y as xa, Z as Ba } from "../chunks/wallet-badge-Cu2WL0RX.js";
4
+ import { A as ka } from "../chunks/auth-provider-BzxebTYE.js";
5
5
  import { notifyCustomerSessionChanged as Ma, subscribeCustomerSessionChanges as Va } from "@24city/web-runtime/session-sync";
6
6
  export {
7
7
  D as ACCOUNT_SECTIONS,
@@ -0,0 +1,7 @@
1
+ import { type AxiosAdapter } from 'axios';
2
+ /**
3
+ * 页面正在关闭时用的发送方式:请求照常经过 axios 的拦截器(CSRF 头、基础路径),最后由浏览器的 fetch 以 keepalive 发出,
4
+ * 页面关掉后请求仍会发完。不用 axios 自带的 fetch 适配器,是因为它会加上 `User-Agent: axios/…`,部分浏览器照发,
5
+ * 统一中心就把访客的浏览器和设备记错了。
6
+ */
7
+ export declare const keepaliveAdapter: AxiosAdapter;
@@ -1,4 +1,4 @@
1
- import type { BehaviorEventInput, BehaviorPropValue, VisitorPageViewInput } from './account-api';
1
+ import type { BehaviorEventInput, BehaviorPropValue, ReportOptions, VisitorPageViewInput } from './account-api';
2
2
  export interface TrackOptions {
3
3
  /** 低基数的作用对象:页面路由模板、套餐编码、弹窗名等;不放用户输入和真实 ID。 */
4
4
  target?: string;
@@ -11,14 +11,15 @@ export type Track = (name: string, options?: TrackOptions) => void;
11
11
  export declare const PAGE_VIEWED = "page.viewed";
12
12
  interface Tracker {
13
13
  track: Track;
14
- flush: () => Promise<void>;
14
+ flush: (options?: ReportOptions) => Promise<void>;
15
15
  /** 登录状态:未知时事件先排队不发;确认已登录后照常发送,确认未登录则页面浏览转给访客队列、其他事件丢掉。 */
16
16
  setSignedIn: (signedIn: boolean | undefined) => void;
17
17
  }
18
18
  /** 没登录访客的页面浏览队列。 */
19
19
  export interface VisitorTracker {
20
20
  pageView: (path: string, occurredAt?: string) => void;
21
- flush: () => Promise<void>;
21
+ /** 立即发出排队的页面浏览;`{ keepalive: true }` 用在页面马上要关的时候(例如跳去外部支付页之前)。 */
22
+ flush: (options?: ReportOptions) => Promise<void>;
22
23
  }
23
24
  /** 这次打开网页时的来源:外部来源网站和推广参数。 */
24
25
  export type VisitorLanding = Omit<VisitorPageViewInput, 'path' | 'occurredAt'>;
@@ -28,17 +29,18 @@ export type VisitorLanding = Omit<VisitorPageViewInput, 'path' | 'occurredAt'>;
28
29
  */
29
30
  export declare const readVisitorLanding: (href: string, referrer: string) => VisitorLanding | undefined;
30
31
  /**
31
- * 没登录访客的页面浏览:2 秒或满 20 条发一次;这次打开网页的第一页带上来源;产品后端还没有转发接口(404)时
32
- * 本次会话不再上报。
32
+ * 没登录访客的页面浏览:2 秒或满 20 条发一次;这次打开网页的第一页带上来源;页面关闭时把排队的用 keepalive 发出;
33
+ * 产品后端还没有转发接口(404)时本次会话不再上报。
33
34
  */
34
- export declare const createVisitorTracker: (report: (pageViews: VisitorPageViewInput[]) => Promise<void>,
35
+ export declare const createVisitorTracker: (report: (pageViews: VisitorPageViewInput[], options?: ReportOptions) => Promise<void>,
35
36
  /** 第一页带的来源;不传时用这次打开网页时读到的,传 null 表示没有。 */
36
37
  landing?: VisitorLanding | null) => VisitorTracker;
37
38
  /**
38
- * 一个账号接口一份队列:2 秒或满 20 条发一次;产品后端没有转发接口(404)时本次会话不再上报。
39
- * 不传 signedIn 时视为已登录(直接用队列的场景);useTrack 按会话恢复的结果设置。没登录时页面浏览交给 visitor。
39
+ * 一个账号接口一份队列:2 秒或满 20 条发一次;页面关闭时把排队的用 keepalive 发出;产品后端没有转发接口(404)时
40
+ * 本次会话不再上报。不传 signedIn 时视为已登录(直接用队列的场景);useTrack 按会话恢复的结果设置。
41
+ * 没登录时页面浏览交给 visitor。
40
42
  */
41
- export declare const createBehaviorTracker: (report: (events: BehaviorEventInput[]) => Promise<void>, signedIn?: boolean | undefined, visitor?: VisitorTracker) => Tracker;
43
+ export declare const createBehaviorTracker: (report: (events: BehaviorEventInput[], options?: ReportOptions) => Promise<void>, signedIn?: boolean | undefined, visitor?: VisitorTracker) => Tracker;
42
44
  /**
43
45
  * 记录当前用户的行为。已登录时上报行为事件;没登录时只记页面浏览,算访客的来访。自己实现 AccountApi 且没有
44
46
  * `reportBehaviorEvents`、`reportVisits` 的产品什么也不发。
@@ -2,7 +2,7 @@ import { jsx as U, Fragment as L } from "react/jsx-runtime";
2
2
  import { useEffect as T } from "react";
3
3
  import { useQueryClient as I } from "@tanstack/react-query";
4
4
  import { b as R } from "./context-CaVim6ZO.js";
5
- import { g as A, n as y, i as c, v as k, f as S, r as x, y as P, t as h } from "./logout-signal-XyvlxcEc.js";
5
+ import { g as A, n as y, i as c, v as k, f as S, r as x, y as P, t as h } from "./logout-signal-DtOS9Rse.js";
6
6
  import { subscribeCustomerSessionChanges as _ } from "@24city/web-runtime/session-sync";
7
7
  const z = (e) => !h(e, 401) && !h(e, 403) && !h(e, 404), F = (e, i) => (e == null ? void 0 : e.purpose) === i.purpose && e.globalUserId === i.globalUserId && e.activeSpaceId === i.activeSpaceId, H = [1e3, 2e3, 4e3], Q = 15e3, B = (e) => new Promise((i) => setTimeout(i, e)), D = ({ children: e }) => {
8
8
  const i = I(), o = A(), { accountApi: f, config: r, http: d } = R();
@@ -3,7 +3,7 @@ import { useEffect as z, useState as b } from "react";
3
3
  import { Layout as v, Button as f, Typography as Y, Space as F, Nav as $ } from "@douyinfe/semi-ui";
4
4
  import { IconSidebar as P } from "@douyinfe/semi-icons";
5
5
  import { useLocation as Q, useNavigate as q, Outlet as D } from "react-router";
6
- import { Y as J, i as V, j as X, H as Z, s as ee, f as te, W as ne, b as ae } from "./wallet-badge-DIJeoyjn.js";
6
+ import { Y as J, i as V, j as X, H as Z, s as ee, f as te, W as ne, b as ae } from "./wallet-badge-Cu2WL0RX.js";
7
7
  import { u as R, b as oe, a as se } from "./context-CaVim6ZO.js";
8
8
  import { u as le } from "./use-media-query-DvyinWNg.js";
9
9
  import { a as re } from "./scale-smFifpMm.js";
@@ -0,0 +1,434 @@
1
+ import { sanitizeInternalReturnPath as v } from "@24city/web-runtime/core/internal-path";
2
+ import { AxiosError as N } from "axios";
3
+ import { createContext as F, useSyncExternalStore as k, useContext as M } from "react";
4
+ import { summarizeCustomerError as _ } from "@24city/web-runtime/error-summary";
5
+ const T = (t) => t.includes("\\") || [...t].some((e) => {
6
+ const s = e.charCodeAt(0);
7
+ return s <= 31 || s === 127;
8
+ }), St = (t) => !T(t) && t.startsWith("/") && !t.startsWith("//") && (() => {
9
+ try {
10
+ const e = new URL(t, "https://product.invalid");
11
+ return e.origin === "https://product.invalid" && v(t, e.pathname) === t;
12
+ } catch {
13
+ return !1;
14
+ }
15
+ })(), gt = (t, e) => !T(t) && v(t, e) === t, q = (t, e) => !t || T(t) ? e : v(t, e), U = (t) => typeof t == "object" && t !== null && !Array.isArray(t), p = (t, e) => {
16
+ const s = e.data;
17
+ if (!U(s) || s.code !== 0 || !("data" in s))
18
+ throw new Error(`接口 ${t} 返回了无效响应`);
19
+ return s.data;
20
+ }, l = (t, e, s) => {
21
+ if (!U(t)) throw new Error(`接口 ${e} 字段 ${s} 无效`);
22
+ return t;
23
+ }, a = (t, e, s) => {
24
+ const r = t[e];
25
+ if (typeof r != "string" || !r.trim())
26
+ throw new Error(`接口 ${s} 字段 ${e} 无效`);
27
+ return r;
28
+ }, h = (t, e, s) => {
29
+ const r = t[e];
30
+ if (typeof r != "number" || !Number.isSafeInteger(r) || r < 0)
31
+ throw new Error(`接口 ${s} 字段 ${e} 无效`);
32
+ return r;
33
+ }, W = 60 * 1024, B = /^[a-z][a-z\d+.-]*:\/\//i, H = ({ baseURL: t, url: e = "" }) => !t || B.test(e) ? e : `${t.replace(/\/+$/, "")}/${e.replace(/^\/+/, "")}`, V = (t) => {
34
+ const e = new Headers();
35
+ for (const [s, r] of Object.entries(t.headers.toJSON(!0))) e.set(s, String(r));
36
+ return e;
37
+ }, j = (t) => {
38
+ const e = {};
39
+ return t.headers.forEach((s, r) => {
40
+ e[r] = s;
41
+ }), e;
42
+ }, D = async (t) => {
43
+ const e = typeof t.data == "string" ? t.data : t.data == null ? void 0 : JSON.stringify(t.data);
44
+ let s;
45
+ try {
46
+ s = await fetch(H(t), {
47
+ method: (t.method ?? "post").toUpperCase(),
48
+ headers: V(t),
49
+ body: e,
50
+ credentials: t.withCredentials ? "include" : "same-origin",
51
+ keepalive: e === void 0 || new TextEncoder().encode(e).length <= W
52
+ });
53
+ } catch (w) {
54
+ throw N.from(w, N.ERR_NETWORK, t);
55
+ }
56
+ const r = await s.text();
57
+ let n = r;
58
+ try {
59
+ n = r && JSON.parse(r);
60
+ } catch {
61
+ n = r;
62
+ }
63
+ const c = {
64
+ data: n,
65
+ status: s.status,
66
+ statusText: s.statusText,
67
+ headers: j(s),
68
+ config: t
69
+ };
70
+ if (!t.validateStatus || t.validateStatus(s.status)) return c;
71
+ throw new N(
72
+ `Request failed with status code ${s.status}`,
73
+ s.status >= 500 ? N.ERR_BAD_RESPONSE : N.ERR_BAD_REQUEST,
74
+ t,
75
+ void 0,
76
+ c
77
+ );
78
+ }, m = "/account", u = `${m}/session`, P = `${m}/logout`, i = `${m}/spaces`, O = `${i}/switch`, b = `${m}/profile`, g = `${m}/wallet`, $ = `${m}/entitlements`, f = `${m}/subscription`, o = `${m}/plans`, E = `${m}/shown-prompts`, G = `${m}/events`, K = `${m}/visits`, J = /^[a-z][a-z0-9_]{0,31}$/, A = (t, e, s) => {
79
+ const r = t[e];
80
+ if (r !== null && typeof r != "string")
81
+ throw new Error(`接口 ${s} 字段 ${e} 无效`);
82
+ return r;
83
+ }, y = (t, e, s) => {
84
+ const r = t[e];
85
+ if (r != null) {
86
+ if (typeof r != "string")
87
+ throw new Error(`接口 ${s} 字段 ${e} 无效`);
88
+ return r;
89
+ }
90
+ }, Y = (t, e, s) => {
91
+ const r = t[e];
92
+ return r === null ? {} : l(r, s, e);
93
+ }, Q = (t) => {
94
+ const e = l(t, P, "data"), s = y(e, "endSessionUrl", P);
95
+ if (!s) return null;
96
+ try {
97
+ return new URL(s).protocol === "https:" ? s : null;
98
+ } catch {
99
+ return null;
100
+ }
101
+ }, L = (t) => {
102
+ const e = l(t, u, "data");
103
+ if (e.purpose !== "user") throw new Error("产品用户 Web 只接受 user Purpose 会话");
104
+ return {
105
+ globalUserId: a(e, "globalUserId", u),
106
+ localUserId: h(e, "localUserId", u),
107
+ activeSpaceId: a(e, "activeSpaceId", u),
108
+ authorityId: h(e, "authorityId", u),
109
+ orgId: h(e, "orgId", u),
110
+ purpose: "user",
111
+ csrfToken: a(e, "csrfToken", u),
112
+ issuedAt: a(e, "issuedAt", u),
113
+ lastSeenAt: a(e, "lastSeenAt", u),
114
+ absoluteExpiresAt: a(e, "absoluteExpiresAt", u),
115
+ lastCentralVerifiedAt: a(e, "lastCentralVerifiedAt", u),
116
+ accountCenterUrl: a(e, "accountCenterUrl", u)
117
+ };
118
+ }, x = (t, e, s) => {
119
+ const r = l(t, e, s);
120
+ return {
121
+ id: a(r, "id", e),
122
+ entitlementCode: a(r, "entitlementCode", e),
123
+ status: y(r, "status", e),
124
+ startsAt: a(r, "startsAt", e),
125
+ expiresAt: A(r, "expiresAt", e),
126
+ metadata: Y(r, "metadata", e)
127
+ };
128
+ }, X = (t, e) => {
129
+ const s = l(t, i, `spaces[${e}]`), r = l(s.entitlementSummary, i, "entitlementSummary"), n = r.codes, c = s.entitlements;
130
+ if (!Array.isArray(n) || n.some((w) => typeof w != "string"))
131
+ throw new Error(`接口 ${i} 字段 entitlementSummary.codes 无效`);
132
+ if (!Array.isArray(c))
133
+ throw new Error(`接口 ${i} 字段 entitlements 无效`);
134
+ return {
135
+ id: a(s, "id", i),
136
+ name: a(s, "name", i),
137
+ slug: a(s, "slug", i),
138
+ type: a(s, "type", i),
139
+ role: a(s, "role", i),
140
+ status: a(s, "status", i),
141
+ membershipStatus: a(s, "membershipStatus", i),
142
+ entitlementSummary: {
143
+ activeCount: h(r, "activeCount", i),
144
+ codes: [...n]
145
+ },
146
+ entitlements: c.map(
147
+ (w, d) => x(w, i, `entitlements[${d}]`)
148
+ )
149
+ };
150
+ }, Z = (t) => {
151
+ const e = l(t, i, "data"), s = a(e, "activeSpaceId", i);
152
+ if (!Array.isArray(e.spaces)) throw new Error(`接口 ${i} 字段 spaces 无效`);
153
+ const r = e.spaces.map(X);
154
+ if (!r.some((n) => n.id === s))
155
+ throw new Error(`接口 ${i} 的当前空间不在可用空间列表中`);
156
+ return { activeSpaceId: s, spaces: r };
157
+ }, tt = (t) => {
158
+ const e = l(t, b, "data");
159
+ return { nickName: (y(e, "nickName", b) ?? "").trim() };
160
+ }, et = (t) => {
161
+ const e = l(t, g, "data"), s = (r) => {
162
+ const n = e[r];
163
+ if (typeof n != "number" || !Number.isSafeInteger(n))
164
+ throw new Error(`接口 ${g} 字段 ${r} 无效`);
165
+ return n;
166
+ };
167
+ return {
168
+ spaceId: a(e, "spaceId", g),
169
+ globalUserId: a(e, "globalUserId", g),
170
+ productCode: a(e, "productCode", g),
171
+ availablePoints: s("availablePoints"),
172
+ reservedPoints: s("reservedPoints"),
173
+ globalAvailablePoints: s("globalAvailablePoints"),
174
+ globalReservedPoints: s("globalReservedPoints"),
175
+ productAvailablePoints: s("productAvailablePoints"),
176
+ productReservedPoints: s("productReservedPoints"),
177
+ walletAvailablePoints: s("walletAvailablePoints"),
178
+ walletReservedPoints: s("walletReservedPoints"),
179
+ walletVersion: h(e, "walletVersion", g)
180
+ };
181
+ }, rt = (t) => {
182
+ if (t === null) return null;
183
+ const e = l(t, f, "data"), s = e.tier;
184
+ if (typeof s != "number" || !Number.isSafeInteger(s))
185
+ throw new Error(`接口 ${f} 字段 tier 无效`);
186
+ if (typeof e.isDefault != "boolean")
187
+ throw new Error(`接口 ${f} 字段 isDefault 无效`);
188
+ return {
189
+ subscriptionId: A(e, "subscriptionId", f),
190
+ planCode: a(e, "planCode", f),
191
+ planName: (y(e, "planName", f) ?? "").trim(),
192
+ tier: s,
193
+ isDefault: e.isDefault,
194
+ spaceType: y(e, "spaceType", f) ?? "",
195
+ currentPeriodEnd: A(e, "currentPeriodEnd", f)
196
+ };
197
+ }, st = /* @__PURE__ */ new Set(["month", "year", "one_time"]), nt = (t, e) => {
198
+ const s = l(t, o, e), r = a(s, "billingPeriod", o);
199
+ if (!st.has(r)) throw new Error(`接口 ${o} 字段 ${e}.billingPeriod 无效`);
200
+ return {
201
+ code: a(s, "code", o),
202
+ amountCents: h(s, "amountCents", o),
203
+ currency: a(s, "currency", o),
204
+ billingPeriod: r,
205
+ durationDays: h(s, "durationDays", o),
206
+ pointCycles: h(s, "pointCycles", o)
207
+ };
208
+ }, at = (t, e) => {
209
+ const s = l(t, o, e), r = s.limit;
210
+ if (r != null && (typeof r != "number" || !Number.isSafeInteger(r) || r < 0))
211
+ throw new Error(`接口 ${o} 字段 ${e}.limit 无效`);
212
+ const n = Array.isArray(s.discounts) ? s.discounts.filter((c) => typeof c == "string") : [];
213
+ return {
214
+ key: y(s, "key", o) ?? "",
215
+ name: a(s, "name", o),
216
+ description: y(s, "description", o) ?? "",
217
+ limit: typeof r == "number" ? r : null,
218
+ discounts: n
219
+ };
220
+ }, ot = (t, e) => {
221
+ const s = `data[${e}]`, r = l(t, o, s), n = a(r, "spaceType", o);
222
+ if (n !== "personal" && n !== "team") throw new Error(`接口 ${o} 字段 ${s}.spaceType 无效`);
223
+ if (typeof r.tier != "number" || !Number.isSafeInteger(r.tier)) throw new Error(`接口 ${o} 字段 ${s}.tier 无效`);
224
+ if (typeof r.isDefault != "boolean") throw new Error(`接口 ${o} 字段 ${s}.isDefault 无效`);
225
+ if (!Array.isArray(r.prices)) throw new Error(`接口 ${o} 字段 ${s}.prices 无效`);
226
+ const c = Array.isArray(r.benefits) ? r.benefits : [], w = Array.isArray(r.otherProducts) ? r.otherProducts.filter((d) => typeof d == "string" && d.trim() !== "").map((d) => d.trim()) : [];
227
+ return {
228
+ code: a(r, "code", o),
229
+ name: a(r, "name", o).trim(),
230
+ spaceType: n,
231
+ tier: r.tier,
232
+ isDefault: r.isDefault,
233
+ includedSeats: h(r, "includedSeats", o),
234
+ monthlyPoints: h(r, "monthlyPoints", o),
235
+ prices: r.prices.map((d, I) => nt(d, `${s}.prices[${I}]`)),
236
+ benefits: c.map((d, I) => at(d, `${s}.benefits[${I}]`)),
237
+ otherProducts: w
238
+ };
239
+ }, R = (t, e) => {
240
+ const s = l(t, E, "data")[e];
241
+ if (!Array.isArray(s) || s.some((r) => typeof r != "string"))
242
+ throw new Error(`接口 ${E} 字段 ${e} 无效`);
243
+ return [...s];
244
+ }, it = (t) => {
245
+ if (!Array.isArray(t)) throw new Error(`接口 ${o} 字段 data 无效`);
246
+ return t.map(ot);
247
+ }, yt = (t, e) => {
248
+ const s = e === "/" ? "" : e;
249
+ return {
250
+ async reportBehaviorEvents(r, n) {
251
+ r.length !== 0 && await t.post(G, { events: r }, n != null && n.keepalive ? { adapter: D } : void 0);
252
+ },
253
+ async reportVisits(r, n) {
254
+ r.length !== 0 && await t.post(K, { pageViews: r }, n != null && n.keepalive ? { adapter: D } : void 0);
255
+ },
256
+ startLogin(r, n, c) {
257
+ const w = q(r, n), d = c != null && c.entry && J.test(c.entry) ? `&entry=${c.entry}` : "";
258
+ return `${s}${m}/startLogin?returnPath=${encodeURIComponent(w)}${d}`;
259
+ },
260
+ async getSession() {
261
+ return L(p(u, await t.get(u)));
262
+ },
263
+ async getSpaces() {
264
+ return Z(p(i, await t.get(i)));
265
+ },
266
+ async switchSpace(r) {
267
+ const n = p(O, await t.post(O, { globalSpaceId: r }));
268
+ return L(n);
269
+ },
270
+ async getProfile() {
271
+ return tt(p(b, await t.get(b)));
272
+ },
273
+ async getWallet() {
274
+ return et(p(g, await t.get(g)));
275
+ },
276
+ async getEntitlements() {
277
+ const r = p($, await t.get($));
278
+ if (!Array.isArray(r)) throw new Error(`接口 ${$} 字段 data 无效`);
279
+ return r.map((n, c) => x(n, $, `entitlements[${c}]`));
280
+ },
281
+ async getSubscription() {
282
+ return rt(p(f, await t.get(f)));
283
+ },
284
+ async getPlans() {
285
+ return it(p(o, await t.get(o)));
286
+ },
287
+ async logout() {
288
+ const r = p(P, await t.post(P));
289
+ return { endSessionUrl: Q(r) };
290
+ },
291
+ async getShownPrompts(r) {
292
+ const n = await t.get(E, { params: { keys: r.join(",") } });
293
+ return R(p(E, n), "shown");
294
+ },
295
+ async claimShownPrompts(r) {
296
+ const n = await t.post(E, { keys: [...r] });
297
+ return R(p(E, n), "claimed");
298
+ }
299
+ };
300
+ }, Et = async (t) => {
301
+ let e = await t.getSession();
302
+ const s = await t.getSpaces();
303
+ if (s.activeSpaceId !== e.activeSpaceId && (e = await t.getSession()), s.activeSpaceId !== e.activeSpaceId)
304
+ throw new Error("产品会话与统一空间上下文不一致");
305
+ return { session: e, spaces: s.spaces };
306
+ }, Nt = (t) => t == null || !Number.isFinite(t) ? "暂无" : t >= 1e8 ? `${(Math.floor(t / 1e7) / 10).toFixed(1)}亿` : t >= 1e4 ? `${(Math.floor(t / 1e3) / 10).toFixed(1)}万` : t.toLocaleString("zh-CN"), $t = (t) => t.toLocaleString("zh-CN", { maximumFractionDigits: 0 }), Pt = (t) => t > 0 && t < 0.01 ? "<0.01" : t.toLocaleString("zh-CN", { maximumFractionDigits: 2 }), bt = (t) => t ? `¥${(t / 100).toLocaleString("zh-CN", { minimumFractionDigits: 2, maximumFractionDigits: 2 })}` : "暂无", It = (t) => {
307
+ if (t === void 0 || t <= 0) return "";
308
+ const e = Math.floor(t / 60), s = Math.floor(t % 60);
309
+ return `${e}:${String(s).padStart(2, "0")}`;
310
+ }, At = (t) => {
311
+ if (t === void 0 || t <= 0) return "暂无";
312
+ const e = Math.floor(t / 3600), s = Math.floor(t % 3600 / 60), r = t % 60;
313
+ return e > 0 ? `${e}小时${s}分` : s > 0 ? `${s}分${r}秒` : `${r}秒`;
314
+ }, vt = (t) => {
315
+ const e = new Date(t);
316
+ return Number.isNaN(e.getTime()) ? "暂无" : new Intl.DateTimeFormat("zh-CN", { dateStyle: "short", timeStyle: "short" }).format(e);
317
+ }, Tt = (t) => {
318
+ if (!t) return "长期有效";
319
+ const e = new Date(t);
320
+ return Number.isNaN(e.getTime()) ? "暂无" : new Intl.DateTimeFormat("zh-CN", { dateStyle: "medium" }).format(e);
321
+ }, ct = () => ({
322
+ session: null,
323
+ spaces: [],
324
+ bootstrapped: !1,
325
+ serviceUnavailable: !1
326
+ }), Ct = () => {
327
+ let t = ct();
328
+ const e = /* @__PURE__ */ new Set(), s = (r) => {
329
+ t = r, e.forEach((n) => n());
330
+ };
331
+ return {
332
+ subscribe(r) {
333
+ return e.add(r), () => e.delete(r);
334
+ },
335
+ getState: () => t,
336
+ getCsrfToken: () => {
337
+ var r;
338
+ return ((r = t.session) == null ? void 0 : r.csrfToken) ?? null;
339
+ },
340
+ setContext(r) {
341
+ s({ session: r.session, spaces: [...r.spaces], bootstrapped: !0, serviceUnavailable: !1 });
342
+ },
343
+ setBootstrapping() {
344
+ s({ ...t, bootstrapped: !1, serviceUnavailable: !1 });
345
+ },
346
+ clear(r = {}) {
347
+ s({ session: null, spaces: [], bootstrapped: !0, serviceUnavailable: r.unavailable ?? !1 });
348
+ }
349
+ };
350
+ }, z = F(null), Dt = z.Provider, ut = () => {
351
+ const t = M(z);
352
+ if (!t) throw new Error("AuthStoreProvider 尚未初始化");
353
+ return t;
354
+ }, Ot = () => {
355
+ const t = ut();
356
+ return k(t.subscribe, t.getState, t.getState);
357
+ }, Lt = (t) => t instanceof Error && t.message.trim() ? t.message : "请稍后重试;如问题持续,请联系管理员。", Rt = (t, e) => _(t).status === e, _t = (t) => {
358
+ const { category: e, status: s } = _(t);
359
+ return e === "network" || e === "timeout" || s === 502 || s === 503 || s === 504;
360
+ }, C = "24city.console.logout-at", lt = 15e3;
361
+ let S = null;
362
+ const dt = () => {
363
+ try {
364
+ return Number(window.localStorage.getItem(C) ?? Number.NaN);
365
+ } catch {
366
+ return Number.NaN;
367
+ }
368
+ };
369
+ function Ut(t = Date.now()) {
370
+ try {
371
+ window.localStorage.setItem(C, String(t));
372
+ } catch {
373
+ }
374
+ }
375
+ function mt() {
376
+ try {
377
+ window.localStorage.removeItem(C);
378
+ } catch {
379
+ }
380
+ }
381
+ function xt() {
382
+ S = "leaving";
383
+ }
384
+ function zt() {
385
+ return S === "leaving";
386
+ }
387
+ function Ft(t = Date.now()) {
388
+ if (S === "leaving") return !1;
389
+ const e = t - dt();
390
+ return e >= 0 && e < lt && (S = "logged-out"), S === "logged-out";
391
+ }
392
+ function kt() {
393
+ return S === "logged-out";
394
+ }
395
+ function Mt() {
396
+ S === "logged-out" && (S = null);
397
+ }
398
+ function qt() {
399
+ S = null, mt();
400
+ }
401
+ export {
402
+ Dt as A,
403
+ l as B,
404
+ a as C,
405
+ q as D,
406
+ Lt as E,
407
+ p as F,
408
+ Ut as a,
409
+ Ct as b,
410
+ yt as c,
411
+ kt as d,
412
+ qt as e,
413
+ Et as f,
414
+ ut as g,
415
+ Pt as h,
416
+ zt as i,
417
+ It as j,
418
+ Tt as k,
419
+ xt as l,
420
+ vt as m,
421
+ Ft as n,
422
+ At as o,
423
+ Nt as p,
424
+ $t as q,
425
+ Mt as r,
426
+ bt as s,
427
+ Rt as t,
428
+ Ot as u,
429
+ gt as v,
430
+ mt as w,
431
+ St as x,
432
+ _t as y,
433
+ h as z
434
+ };
@@ -2,8 +2,8 @@ import { jsx as t } from "react/jsx-runtime";
2
2
  import { QueryClient as c, QueryClientProvider as l } from "@tanstack/react-query";
3
3
  import { useMemo as i } from "react";
4
4
  import { CustomerRuntimeConfigProvider as f } from "@24city/web-runtime/runtime-config-provider";
5
- import { A as d } from "./auth-provider-DAxku5aX.js";
6
- import { b as m, A as p } from "./logout-signal-XyvlxcEc.js";
5
+ import { A as d } from "./auth-provider-BzxebTYE.js";
6
+ import { b as m, A as p } from "./logout-signal-DtOS9Rse.js";
7
7
  import { U as C, E as y } from "./unsupported-browser-Dwq1mNRy.js";
8
8
  import { C as h } from "./context-CaVim6ZO.js";
9
9
  import { parseCustomerRuntimeConfig as R, loadCustomerRuntimeConfig as v } from "@24city/web-runtime/core/runtime-config";
@@ -4,8 +4,8 @@ import { IconExternalOpen as Se, IconGift as He, IconRefresh as Pe, IconLock as
4
4
  import { useParams as et, useNavigate as oe, useLocation as ce, Navigate as le } from "react-router";
5
5
  import { S as tt, F as ae, e as q, c as nt } from "./page-YBG0dEN1.js";
6
6
  import { u as Q, a as D, b as R } from "./context-CaVim6ZO.js";
7
- import { q as M, m as at, u as de, D as $e, i as st, d as ge, r as fe } from "./logout-signal-XyvlxcEc.js";
8
- import { M as J, N as ke, u as W, p as it, O as Le, q as se, Y as Te, V as Ie, k as xe, v as he, h as G, r as Ee, G as Ae, D as rt, o as ot, H as ct, B as lt, R as dt, S as ht, t as mt, j as ut, F as pt, w as ze, J as _t, K as gt, T as ft, C as Nt } from "./wallet-badge-DIJeoyjn.js";
7
+ import { q as M, m as at, u as de, D as $e, i as st, d as ge, r as fe } from "./logout-signal-DtOS9Rse.js";
8
+ import { M as J, N as ke, u as W, p as it, O as Le, q as se, Y as Te, V as Ie, k as xe, v as he, h as G, r as Ee, G as Ae, D as rt, o as ot, H as ct, B as lt, R as dt, S as ht, t as mt, j as ut, F as pt, w as ze, J as _t, K as gt, T as ft, C as Nt } from "./wallet-badge-Cu2WL0RX.js";
9
9
  import { L as me } from "./link-button-PqZcqU6s.js";
10
10
  import { useState as bt, useRef as Y, useEffect as X, useSyncExternalStore as yt, useCallback as Ne } from "react";
11
11
  const vt = {