mantur-components 0.1.14-beta.2 → 0.1.14-beta.4
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/README.md +28 -2
- package/dist/api.d.ts +16 -0
- package/dist/billing.d.ts +14 -0
- package/dist/header/components/PointsDetailModal.d.ts +2 -1
- package/dist/header/components/UserMenu.d.ts +2 -1
- package/dist/index.d.ts +6 -2
- package/dist/mantur-components.js +903 -737
- package/dist/mantur-components.umd.cjs +3 -3
- package/dist/posthog.d.ts +4 -0
- package/dist/recharge-config-store.d.ts +6 -0
- package/dist/types.d.ts +5 -0
- package/package.json +5 -1
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ npm install mantur-components
|
|
|
11
11
|
需要宿主项目提供以下 peer dependencies:
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
|
-
npm install react react-dom @arco-design/web-react next-themes react-i18next
|
|
14
|
+
npm install react react-dom @arco-design/web-react next-themes react-i18next posthog-js @posthog/react
|
|
15
15
|
```
|
|
16
16
|
|
|
17
17
|
`next-themes` 用于组件库内置的 `ThemeSwitch`,它不是 Next.js 框架本身,普通 React/Vite 宿主也可以使用。
|
|
@@ -26,7 +26,7 @@ npm install react react-dom @arco-design/web-react next-themes react-i18next
|
|
|
26
26
|
- 获取当前团队
|
|
27
27
|
- 切换团队
|
|
28
28
|
- 获取用户积分
|
|
29
|
-
-
|
|
29
|
+
- 查询充值开关,开启时展示充值积分入口(固定套餐和自定义金额)
|
|
30
30
|
- 个人资料更新
|
|
31
31
|
- 退出登录
|
|
32
32
|
- 语言切换
|
|
@@ -149,12 +149,32 @@ Stripe publishable key 可以通过 `ManturHeader` 的 `stripePublishableKey`
|
|
|
149
149
|
window.__MANTUR_COMPONENTS_STRIPE_PUBLISHABLE_KEY__ = "pk_test_xxx";
|
|
150
150
|
```
|
|
151
151
|
|
|
152
|
+
## PostHog
|
|
153
|
+
|
|
154
|
+
组件库不会单独初始化 PostHog,宿主项目需要在应用入口初始化 `posthog-js` 并挂载 `PostHogProvider`。`ManturHeader` 会通过 `@posthog/react` 复用宿主的 PostHog 实例,在 Header 内部关键交互上自动发送组件级事件,例如团队切换、用户菜单打开、充值入口点击、订单创建和 Stripe 支付成功。
|
|
155
|
+
|
|
156
|
+
如果宿主没有初始化 PostHog,组件库埋点会自动跳过,不影响组件渲染和业务流程。
|
|
157
|
+
|
|
158
|
+
组件库也导出 `captureManturComponentEvent()`,用于组件库外部复用同一套组件事件属性:
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
import { captureManturComponentEvent } from "mantur-components";
|
|
162
|
+
|
|
163
|
+
captureManturComponentEvent("mantur_header_recharge_open", {
|
|
164
|
+
app_name: import.meta.env.VITE_APP_NAME,
|
|
165
|
+
entry: "custom_button",
|
|
166
|
+
});
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
所有组件库事件都会自动补充 `component_library: "mantur-components"`。
|
|
170
|
+
|
|
152
171
|
## Billing API
|
|
153
172
|
|
|
154
173
|
组件库按 `mantur-billing` 用户端接口导出以下 helper:
|
|
155
174
|
|
|
156
175
|
```ts
|
|
157
176
|
import {
|
|
177
|
+
ensureManturBalanceEnough,
|
|
158
178
|
cancelManturRechargeOrder,
|
|
159
179
|
createManturRechargeOrder,
|
|
160
180
|
getManturBillingAccount,
|
|
@@ -162,15 +182,21 @@ import {
|
|
|
162
182
|
getManturBillingPackages,
|
|
163
183
|
getManturPricingChargePoint,
|
|
164
184
|
getManturPricingChargePoints,
|
|
185
|
+
getManturRechargeConfig,
|
|
165
186
|
getManturRechargeOrder,
|
|
187
|
+
refreshManturRechargeConfig,
|
|
166
188
|
MANTUR_RECHARGE_ORDER_CREATED_EVENT,
|
|
167
189
|
} from "mantur-components";
|
|
168
190
|
```
|
|
169
191
|
|
|
192
|
+
`ManturHeader` 挂载后会调用 `refreshManturRechargeConfig()` 拉取 `/billing/recharge/config`,并把结果保存在组件库内部状态中;只有接口返回 `enabled: true` 时,用户菜单和积分明细弹窗才展示“去充值”按钮。用户打开菜单时也会刷新一次充值开关,避免按钮状态长期停留在旧值。
|
|
193
|
+
|
|
170
194
|
充值面板打开时会调用 `getManturBillingPackages()` 拉取 `/billing/packages`;点击支付时会调用 `createManturRechargeOrder()` 创建 `/billing/recharge/orders`,请求体传 `packageId` 或 `customAmount`,并固定传 `uiMode: "elements"`。请求体还会补齐 `app` 和 `redirect`:`app` 优先取 `ManturHeader` 的 `appName` prop,建议宿主传 `import.meta.env.VITE_APP_NAME`;未传时回退到 `window.__MANTUR_APP_NAME__` 或组件库内可读取的 `VITE_APP_NAME`;本地开发若没有这些配置,会用当前端口兜底识别应用(`:82` creative-agent、`:83` production-agent、`:81` traffic-engine、`:84` distribution-matrix)。`redirect` 与路由拦截器一致,只取当前页面的 `pathname + search + hash`,不拼接协议、域名或开发端口。订单创建成功后会触发浏览器事件 `mantur-recharge-order-created`,`detail` 为后端返回的订单信息。
|
|
171
195
|
|
|
172
196
|
积分明细弹窗打开后会调用 `getManturBillingLedger()` 拉取 `/billing/accounts/me/ledger`,并根据“获得/消耗”、来源和日期范围筛选传递 `directions`、`bizTypes`、`fromTime`、`toTime`,分页总数使用接口返回的 `total`。
|
|
173
197
|
|
|
198
|
+
业务页面在真正发起扣款前可以调用 `ensureManturBalanceEnough(deductPoints)`。该函数每次都会实时查询 `/billing/accounts/me` 获取当前余额;余额充足时返回 `enough: true`,余额不足时会刷新 `/billing/recharge/config` 并弹窗引导:充值开关开启时按钮为“去充值”,点击后打开组件库 Header 的充值弹窗;充值开关关闭时按钮为“联系管理员”。如果只需要拿校验结果不弹窗,可以传 `{ showModal: false }`。
|
|
199
|
+
|
|
174
200
|
后端按 Stripe Checkout Elements 要求返回 `clientSecret` 后,`ManturHeader` 会在支付弹窗中挂载 `CheckoutElementsProvider`、`ContactDetailsElement` 和 `PaymentElement`,提交时调用 `checkout.confirm({ redirect: "if_required" })`。后端创建 Checkout Session 时必须使用 `ui_mode="elements"` 或 `ui_mode="custom"`;如果仍创建 `ui_mode="embedded"` 的 Session,Stripe 会拒绝 `initCheckoutElementsSdk`。支付成功后组件库会关闭支付弹窗并刷新积分;用户主动关闭支付弹窗时会先调用 `cancelManturRechargeOrder()` 请求 `/billing/recharge/orders/{orderNo}/cancel`,然后再关闭弹窗。组件库仍兼容旧字段名 `stripeClientSecret`,但优先读取 `clientSecret`。
|
|
175
201
|
|
|
176
202
|
如果支付方式需要跳出授权,后端的 Stripe return_url 会回到 `front-main` 的 `/pay-callback?app=...&redirect=...`,`pay-callback` 会读取这两个参数并跳回原应用的 `redirect` 路由。
|
package/dist/api.d.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { ManturHeaderUser, ManturPaymentMethod, ManturProfileValues, ManturTenant, ManturTenantAuthContext, ManturTenantContextDetail, ManturUserPoints } from "./types";
|
|
2
2
|
export declare const MANTUR_POINTS_REFRESH_EVENT = "mantur-points-refresh";
|
|
3
3
|
export declare const MANTUR_RECHARGE_ORDER_CREATED_EVENT = "mantur-recharge-order-created";
|
|
4
|
+
export declare const MANTUR_RECHARGE_CONFIG_CHANGE_EVENT = "mantur-recharge-config-change";
|
|
5
|
+
export declare const MANTUR_RECHARGE_REQUEST_EVENT = "mantur-recharge-request";
|
|
4
6
|
export declare const MANTUR_TENANT_CONTEXT_CHANGE_EVENT = "mantur-tenant-context-change";
|
|
5
7
|
export interface ManturBillingPackageDTO {
|
|
6
8
|
id?: string;
|
|
@@ -55,6 +57,9 @@ export interface ManturRechargeOrderDTO {
|
|
|
55
57
|
userNickname?: string;
|
|
56
58
|
userAvatar?: string;
|
|
57
59
|
}
|
|
60
|
+
export interface ManturRechargeConfigDTO {
|
|
61
|
+
enabled?: boolean;
|
|
62
|
+
}
|
|
58
63
|
export interface ManturBillingAccountDTO {
|
|
59
64
|
userId?: string;
|
|
60
65
|
totalBalance?: number;
|
|
@@ -113,11 +118,18 @@ export interface ManturLedgerQuery {
|
|
|
113
118
|
fromTime?: string;
|
|
114
119
|
toTime?: string;
|
|
115
120
|
}
|
|
121
|
+
export interface ManturBalanceCheckResult {
|
|
122
|
+
deductPoints: number;
|
|
123
|
+
balance: number;
|
|
124
|
+
enough: boolean;
|
|
125
|
+
points: Required<ManturUserPoints>;
|
|
126
|
+
}
|
|
116
127
|
declare global {
|
|
117
128
|
interface Window {
|
|
118
129
|
__MANTUR_COMPONENTS_API_BASE__?: string;
|
|
119
130
|
__MANTUR_COMPONENTS_POINTS_ENDPOINT__?: string;
|
|
120
131
|
__MANTUR_COMPONENTS_STRIPE_PUBLISHABLE_KEY__?: string;
|
|
132
|
+
__MANTUR_COMPONENTS_RECHARGE_CONFIG__?: ManturRechargeConfigDTO;
|
|
121
133
|
__MANTUR_COMPONENTS_TENANT_CONTEXT__?: ManturTenantContextDetail;
|
|
122
134
|
__MANTUR_MAIN_PREFIX__?: string;
|
|
123
135
|
__MANTUR_APP_NAME__?: string;
|
|
@@ -128,7 +140,11 @@ export declare function logoutManturUser(): Promise<void>;
|
|
|
128
140
|
export declare function updateManturProfile(values: ManturProfileValues): Promise<ManturHeaderUser | undefined>;
|
|
129
141
|
export declare function getManturUserPoints(): Promise<ManturUserPoints>;
|
|
130
142
|
export declare function refreshManturUserPoints(): Promise<ManturUserPoints>;
|
|
143
|
+
export declare function checkManturBalanceEnough(deductPoints: number): Promise<ManturBalanceCheckResult>;
|
|
131
144
|
export declare function getManturBillingPackages(): Promise<ManturBillingPackageDTO[]>;
|
|
145
|
+
export declare function getManturRechargeConfig(): Promise<{
|
|
146
|
+
enabled: boolean;
|
|
147
|
+
}>;
|
|
132
148
|
export declare function createManturRechargeOrder(requestBody: ManturCreateRechargeOrderRequest): Promise<ManturCreateRechargeOrderResponse | undefined>;
|
|
133
149
|
export declare function getManturRechargeOrder(orderNo: string): Promise<ManturRechargeOrderDTO | undefined>;
|
|
134
150
|
export declare function cancelManturRechargeOrder(orderNo: string): Promise<null | undefined>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
import { type ManturBalanceCheckResult } from "./api";
|
|
3
|
+
export interface ManturBalanceEnsureResult extends ManturBalanceCheckResult {
|
|
4
|
+
rechargeEnabled: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface ManturBalanceEnsureOptions {
|
|
7
|
+
showModal?: boolean;
|
|
8
|
+
title?: ReactNode;
|
|
9
|
+
content?: ReactNode;
|
|
10
|
+
onRecharge?: () => void;
|
|
11
|
+
onContactAdmin?: () => void;
|
|
12
|
+
}
|
|
13
|
+
export declare function openManturRechargeModal(): void;
|
|
14
|
+
export declare function ensureManturBalanceEnough(deductPoints: number, options?: ManturBalanceEnsureOptions): Promise<ManturBalanceEnsureResult>;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ManturHeaderLabels, ManturUserPoints } from "../../types";
|
|
2
|
-
export declare function PointsDetailModal({ visible, points, text, onCancel, onRecharge, }: {
|
|
2
|
+
export declare function PointsDetailModal({ visible, points, rechargeEnabled, text, onCancel, onRecharge, }: {
|
|
3
3
|
visible: boolean;
|
|
4
4
|
points: Required<ManturUserPoints>;
|
|
5
|
+
rechargeEnabled: boolean;
|
|
5
6
|
text: ManturHeaderLabels;
|
|
6
7
|
onCancel: () => void;
|
|
7
8
|
onRecharge: () => void;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ManturHeaderLabels, ManturHeaderUser, ManturUserPoints } from "../../types";
|
|
2
|
-
export declare function UserMenu({ user, points, text, onEditProfile, onRecharge, onPointsDetail, onLogout, }: {
|
|
2
|
+
export declare function UserMenu({ user, points, rechargeEnabled, text, onEditProfile, onRecharge, onPointsDetail, onLogout, }: {
|
|
3
3
|
user?: ManturHeaderUser | null;
|
|
4
4
|
points: Required<ManturUserPoints>;
|
|
5
|
+
rechargeEnabled: boolean;
|
|
5
6
|
text: ManturHeaderLabels;
|
|
6
7
|
onEditProfile: () => void;
|
|
7
8
|
onRecharge: () => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
export { ManturHeader } from "./header";
|
|
2
|
-
export {
|
|
3
|
-
export
|
|
2
|
+
export { ensureManturBalanceEnough, openManturRechargeModal, type ManturBalanceEnsureOptions, type ManturBalanceEnsureResult, } from "./billing";
|
|
3
|
+
export { cancelManturRechargeOrder, checkManturBalanceEnough, createManturRechargeOrder, getManturBillingAccount, getManturBillingLedger, getManturBillingPackages, getManturPricingChargePoint, getManturPricingChargePoints, getManturRechargeConfig, getManturRechargeOrder, MANTUR_RECHARGE_CONFIG_CHANGE_EVENT, MANTUR_POINTS_REFRESH_EVENT, MANTUR_RECHARGE_ORDER_CREATED_EVENT, MANTUR_RECHARGE_REQUEST_EVENT, MANTUR_TENANT_CONTEXT_CHANGE_EVENT, refreshManturUserPoints, refreshManturTenantContext, } from "./api";
|
|
4
|
+
export { getManturRechargeConfigSnapshot, refreshManturRechargeConfig, subscribeManturRechargeConfig, } from "./recharge-config-store";
|
|
5
|
+
export type { ManturBalanceCheckResult, ManturBillingAccountDTO, ManturBillingPackageDTO, ManturChargePointWithModelsDTO, ManturCreateRechargeOrderRequest, ManturCreateRechargeOrderResponse, ManturLedgerEntryDTO, ManturLedgerQuery, ManturModelRuleDTO, ManturPageResult, ManturRechargeConfigDTO, ManturRechargeOrderDTO, } from "./api";
|
|
4
6
|
export { formatDateByLang } from "./utils/date";
|
|
5
7
|
export type { ManturDateFormatType, ManturDateInput } from "./utils/date";
|
|
8
|
+
export { captureManturComponentEvent } from "./posthog";
|
|
9
|
+
export type { ManturPostHogEvent, ManturPostHogProperties } from "./posthog";
|
|
6
10
|
export { getManturRechargeRedirectContext, redirectToManturMain, redirectToManturMainHome, resolveManturMainHomeUrl, } from "./utils/url";
|
|
7
11
|
export type { ManturMainRedirectOptions } from "./utils/url";
|
|
8
12
|
export { isManturStripePaymentWindowMessage, MANTUR_STRIPE_PAYMENT_ROUTE, MANTUR_STRIPE_PAYMENT_WINDOW_MESSAGE_TYPE, postManturStripePaymentWindowMessage, resolveManturRechargePaymentPageUrl, resolveManturStripePaymentPageUrl, } from "./utils/stripe-payment-window";
|