mantur-components 0.1.9 → 0.1.11

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 CHANGED
@@ -79,6 +79,8 @@ interface ManturHeaderProps {
79
79
  brandSlot?: React.ReactNode;
80
80
  children?: React.ReactNode;
81
81
  onTenantContextChange?: (detail: ManturTenantContextDetail) => void;
82
+ rechargePaymentMethod?: "card" | "alipay" | "wechat_pay";
83
+ stripePublishableKey?: string;
82
84
  }
83
85
  ```
84
86
 
@@ -92,6 +94,10 @@ interface ManturHeaderProps {
92
94
 
93
95
  `onTenantContextChange`:Header 完成团队上下文初始化或切换团队成功后触发,直接透出当前选中团队、团队列表和当前团队认证上下文。宿主项目需要同步自己的 store 时优先使用这个回调。
94
96
 
97
+ `rechargePaymentMethod`:兼容旧版本的支付方式参数。当前充值创建订单不再主动提交支付方式,支付方式由 Stripe Checkout Session 内部选择。
98
+
99
+ `stripePublishableKey`:Stripe publishable key。订单返回 Checkout Session client secret(字段名为 `clientSecret`,值以 `cs_` 开头)时,组件库会用该 key 调起内置 Stripe Embedded Checkout 支付弹窗。
100
+
95
101
  ### 用户类型
96
102
 
97
103
  ```ts
@@ -114,12 +120,42 @@ interface ManturHeaderUser {
114
120
  window.__MANTUR_COMPONENTS_API_BASE__ = "/api";
115
121
  ```
116
122
 
117
- 积分接口默认是 `/users/me/points`,也可以覆盖:
123
+ 积分接口默认是 `/billing/accounts/me`,也可以覆盖:
118
124
 
119
125
  ```ts
120
126
  window.__MANTUR_COMPONENTS_POINTS_ENDPOINT__ = "/users/me/points";
121
127
  ```
122
128
 
129
+ Stripe publishable key 可以通过 `ManturHeader` 的 `stripePublishableKey` 传入,也可以在渲染组件前通过全局变量覆盖:
130
+
131
+ ```ts
132
+ window.__MANTUR_COMPONENTS_STRIPE_PUBLISHABLE_KEY__ = "pk_test_xxx";
133
+ ```
134
+
135
+ ## Billing API
136
+
137
+ 组件库按 `mantur-billing` 用户端接口导出以下 helper:
138
+
139
+ ```ts
140
+ import {
141
+ createManturRechargeOrder,
142
+ getManturBillingAccount,
143
+ getManturBillingLedger,
144
+ getManturBillingPackages,
145
+ getManturPricingChargePoint,
146
+ getManturPricingChargePoints,
147
+ getManturRechargeOrder,
148
+ postManturStripePaymentWindowMessage,
149
+ MANTUR_RECHARGE_ORDER_CREATED_EVENT,
150
+ } from "mantur-components";
151
+ ```
152
+
153
+ 充值面板打开时会调用 `getManturBillingPackages()` 拉取 `/billing/packages`;点击支付时会调用 `createManturRechargeOrder()` 创建 `/billing/recharge/orders`,请求体只传 `packageId` 或 `customAmount`。订单创建成功后会触发浏览器事件 `mantur-recharge-order-created`,`detail` 为后端返回的订单信息。
154
+
155
+ 后端按 `mantur-billing` 文档返回 `ui_mode="embedded"` Checkout Session 的 `clientSecret` 后,`ManturHeader` 会通过 `EmbeddedCheckoutProvider` 挂载 Stripe Embedded Checkout;支付完成后由 Stripe 的 `onComplete` 回调刷新积分。如果后端返回 `paymentUrl`、`checkoutUrl`、`url` 或 `returnUrl` 这类托管支付地址,组件库会直接跳转。组件库仍兼容旧字段名 `stripeClientSecret`,但优先读取 `clientSecret`。
156
+
157
+ 如果宿主项目把 Stripe 支付页放在主应用 `front-main` 中,组件库会在创建订单后按 `redirectToManturMain` 的规则打开子窗口,并通过 URL 参数携带 `orderNo`、`clientSecret`、`amount`、`points` 到 `/stripe-payment`。子页完成支付或点击关闭时调用 `postManturStripePaymentWindowMessage()` 通知父窗口,父窗口会关闭子窗口并刷新用户余额。
158
+
123
159
  ## 团队上下文同步
124
160
 
125
161
  团队列表、当前团队、切换团队都由 `ManturHeader` 内部处理。
@@ -216,11 +252,14 @@ redirectToManturMain(import.meta.env.VITE_MAIN_PREFIX, import.meta.env.VITE_APP_
216
252
  ```ts
217
253
  import { ManturHeader, formatDateByLang, redirectToManturMain } from "mantur-components";
218
254
  import type {
255
+ ManturBillingPackageDTO,
256
+ ManturCreateRechargeOrderResponse,
219
257
  ManturDateFormatType,
220
258
  ManturDateInput,
221
259
  ManturHeaderProps,
222
260
  ManturHeaderUser,
223
261
  ManturMainRedirectOptions,
262
+ ManturPaymentMethod,
224
263
  ManturTenant,
225
264
  ManturTenantContextDetail,
226
265
  } from "mantur-components";
package/dist/api.d.ts CHANGED
@@ -1,11 +1,123 @@
1
- import type { ManturHeaderUser, ManturProfileValues, ManturTenant, ManturTenantAuthContext, ManturTenantContextDetail, ManturUserPoints } from "./types";
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
+ export declare const MANTUR_RECHARGE_ORDER_CREATED_EVENT = "mantur-recharge-order-created";
3
4
  export declare const MANTUR_TENANT_CONTEXT_CHANGE_EVENT = "mantur-tenant-context-change";
5
+ export interface ManturBillingPackageDTO {
6
+ id?: string;
7
+ packageCode?: string;
8
+ packageName?: string;
9
+ packageNameEn?: string;
10
+ amount?: number;
11
+ points?: number;
12
+ isRecommended?: boolean;
13
+ sortOrder?: number;
14
+ status?: number;
15
+ createTime?: string;
16
+ updateTime?: string;
17
+ }
18
+ export interface ManturCreateRechargeOrderRequest {
19
+ packageId?: string;
20
+ customAmount?: number;
21
+ paymentMethod?: ManturPaymentMethod;
22
+ }
23
+ export interface ManturCreateRechargeOrderResponse {
24
+ orderNo?: string;
25
+ amount?: number;
26
+ points?: number;
27
+ clientSecret?: string;
28
+ stripeClientSecret?: string;
29
+ paymentUrl?: string;
30
+ checkoutUrl?: string;
31
+ url?: string;
32
+ returnUrl?: string;
33
+ }
34
+ export interface ManturRechargeOrderDTO {
35
+ orderNo?: string;
36
+ userId?: string;
37
+ packageId?: string;
38
+ packageName?: string;
39
+ packageNameEn?: string;
40
+ stripeTradeNo?: string;
41
+ amount?: number;
42
+ points?: number;
43
+ channel?: number;
44
+ paymentMethod?: ManturPaymentMethod | string;
45
+ channelFeeAmount?: number;
46
+ status?: number;
47
+ paidTime?: string;
48
+ fulfilledTime?: string;
49
+ batchId?: string;
50
+ createTime?: string;
51
+ userEmail?: string;
52
+ userNickname?: string;
53
+ userAvatar?: string;
54
+ }
55
+ export interface ManturBillingAccountDTO {
56
+ userId?: string;
57
+ totalBalance?: number;
58
+ rechargeBalance?: number;
59
+ giftBalance?: number;
60
+ earliestExpireTime?: string;
61
+ rechargeEarliestExpireTime?: string;
62
+ giftEarliestExpireTime?: string;
63
+ }
64
+ export interface ManturModelRuleDTO {
65
+ modelId?: string;
66
+ modelName?: string;
67
+ modelNameEn?: string;
68
+ modelProvider?: string;
69
+ modelType?: number;
70
+ ruleJson?: string;
71
+ ruleVersion?: number;
72
+ status?: number;
73
+ }
74
+ export interface ManturChargePointWithModelsDTO {
75
+ chargePointId?: string;
76
+ chargePointName?: string;
77
+ chargePointNameEn?: string;
78
+ module?: string;
79
+ chargeType?: number;
80
+ fixedPoints?: number;
81
+ ruleVersion?: number;
82
+ status?: number;
83
+ models?: ManturModelRuleDTO[];
84
+ }
85
+ export interface ManturLedgerEntryDTO {
86
+ id?: string;
87
+ direction?: number;
88
+ amount?: number;
89
+ pointType?: number;
90
+ bizType?: number;
91
+ bizRefId?: string;
92
+ balanceAfter?: number;
93
+ context?: string;
94
+ createTime?: string;
95
+ actionName?: string;
96
+ contextDisplay?: string;
97
+ }
98
+ export interface ManturPageResult<T> {
99
+ total?: number;
100
+ pageNum?: number;
101
+ pageSize?: number;
102
+ pages?: number;
103
+ records?: T[];
104
+ }
105
+ export interface ManturLedgerQuery {
106
+ pageNum: number;
107
+ pageSize: number;
108
+ directions?: number[];
109
+ bizTypes?: number[];
110
+ fromTime?: string;
111
+ toTime?: string;
112
+ }
4
113
  declare global {
5
114
  interface Window {
6
115
  __MANTUR_COMPONENTS_API_BASE__?: string;
7
116
  __MANTUR_COMPONENTS_POINTS_ENDPOINT__?: string;
117
+ __MANTUR_COMPONENTS_STRIPE_PUBLISHABLE_KEY__?: string;
8
118
  __MANTUR_COMPONENTS_TENANT_CONTEXT__?: ManturTenantContextDetail;
119
+ __MANTUR_MAIN_PREFIX__?: string;
120
+ __MANTUR_APP_NAME__?: string;
9
121
  }
10
122
  }
11
123
  export declare function removeManturCookie(name: string): void;
@@ -13,6 +125,13 @@ export declare function logoutManturUser(): Promise<void>;
13
125
  export declare function updateManturProfile(values: ManturProfileValues): Promise<ManturHeaderUser | undefined>;
14
126
  export declare function getManturUserPoints(): Promise<ManturUserPoints>;
15
127
  export declare function refreshManturUserPoints(): Promise<ManturUserPoints>;
128
+ export declare function getManturBillingPackages(): Promise<ManturBillingPackageDTO[]>;
129
+ export declare function createManturRechargeOrder(requestBody: ManturCreateRechargeOrderRequest): Promise<ManturCreateRechargeOrderResponse | undefined>;
130
+ export declare function getManturRechargeOrder(orderNo: string): Promise<ManturRechargeOrderDTO | undefined>;
131
+ export declare function getManturPricingChargePoints(): Promise<ManturChargePointWithModelsDTO[]>;
132
+ export declare function getManturPricingChargePoint(chargePointId: string): Promise<ManturChargePointWithModelsDTO | undefined>;
133
+ export declare function getManturBillingAccount(): Promise<ManturBillingAccountDTO | undefined>;
134
+ export declare function getManturBillingLedger(query: ManturLedgerQuery): Promise<ManturPageResult<ManturLedgerEntryDTO>>;
16
135
  export declare function getManturTenantContextSnapshot(): ManturTenantContextDetail | undefined;
17
136
  export declare function getManturTenants(): Promise<ManturTenant[]>;
18
137
  export declare function getManturCurrentTenant(): Promise<ManturTenantAuthContext | undefined>;
@@ -1,2 +1,2 @@
1
1
  import type { ManturHeaderProps } from "../types";
2
- export declare function ManturHeader({ user, disabled, brandSlot, children, onTenantContextChange, }: ManturHeaderProps): import("react/jsx-runtime").JSX.Element;
2
+ export declare function ManturHeader({ user, disabled, brandSlot, children, onTenantContextChange, stripePublishableKey, stripePaymentWindowFeatures, }: ManturHeaderProps): import("react/jsx-runtime").JSX.Element;
@@ -1,10 +1,13 @@
1
1
  import type { ManturHeaderLabels, ManturHeaderUser, ManturUserPoints } from "../../types";
2
- import { type RechargePackage } from "../mock";
3
- export declare function RechargeModal({ visible, user, points, text, onCancel, onPay, }: {
2
+ import { type FixedRechargePackage, type RechargePackage } from "../mock";
3
+ export declare function RechargeModal({ visible, user, points, text, packages, packageLoading, submitting, onCancel, onPay, }: {
4
4
  visible: boolean;
5
5
  user?: ManturHeaderUser | null;
6
6
  points: Required<ManturUserPoints>;
7
7
  text: ManturHeaderLabels;
8
+ packages?: FixedRechargePackage[];
9
+ packageLoading?: boolean;
10
+ submitting?: boolean;
8
11
  onCancel: () => void;
9
- onPay: (rechargePackage: RechargePackage) => void;
12
+ onPay: (rechargePackage: RechargePackage) => void | Promise<void>;
10
13
  }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,12 @@
1
+ import type { ManturCreateRechargeOrderResponse } from "../../api";
2
+ import type { ManturHeaderLabels } from "../../types";
3
+ interface StripePaymentModalProps {
4
+ visible: boolean;
5
+ publishableKey?: string;
6
+ order?: ManturCreateRechargeOrderResponse;
7
+ text: ManturHeaderLabels;
8
+ onCancel: () => void;
9
+ onSuccess: () => void;
10
+ }
11
+ export declare function StripePaymentModal({ visible, publishableKey, order, text, onCancel, onSuccess, }: StripePaymentModalProps): import("react/jsx-runtime").JSX.Element;
12
+ export {};
@@ -1,20 +1,16 @@
1
- export declare const RECHARGE_PACKAGES: readonly [{
2
- readonly id: "points-500";
3
- readonly points: 500;
4
- readonly price: 5;
5
- }, {
6
- readonly id: "points-1000";
7
- readonly points: 1000;
8
- readonly price: 10;
9
- }, {
10
- readonly id: "points-5500";
11
- readonly points: 5500;
12
- readonly price: 50;
13
- readonly recommended: true;
14
- }];
1
+ export interface FixedRechargePackage {
2
+ id: string;
3
+ packageCode?: string;
4
+ packageName?: string;
5
+ packageNameEn?: string;
6
+ points: number;
7
+ price: number;
8
+ recommended?: boolean;
9
+ sortOrder?: number;
10
+ }
11
+ export declare const RECHARGE_PACKAGES: FixedRechargePackage[];
15
12
  export declare const CUSTOM_RECHARGE_MIN_PRICE = 10;
16
13
  export declare const CUSTOM_RECHARGE_POINTS_PER_USD = 100;
17
- export type FixedRechargePackage = (typeof RECHARGE_PACKAGES)[number];
18
14
  export interface CustomRechargePackage {
19
15
  id: "custom";
20
16
  points: number;
package/dist/index.d.ts CHANGED
@@ -1,6 +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";
3
+ export type { ManturBillingAccountDTO, ManturBillingPackageDTO, ManturChargePointWithModelsDTO, ManturCreateRechargeOrderRequest, ManturCreateRechargeOrderResponse, ManturLedgerEntryDTO, ManturLedgerQuery, ManturModelRuleDTO, ManturPageResult, ManturRechargeOrderDTO, } from "./api";
2
4
  export { formatDateByLang } from "./utils/date";
3
5
  export type { ManturDateFormatType, ManturDateInput } from "./utils/date";
4
6
  export { redirectToManturMain } from "./utils/url";
5
7
  export type { ManturMainRedirectOptions } from "./utils/url";
6
- export type { ManturHeaderLabels, ManturHeaderProps, ManturHeaderUser, ManturProfileValues, ManturRole, ManturTenant, ManturTenantAuthContext, ManturTenantContextDetail, ManturUserPoints, } from "./types";
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";
10
+ export type { ManturHeaderLabels, ManturHeaderProps, ManturHeaderUser, ManturPaymentMethod, ManturProfileValues, ManturRole, ManturTenant, ManturTenantAuthContext, ManturTenantContextDetail, ManturUserPoints, } from "./types";