mantur-components 0.1.12 → 0.1.13-beta.1
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 +61 -7
- package/dist/api.d.ts +4 -0
- package/dist/header/ManturHeader.d.ts +1 -1
- package/dist/header/components/StripePaymentModal.d.ts +1 -1
- package/dist/header/mock.d.ts +0 -15
- package/dist/index.d.ts +4 -4
- package/dist/mantur-components.js +1156 -920
- package/dist/mantur-components.umd.cjs +3 -3
- package/dist/types.d.ts +6 -0
- package/dist/utils/stripe-payment-window.d.ts +8 -2
- package/dist/utils/url.d.ts +4 -0
- package/package.json +3 -1
package/README.md
CHANGED
|
@@ -42,7 +42,7 @@ export function Header({
|
|
|
42
42
|
}: {
|
|
43
43
|
userInfo: { username?: string; nickname?: string; avatar?: string } | null;
|
|
44
44
|
}) {
|
|
45
|
-
return <ManturHeader user={userInfo} />;
|
|
45
|
+
return <ManturHeader user={userInfo} appName={import.meta.env.VITE_APP_NAME} />;
|
|
46
46
|
}
|
|
47
47
|
```
|
|
48
48
|
|
|
@@ -62,6 +62,7 @@ export function Header({
|
|
|
62
62
|
<ManturHeader
|
|
63
63
|
user={userInfo}
|
|
64
64
|
disabled={disabled}
|
|
65
|
+
appName={import.meta.env.VITE_APP_NAME}
|
|
65
66
|
brandSlot={<span className="text-lg font-bold">自定义品牌</span>}
|
|
66
67
|
>
|
|
67
68
|
<div className="px-4">自定义中间内容</div>
|
|
@@ -80,7 +81,9 @@ interface ManturHeaderProps {
|
|
|
80
81
|
children?: React.ReactNode;
|
|
81
82
|
onTenantContextChange?: (detail: ManturTenantContextDetail) => void;
|
|
82
83
|
rechargePaymentMethod?: "card" | "alipay" | "wechat_pay";
|
|
84
|
+
appName?: string;
|
|
83
85
|
stripePublishableKey?: string;
|
|
86
|
+
stripePaymentWindowFeatures?: string;
|
|
84
87
|
}
|
|
85
88
|
```
|
|
86
89
|
|
|
@@ -96,7 +99,11 @@ interface ManturHeaderProps {
|
|
|
96
99
|
|
|
97
100
|
`rechargePaymentMethod`:兼容旧版本的支付方式参数。当前充值创建订单不再主动提交支付方式,支付方式由 Stripe Checkout Session 内部选择。
|
|
98
101
|
|
|
99
|
-
`
|
|
102
|
+
`appName`:当前宿主应用名,建议宿主在调用 Header 时传 `appName={import.meta.env.VITE_APP_NAME}`。充值创建订单时会优先使用该值作为请求体 `app`,不传时才回退到 `window.__MANTUR_APP_NAME__`、组件库构建环境或本地开发端口推断。
|
|
103
|
+
|
|
104
|
+
`stripePublishableKey`:Stripe publishable key。订单返回 Checkout Session `clientSecret`(字段名为 `clientSecret`,值以 `cs_` 开头)时,组件库会在自己的支付弹窗中挂载 Stripe Checkout Elements。
|
|
105
|
+
|
|
106
|
+
`stripePaymentWindowFeatures`:兼容旧版本的窗口配置参数。当前支付不再打开新窗口,不读取该参数。
|
|
100
107
|
|
|
101
108
|
### 用户类型
|
|
102
109
|
|
|
@@ -138,6 +145,7 @@ window.__MANTUR_COMPONENTS_STRIPE_PUBLISHABLE_KEY__ = "pk_test_xxx";
|
|
|
138
145
|
|
|
139
146
|
```ts
|
|
140
147
|
import {
|
|
148
|
+
cancelManturRechargeOrder,
|
|
141
149
|
createManturRechargeOrder,
|
|
142
150
|
getManturBillingAccount,
|
|
143
151
|
getManturBillingLedger,
|
|
@@ -145,16 +153,19 @@ import {
|
|
|
145
153
|
getManturPricingChargePoint,
|
|
146
154
|
getManturPricingChargePoints,
|
|
147
155
|
getManturRechargeOrder,
|
|
148
|
-
postManturStripePaymentWindowMessage,
|
|
149
156
|
MANTUR_RECHARGE_ORDER_CREATED_EVENT,
|
|
150
157
|
} from "mantur-components";
|
|
151
158
|
```
|
|
152
159
|
|
|
153
|
-
充值面板打开时会调用 `getManturBillingPackages()` 拉取 `/billing/packages`;点击支付时会调用 `createManturRechargeOrder()` 创建 `/billing/recharge/orders
|
|
160
|
+
充值面板打开时会调用 `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` 为后端返回的订单信息。
|
|
161
|
+
|
|
162
|
+
积分明细弹窗打开后会调用 `getManturBillingLedger()` 拉取 `/billing/accounts/me/ledger`,并根据“获得/消耗”、来源和日期范围筛选传递 `directions`、`bizTypes`、`fromTime`、`toTime`,分页总数使用接口返回的 `total`。
|
|
163
|
+
|
|
164
|
+
后端按 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`。
|
|
154
165
|
|
|
155
|
-
|
|
166
|
+
如果支付方式需要跳出授权,后端的 Stripe return_url 会回到 `front-main` 的 `/pay-callback?app=...&redirect=...`,`pay-callback` 会读取这两个参数并跳回原应用的 `redirect` 路由。
|
|
156
167
|
|
|
157
|
-
|
|
168
|
+
`postManturStripePaymentWindowMessage()`、`resolveManturStripePaymentPageUrl()` 和 `resolveManturRechargePaymentPageUrl()` 对外导出,用于 `front-main` 支付页和其它宿主复用同一套支付窗口消息协议。
|
|
158
169
|
|
|
159
170
|
## 团队上下文同步
|
|
160
171
|
|
|
@@ -176,7 +187,13 @@ function applyTenantContext(detail: ManturTenantContextDetail) {
|
|
|
176
187
|
}
|
|
177
188
|
|
|
178
189
|
function Header({ userInfo }: { userInfo: UserInfo | null }) {
|
|
179
|
-
return
|
|
190
|
+
return (
|
|
191
|
+
<ManturHeader
|
|
192
|
+
user={userInfo}
|
|
193
|
+
appName={import.meta.env.VITE_APP_NAME}
|
|
194
|
+
onTenantContextChange={applyTenantContext}
|
|
195
|
+
/>
|
|
196
|
+
);
|
|
180
197
|
}
|
|
181
198
|
```
|
|
182
199
|
|
|
@@ -270,3 +287,40 @@ import type {
|
|
|
270
287
|
```bash
|
|
271
288
|
npm run build
|
|
272
289
|
```
|
|
290
|
+
|
|
291
|
+
## 发布
|
|
292
|
+
|
|
293
|
+
测试包和生产包直接发布到 npm,通过 npm tag 区分:
|
|
294
|
+
|
|
295
|
+
```bash
|
|
296
|
+
npm run publish:test
|
|
297
|
+
npm run publish:pro
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
`publish:test` 会使用 `vite build --mode test` 构建,并发布到 `test` tag。测试包版本必须是 prerelease,例如:
|
|
301
|
+
|
|
302
|
+
```bash
|
|
303
|
+
npm version prerelease --preid beta --no-git-tag-version
|
|
304
|
+
npm run publish:test
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
测试项目安装:
|
|
308
|
+
|
|
309
|
+
```bash
|
|
310
|
+
npm install mantur-components@test
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
`publish:pro` 会使用 `vite build --mode pro` 构建,并发布到 `latest` tag。生产包版本不能包含 `beta`、`alpha`、`rc` 等 prerelease 标识,例如:
|
|
314
|
+
|
|
315
|
+
```bash
|
|
316
|
+
npm version 0.1.13 --no-git-tag-version
|
|
317
|
+
npm run publish:pro
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
生产项目安装:
|
|
321
|
+
|
|
322
|
+
```bash
|
|
323
|
+
npm install mantur-components@latest
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
环境变量读取遵循 Vite mode 规则:测试包读取 `.env` 和 `.env.test`,生产包读取 `.env` 和 `.env.pro`。发布前需要确认对应环境变量已经写入正确的 `VITE_*` 配置。
|
package/dist/api.d.ts
CHANGED
|
@@ -19,6 +19,9 @@ export interface ManturCreateRechargeOrderRequest {
|
|
|
19
19
|
packageId?: string;
|
|
20
20
|
customAmount?: number;
|
|
21
21
|
paymentMethod?: ManturPaymentMethod;
|
|
22
|
+
uiMode?: "custom" | "elements" | "embedded";
|
|
23
|
+
app?: string;
|
|
24
|
+
redirect?: string;
|
|
22
25
|
}
|
|
23
26
|
export interface ManturCreateRechargeOrderResponse {
|
|
24
27
|
orderNo?: string;
|
|
@@ -128,6 +131,7 @@ export declare function refreshManturUserPoints(): Promise<ManturUserPoints>;
|
|
|
128
131
|
export declare function getManturBillingPackages(): Promise<ManturBillingPackageDTO[]>;
|
|
129
132
|
export declare function createManturRechargeOrder(requestBody: ManturCreateRechargeOrderRequest): Promise<ManturCreateRechargeOrderResponse | undefined>;
|
|
130
133
|
export declare function getManturRechargeOrder(orderNo: string): Promise<ManturRechargeOrderDTO | undefined>;
|
|
134
|
+
export declare function cancelManturRechargeOrder(orderNo: string): Promise<null | undefined>;
|
|
131
135
|
export declare function getManturPricingChargePoints(): Promise<ManturChargePointWithModelsDTO[]>;
|
|
132
136
|
export declare function getManturPricingChargePoint(chargePointId: string): Promise<ManturChargePointWithModelsDTO | undefined>;
|
|
133
137
|
export declare function getManturBillingAccount(): Promise<ManturBillingAccountDTO | undefined>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { ManturHeaderProps } from "../types";
|
|
2
|
-
export declare function ManturHeader({ user, disabled, brandSlot, children, onTenantContextChange,
|
|
2
|
+
export declare function ManturHeader({ user, disabled, brandSlot, children, onTenantContextChange, appName, stripePublishableKey, }: ManturHeaderProps): import("react/jsx-runtime").JSX.Element;
|
package/dist/header/mock.d.ts
CHANGED
|
@@ -19,18 +19,3 @@ export interface CustomRechargePackage {
|
|
|
19
19
|
}
|
|
20
20
|
export type RechargePackage = FixedRechargePackage | CustomRechargePackage;
|
|
21
21
|
export type RechargePackageId = FixedRechargePackage["id"] | CustomRechargePackage["id"];
|
|
22
|
-
export type PointsLedgerType = "all" | "income" | "expense";
|
|
23
|
-
export type PointsLedgerSource = "all" | "recharge" | "gift";
|
|
24
|
-
export type PointsLedgerBadgeKind = "recharge" | "gift" | "deducted" | "expired";
|
|
25
|
-
export interface PointsLedgerRecord {
|
|
26
|
-
id: string;
|
|
27
|
-
type: Exclude<PointsLedgerType, "all">;
|
|
28
|
-
source?: Exclude<PointsLedgerSource, "all">;
|
|
29
|
-
name: string;
|
|
30
|
-
meta: string;
|
|
31
|
-
date: string;
|
|
32
|
-
amount: number;
|
|
33
|
-
badgeKind: PointsLedgerBadgeKind;
|
|
34
|
-
badgeText: string;
|
|
35
|
-
}
|
|
36
|
-
export declare const MOCK_POINTS_LEDGER: PointsLedgerRecord[];
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export { ManturHeader } from "./header";
|
|
2
|
-
export { createManturRechargeOrder, getManturBillingAccount, getManturBillingLedger, getManturBillingPackages, getManturPricingChargePoint, getManturPricingChargePoints, getManturRechargeOrder, MANTUR_POINTS_REFRESH_EVENT, MANTUR_RECHARGE_ORDER_CREATED_EVENT, MANTUR_TENANT_CONTEXT_CHANGE_EVENT, refreshManturUserPoints, refreshManturTenantContext, } from "./api";
|
|
2
|
+
export { cancelManturRechargeOrder, createManturRechargeOrder, getManturBillingAccount, getManturBillingLedger, getManturBillingPackages, getManturPricingChargePoint, getManturPricingChargePoints, getManturRechargeOrder, MANTUR_POINTS_REFRESH_EVENT, MANTUR_RECHARGE_ORDER_CREATED_EVENT, MANTUR_TENANT_CONTEXT_CHANGE_EVENT, refreshManturUserPoints, refreshManturTenantContext, } from "./api";
|
|
3
3
|
export type { ManturBillingAccountDTO, ManturBillingPackageDTO, ManturChargePointWithModelsDTO, ManturCreateRechargeOrderRequest, ManturCreateRechargeOrderResponse, ManturLedgerEntryDTO, ManturLedgerQuery, ManturModelRuleDTO, ManturPageResult, ManturRechargeOrderDTO, } from "./api";
|
|
4
4
|
export { formatDateByLang } from "./utils/date";
|
|
5
5
|
export type { ManturDateFormatType, ManturDateInput } from "./utils/date";
|
|
6
|
-
export { redirectToManturMain } from "./utils/url";
|
|
6
|
+
export { getManturRechargeRedirectContext, redirectToManturMain } from "./utils/url";
|
|
7
7
|
export type { ManturMainRedirectOptions } from "./utils/url";
|
|
8
|
-
export { isManturStripePaymentWindowMessage, MANTUR_STRIPE_PAYMENT_ROUTE, MANTUR_STRIPE_PAYMENT_WINDOW_MESSAGE_TYPE, postManturStripePaymentWindowMessage, resolveManturStripePaymentPageUrl, } from "./utils/stripe-payment-window";
|
|
9
|
-
export type { ManturStripePaymentWindowAction, ManturStripePaymentWindowMessage, } from "./utils/stripe-payment-window";
|
|
8
|
+
export { isManturStripePaymentWindowMessage, MANTUR_STRIPE_PAYMENT_ROUTE, MANTUR_STRIPE_PAYMENT_WINDOW_MESSAGE_TYPE, postManturStripePaymentWindowMessage, resolveManturRechargePaymentPageUrl, resolveManturStripePaymentPageUrl, } from "./utils/stripe-payment-window";
|
|
9
|
+
export type { ManturStripePaymentPageUrlOptions, ManturStripePaymentWindowAction, ManturStripePaymentWindowMessage, } from "./utils/stripe-payment-window";
|
|
10
10
|
export type { ManturHeaderLabels, ManturHeaderProps, ManturHeaderUser, ManturPaymentMethod, ManturProfileValues, ManturRole, ManturTenant, ManturTenantAuthContext, ManturTenantContextDetail, ManturUserPoints, } from "./types";
|