@24city/web-console 0.3.10 → 0.3.12

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.
@@ -0,0 +1,385 @@
1
+ import { sanitizeInternalReturnPath as A } from "@24city/web-runtime/core/internal-path";
2
+ import { createContext as x, useSyncExternalStore as F, useContext as z } from "react";
3
+ import { summarizeCustomerError as O } from "@24city/web-runtime/error-summary";
4
+ const v = (t) => t.includes("\\") || [...t].some((e) => {
5
+ const s = e.charCodeAt(0);
6
+ return s <= 31 || s === 127;
7
+ }), it = (t) => !v(t) && t.startsWith("/") && !t.startsWith("//") && (() => {
8
+ try {
9
+ const e = new URL(t, "https://product.invalid");
10
+ return e.origin === "https://product.invalid" && A(t, e.pathname) === t;
11
+ } catch {
12
+ return !1;
13
+ }
14
+ })(), ct = (t, e) => !v(t) && A(t, e) === t, M = (t, e) => !t || v(t) ? e : A(t, e), U = (t) => typeof t == "object" && t !== null && !Array.isArray(t), l = (t, e) => {
15
+ const s = e.data;
16
+ if (!U(s) || s.code !== 0 || !("data" in s))
17
+ throw new Error(`接口 ${t} 返回了无效响应`);
18
+ return s.data;
19
+ }, u = (t, e, s) => {
20
+ if (!U(t)) throw new Error(`接口 ${e} 字段 ${s} 无效`);
21
+ return t;
22
+ }, o = (t, e, s) => {
23
+ const r = t[e];
24
+ if (typeof r != "string" || !r.trim())
25
+ throw new Error(`接口 ${s} 字段 ${e} 无效`);
26
+ return r;
27
+ }, g = (t, e, s) => {
28
+ const r = t[e];
29
+ if (typeof r != "number" || !Number.isSafeInteger(r) || r < 0)
30
+ throw new Error(`接口 ${s} 字段 ${e} 无效`);
31
+ return r;
32
+ }, d = "/account", c = `${d}/session`, E = `${d}/logout`, i = `${d}/spaces`, T = `${i}/switch`, $ = `${d}/profile`, h = `${d}/wallet`, P = `${d}/entitlements`, f = `${d}/subscription`, a = `${d}/plans`, y = `${d}/shown-prompts`, W = `${d}/events`, I = (t, e, s) => {
33
+ const r = t[e];
34
+ if (r !== null && typeof r != "string")
35
+ throw new Error(`接口 ${s} 字段 ${e} 无效`);
36
+ return r;
37
+ }, S = (t, e, s) => {
38
+ const r = t[e];
39
+ if (r != null) {
40
+ if (typeof r != "string")
41
+ throw new Error(`接口 ${s} 字段 ${e} 无效`);
42
+ return r;
43
+ }
44
+ }, k = (t, e, s) => {
45
+ const r = t[e];
46
+ return r === null ? {} : u(r, s, e);
47
+ }, q = (t) => {
48
+ const e = u(t, E, "data"), s = S(e, "endSessionUrl", E);
49
+ if (!s) return null;
50
+ try {
51
+ return new URL(s).protocol === "https:" ? s : null;
52
+ } catch {
53
+ return null;
54
+ }
55
+ }, D = (t) => {
56
+ const e = u(t, c, "data");
57
+ if (e.purpose !== "user") throw new Error("产品用户 Web 只接受 user Purpose 会话");
58
+ return {
59
+ globalUserId: o(e, "globalUserId", c),
60
+ localUserId: g(e, "localUserId", c),
61
+ activeSpaceId: o(e, "activeSpaceId", c),
62
+ authorityId: g(e, "authorityId", c),
63
+ orgId: g(e, "orgId", c),
64
+ purpose: "user",
65
+ csrfToken: o(e, "csrfToken", c),
66
+ issuedAt: o(e, "issuedAt", c),
67
+ lastSeenAt: o(e, "lastSeenAt", c),
68
+ absoluteExpiresAt: o(e, "absoluteExpiresAt", c),
69
+ lastCentralVerifiedAt: o(e, "lastCentralVerifiedAt", c),
70
+ accountCenterUrl: o(e, "accountCenterUrl", c)
71
+ };
72
+ }, R = (t, e, s) => {
73
+ const r = u(t, e, s);
74
+ return {
75
+ id: o(r, "id", e),
76
+ entitlementCode: o(r, "entitlementCode", e),
77
+ status: S(r, "status", e),
78
+ startsAt: o(r, "startsAt", e),
79
+ expiresAt: I(r, "expiresAt", e),
80
+ metadata: k(r, "metadata", e)
81
+ };
82
+ }, B = (t, e) => {
83
+ const s = u(t, i, `spaces[${e}]`), r = u(s.entitlementSummary, i, "entitlementSummary"), n = r.codes, m = s.entitlements;
84
+ if (!Array.isArray(n) || n.some((b) => typeof b != "string"))
85
+ throw new Error(`接口 ${i} 字段 entitlementSummary.codes 无效`);
86
+ if (!Array.isArray(m))
87
+ throw new Error(`接口 ${i} 字段 entitlements 无效`);
88
+ return {
89
+ id: o(s, "id", i),
90
+ name: o(s, "name", i),
91
+ slug: o(s, "slug", i),
92
+ type: o(s, "type", i),
93
+ role: o(s, "role", i),
94
+ status: o(s, "status", i),
95
+ membershipStatus: o(s, "membershipStatus", i),
96
+ entitlementSummary: {
97
+ activeCount: g(r, "activeCount", i),
98
+ codes: [...n]
99
+ },
100
+ entitlements: m.map(
101
+ (b, p) => R(b, i, `entitlements[${p}]`)
102
+ )
103
+ };
104
+ }, V = (t) => {
105
+ const e = u(t, i, "data"), s = o(e, "activeSpaceId", i);
106
+ if (!Array.isArray(e.spaces)) throw new Error(`接口 ${i} 字段 spaces 无效`);
107
+ const r = e.spaces.map(B);
108
+ if (!r.some((n) => n.id === s))
109
+ throw new Error(`接口 ${i} 的当前空间不在可用空间列表中`);
110
+ return { activeSpaceId: s, spaces: r };
111
+ }, H = (t) => {
112
+ const e = u(t, $, "data");
113
+ return { nickName: (S(e, "nickName", $) ?? "").trim() };
114
+ }, j = (t) => {
115
+ const e = u(t, h, "data"), s = (r) => {
116
+ const n = e[r];
117
+ if (typeof n != "number" || !Number.isSafeInteger(n))
118
+ throw new Error(`接口 ${h} 字段 ${r} 无效`);
119
+ return n;
120
+ };
121
+ return {
122
+ spaceId: o(e, "spaceId", h),
123
+ globalUserId: o(e, "globalUserId", h),
124
+ productCode: o(e, "productCode", h),
125
+ availablePoints: s("availablePoints"),
126
+ reservedPoints: s("reservedPoints"),
127
+ globalAvailablePoints: s("globalAvailablePoints"),
128
+ globalReservedPoints: s("globalReservedPoints"),
129
+ productAvailablePoints: s("productAvailablePoints"),
130
+ productReservedPoints: s("productReservedPoints"),
131
+ walletAvailablePoints: s("walletAvailablePoints"),
132
+ walletReservedPoints: s("walletReservedPoints"),
133
+ walletVersion: g(e, "walletVersion", h)
134
+ };
135
+ }, G = (t) => {
136
+ if (t === null) return null;
137
+ const e = u(t, f, "data"), s = e.tier;
138
+ if (typeof s != "number" || !Number.isSafeInteger(s))
139
+ throw new Error(`接口 ${f} 字段 tier 无效`);
140
+ if (typeof e.isDefault != "boolean")
141
+ throw new Error(`接口 ${f} 字段 isDefault 无效`);
142
+ return {
143
+ subscriptionId: I(e, "subscriptionId", f),
144
+ planCode: o(e, "planCode", f),
145
+ planName: (S(e, "planName", f) ?? "").trim(),
146
+ tier: s,
147
+ isDefault: e.isDefault,
148
+ spaceType: S(e, "spaceType", f) ?? "",
149
+ currentPeriodEnd: I(e, "currentPeriodEnd", f)
150
+ };
151
+ }, K = /* @__PURE__ */ new Set(["month", "year", "one_time"]), X = (t, e) => {
152
+ const s = u(t, a, e), r = o(s, "billingPeriod", a);
153
+ if (!K.has(r)) throw new Error(`接口 ${a} 字段 ${e}.billingPeriod 无效`);
154
+ return {
155
+ code: o(s, "code", a),
156
+ amountCents: g(s, "amountCents", a),
157
+ currency: o(s, "currency", a),
158
+ billingPeriod: r,
159
+ durationDays: g(s, "durationDays", a),
160
+ pointCycles: g(s, "pointCycles", a)
161
+ };
162
+ }, Y = (t, e) => {
163
+ const s = u(t, a, e), r = s.limit;
164
+ if (r != null && (typeof r != "number" || !Number.isSafeInteger(r) || r < 0))
165
+ throw new Error(`接口 ${a} 字段 ${e}.limit 无效`);
166
+ const n = Array.isArray(s.discounts) ? s.discounts.filter((m) => typeof m == "string") : [];
167
+ return {
168
+ key: S(s, "key", a) ?? "",
169
+ name: o(s, "name", a),
170
+ description: S(s, "description", a) ?? "",
171
+ limit: typeof r == "number" ? r : null,
172
+ discounts: n
173
+ };
174
+ }, J = (t, e) => {
175
+ const s = `data[${e}]`, r = u(t, a, s), n = o(r, "spaceType", a);
176
+ if (n !== "personal" && n !== "team") throw new Error(`接口 ${a} 字段 ${s}.spaceType 无效`);
177
+ if (typeof r.tier != "number" || !Number.isSafeInteger(r.tier)) throw new Error(`接口 ${a} 字段 ${s}.tier 无效`);
178
+ if (typeof r.isDefault != "boolean") throw new Error(`接口 ${a} 字段 ${s}.isDefault 无效`);
179
+ if (!Array.isArray(r.prices)) throw new Error(`接口 ${a} 字段 ${s}.prices 无效`);
180
+ const m = Array.isArray(r.benefits) ? r.benefits : [], b = Array.isArray(r.otherProducts) ? r.otherProducts.filter((p) => typeof p == "string" && p.trim() !== "").map((p) => p.trim()) : [];
181
+ return {
182
+ code: o(r, "code", a),
183
+ name: o(r, "name", a).trim(),
184
+ spaceType: n,
185
+ tier: r.tier,
186
+ isDefault: r.isDefault,
187
+ includedSeats: g(r, "includedSeats", a),
188
+ monthlyPoints: g(r, "monthlyPoints", a),
189
+ prices: r.prices.map((p, N) => X(p, `${s}.prices[${N}]`)),
190
+ benefits: m.map((p, N) => Y(p, `${s}.benefits[${N}]`)),
191
+ otherProducts: b
192
+ };
193
+ }, L = (t, e) => {
194
+ const s = u(t, y, "data")[e];
195
+ if (!Array.isArray(s) || s.some((r) => typeof r != "string"))
196
+ throw new Error(`接口 ${y} 字段 ${e} 无效`);
197
+ return [...s];
198
+ }, Q = (t) => {
199
+ if (!Array.isArray(t)) throw new Error(`接口 ${a} 字段 data 无效`);
200
+ return t.map(J);
201
+ }, ut = (t, e) => {
202
+ const s = e === "/" ? "" : e;
203
+ return {
204
+ async reportBehaviorEvents(r) {
205
+ r.length !== 0 && await t.post(W, { events: r });
206
+ },
207
+ startLogin(r, n) {
208
+ const m = M(r, n);
209
+ return `${s}${d}/startLogin?returnPath=${encodeURIComponent(m)}`;
210
+ },
211
+ async getSession() {
212
+ return D(l(c, await t.get(c)));
213
+ },
214
+ async getSpaces() {
215
+ return V(l(i, await t.get(i)));
216
+ },
217
+ async switchSpace(r) {
218
+ const n = l(T, await t.post(T, { globalSpaceId: r }));
219
+ return D(n);
220
+ },
221
+ async getProfile() {
222
+ return H(l($, await t.get($)));
223
+ },
224
+ async getWallet() {
225
+ return j(l(h, await t.get(h)));
226
+ },
227
+ async getEntitlements() {
228
+ const r = l(P, await t.get(P));
229
+ if (!Array.isArray(r)) throw new Error(`接口 ${P} 字段 data 无效`);
230
+ return r.map((n, m) => R(n, P, `entitlements[${m}]`));
231
+ },
232
+ async getSubscription() {
233
+ return G(l(f, await t.get(f)));
234
+ },
235
+ async getPlans() {
236
+ return Q(l(a, await t.get(a)));
237
+ },
238
+ async logout() {
239
+ const r = l(E, await t.post(E));
240
+ return { endSessionUrl: q(r) };
241
+ },
242
+ async getShownPrompts(r) {
243
+ const n = await t.get(y, { params: { keys: r.join(",") } });
244
+ return L(l(y, n), "shown");
245
+ },
246
+ async claimShownPrompts(r) {
247
+ const n = await t.post(y, { keys: [...r] });
248
+ return L(l(y, n), "claimed");
249
+ }
250
+ };
251
+ }, lt = async (t) => {
252
+ let e = await t.getSession();
253
+ const s = await t.getSpaces();
254
+ if (s.activeSpaceId !== e.activeSpaceId && (e = await t.getSession()), s.activeSpaceId !== e.activeSpaceId)
255
+ throw new Error("产品会话与统一空间上下文不一致");
256
+ return { session: e, spaces: s.spaces };
257
+ }, dt = (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"), mt = (t) => t.toLocaleString("zh-CN", { maximumFractionDigits: 0 }), pt = (t) => t > 0 && t < 0.01 ? "<0.01" : t.toLocaleString("zh-CN", { maximumFractionDigits: 2 }), ft = (t) => t ? `¥${(t / 100).toLocaleString("zh-CN", { minimumFractionDigits: 2, maximumFractionDigits: 2 })}` : "暂无", gt = (t) => {
258
+ if (t === void 0 || t <= 0) return "";
259
+ const e = Math.floor(t / 60), s = Math.floor(t % 60);
260
+ return `${e}:${String(s).padStart(2, "0")}`;
261
+ }, wt = (t) => {
262
+ if (t === void 0 || t <= 0) return "暂无";
263
+ const e = Math.floor(t / 3600), s = Math.floor(t % 3600 / 60), r = t % 60;
264
+ return e > 0 ? `${e}小时${s}分` : s > 0 ? `${s}分${r}秒` : `${r}秒`;
265
+ }, ht = (t) => {
266
+ const e = new Date(t);
267
+ return Number.isNaN(e.getTime()) ? "暂无" : new Intl.DateTimeFormat("zh-CN", { dateStyle: "short", timeStyle: "short" }).format(e);
268
+ }, St = (t) => {
269
+ if (!t) return "长期有效";
270
+ const e = new Date(t);
271
+ return Number.isNaN(e.getTime()) ? "暂无" : new Intl.DateTimeFormat("zh-CN", { dateStyle: "medium" }).format(e);
272
+ }, Z = () => ({
273
+ session: null,
274
+ spaces: [],
275
+ bootstrapped: !1,
276
+ serviceUnavailable: !1
277
+ }), yt = () => {
278
+ let t = Z();
279
+ const e = /* @__PURE__ */ new Set(), s = (r) => {
280
+ t = r, e.forEach((n) => n());
281
+ };
282
+ return {
283
+ subscribe(r) {
284
+ return e.add(r), () => e.delete(r);
285
+ },
286
+ getState: () => t,
287
+ getCsrfToken: () => {
288
+ var r;
289
+ return ((r = t.session) == null ? void 0 : r.csrfToken) ?? null;
290
+ },
291
+ setContext(r) {
292
+ s({ session: r.session, spaces: [...r.spaces], bootstrapped: !0, serviceUnavailable: !1 });
293
+ },
294
+ setBootstrapping() {
295
+ s({ ...t, bootstrapped: !1, serviceUnavailable: !1 });
296
+ },
297
+ clear(r = {}) {
298
+ s({ session: null, spaces: [], bootstrapped: !0, serviceUnavailable: r.unavailable ?? !1 });
299
+ }
300
+ };
301
+ }, _ = x(null), bt = _.Provider, tt = () => {
302
+ const t = z(_);
303
+ if (!t) throw new Error("AuthStoreProvider 尚未初始化");
304
+ return t;
305
+ }, Pt = () => {
306
+ const t = tt();
307
+ return F(t.subscribe, t.getState, t.getState);
308
+ }, Et = (t) => t instanceof Error && t.message.trim() ? t.message : "请稍后重试;如问题持续,请联系管理员。", $t = (t, e) => O(t).status === e, Nt = (t) => {
309
+ const { category: e, status: s } = O(t);
310
+ return e === "network" || e === "timeout" || s === 502 || s === 503 || s === 504;
311
+ }, C = "24city.console.logout-at", et = 15e3;
312
+ let w = null;
313
+ const rt = () => {
314
+ try {
315
+ return Number(window.localStorage.getItem(C) ?? Number.NaN);
316
+ } catch {
317
+ return Number.NaN;
318
+ }
319
+ };
320
+ function It(t = Date.now()) {
321
+ try {
322
+ window.localStorage.setItem(C, String(t));
323
+ } catch {
324
+ }
325
+ }
326
+ function st() {
327
+ try {
328
+ window.localStorage.removeItem(C);
329
+ } catch {
330
+ }
331
+ }
332
+ function At() {
333
+ w = "leaving";
334
+ }
335
+ function vt() {
336
+ return w === "leaving";
337
+ }
338
+ function Ct(t = Date.now()) {
339
+ if (w === "leaving") return !1;
340
+ const e = t - rt();
341
+ return e >= 0 && e < et && (w = "logged-out"), w === "logged-out";
342
+ }
343
+ function Tt() {
344
+ return w === "logged-out";
345
+ }
346
+ function Dt() {
347
+ w === "logged-out" && (w = null);
348
+ }
349
+ function Lt() {
350
+ w = null, st();
351
+ }
352
+ export {
353
+ bt as A,
354
+ u as B,
355
+ o as C,
356
+ M as D,
357
+ Et as E,
358
+ l as F,
359
+ It as a,
360
+ yt as b,
361
+ ut as c,
362
+ Tt as d,
363
+ Lt as e,
364
+ lt as f,
365
+ tt as g,
366
+ pt as h,
367
+ vt as i,
368
+ gt as j,
369
+ St as k,
370
+ At as l,
371
+ ht as m,
372
+ Ct as n,
373
+ wt as o,
374
+ dt as p,
375
+ mt as q,
376
+ Dt as r,
377
+ ft as s,
378
+ $t as t,
379
+ Pt as u,
380
+ ct as v,
381
+ st as w,
382
+ it as x,
383
+ Nt as y,
384
+ g as z
385
+ };
@@ -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-7FOj7Y84.js";
6
- import { b as m, A as p } from "./logout-signal-CLdquzzn.js";
5
+ import { A as d } from "./auth-provider-Cwib6lRM.js";
6
+ import { b as m, A as p } from "./logout-signal-qvHorCCF.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";