mantur-components 0.1.8 → 0.1.10

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
@@ -26,6 +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
  - 语言切换
@@ -78,6 +79,8 @@ interface ManturHeaderProps {
78
79
  brandSlot?: React.ReactNode;
79
80
  children?: React.ReactNode;
80
81
  onTenantContextChange?: (detail: ManturTenantContextDetail) => void;
82
+ rechargePaymentMethod?: "card" | "alipay" | "wechat_pay";
83
+ stripePublishableKey?: string;
81
84
  }
82
85
  ```
83
86
 
@@ -91,6 +94,10 @@ interface ManturHeaderProps {
91
94
 
92
95
  `onTenantContextChange`:Header 完成团队上下文初始化或切换团队成功后触发,直接透出当前选中团队、团队列表和当前团队认证上下文。宿主项目需要同步自己的 store 时优先使用这个回调。
93
96
 
97
+ `rechargePaymentMethod`:兼容旧版本的支付方式参数。当前充值创建订单不再主动提交支付方式,支付方式由 Stripe Checkout Session 内部选择。
98
+
99
+ `stripePublishableKey`:Stripe publishable key。订单返回 Checkout Session client secret(字段名为 `clientSecret`,值以 `cs_` 开头)时,组件库会用该 key 调起内置 Stripe Embedded Checkout 支付弹窗。
100
+
94
101
  ### 用户类型
95
102
 
96
103
  ```ts
@@ -113,12 +120,39 @@ interface ManturHeaderUser {
113
120
  window.__MANTUR_COMPONENTS_API_BASE__ = "/api";
114
121
  ```
115
122
 
116
- 积分接口默认是 `/users/me/points`,也可以覆盖:
123
+ 积分接口默认是 `/billing/accounts/me`,也可以覆盖:
117
124
 
118
125
  ```ts
119
126
  window.__MANTUR_COMPONENTS_POINTS_ENDPOINT__ = "/users/me/points";
120
127
  ```
121
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
+ MANTUR_RECHARGE_ORDER_CREATED_EVENT,
149
+ } from "mantur-components";
150
+ ```
151
+
152
+ 充值面板打开时会调用 `getManturBillingPackages()` 拉取 `/billing/packages`;点击支付时会调用 `createManturRechargeOrder()` 创建 `/billing/recharge/orders`,请求体只传 `packageId` 或 `customAmount`。订单创建成功后会触发浏览器事件 `mantur-recharge-order-created`,`detail` 为后端返回的订单信息。
153
+
154
+ 后端按 `mantur-billing` 文档返回 `ui_mode="embedded"` Checkout Session 的 `clientSecret` 后,`ManturHeader` 会通过 `EmbeddedCheckoutProvider` 挂载 Stripe Embedded Checkout;支付完成后由 Stripe 的 `onComplete` 回调刷新积分。如果后端返回 `paymentUrl`、`checkoutUrl`、`url` 或 `returnUrl` 这类托管支付地址,组件库会直接跳转。组件库仍兼容旧字段名 `stripeClientSecret`,但优先读取 `clientSecret`。
155
+
122
156
  ## 团队上下文同步
123
157
 
124
158
  团队列表、当前团队、切换团队都由 `ManturHeader` 内部处理。
@@ -215,11 +249,14 @@ redirectToManturMain(import.meta.env.VITE_MAIN_PREFIX, import.meta.env.VITE_APP_
215
249
  ```ts
216
250
  import { ManturHeader, formatDateByLang, redirectToManturMain } from "mantur-components";
217
251
  import type {
252
+ ManturBillingPackageDTO,
253
+ ManturCreateRechargeOrderResponse,
218
254
  ManturDateFormatType,
219
255
  ManturDateInput,
220
256
  ManturHeaderProps,
221
257
  ManturHeaderUser,
222
258
  ManturMainRedirectOptions,
259
+ ManturPaymentMethod,
223
260
  ManturTenant,
224
261
  ManturTenantContextDetail,
225
262
  } from "mantur-components";
package/dist/api.d.ts CHANGED
@@ -1,10 +1,120 @@
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;
9
119
  }
10
120
  }
@@ -13,6 +123,13 @@ export declare function logoutManturUser(): Promise<void>;
13
123
  export declare function updateManturProfile(values: ManturProfileValues): Promise<ManturHeaderUser | undefined>;
14
124
  export declare function getManturUserPoints(): Promise<ManturUserPoints>;
15
125
  export declare function refreshManturUserPoints(): Promise<ManturUserPoints>;
126
+ export declare function getManturBillingPackages(): Promise<ManturBillingPackageDTO[]>;
127
+ export declare function createManturRechargeOrder(requestBody: ManturCreateRechargeOrderRequest): Promise<ManturCreateRechargeOrderResponse | undefined>;
128
+ export declare function getManturRechargeOrder(orderNo: string): Promise<ManturRechargeOrderDTO | undefined>;
129
+ export declare function getManturPricingChargePoints(): Promise<ManturChargePointWithModelsDTO[]>;
130
+ export declare function getManturPricingChargePoint(chargePointId: string): Promise<ManturChargePointWithModelsDTO | undefined>;
131
+ export declare function getManturBillingAccount(): Promise<ManturBillingAccountDTO | undefined>;
132
+ export declare function getManturBillingLedger(query: ManturLedgerQuery): Promise<ManturPageResult<ManturLedgerEntryDTO>>;
16
133
  export declare function getManturTenantContextSnapshot(): ManturTenantContextDetail | undefined;
17
134
  export declare function getManturTenants(): Promise<ManturTenant[]>;
18
135
  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, }: 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,23 +1,24 @@
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
- }, {
15
- readonly id: "points-24000";
16
- readonly points: 24000;
17
- readonly price: 200;
18
- }];
19
- export type RechargePackage = (typeof RECHARGE_PACKAGES)[number];
20
- export type RechargePackageId = RechargePackage["id"];
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[];
12
+ export declare const CUSTOM_RECHARGE_MIN_PRICE = 10;
13
+ export declare const CUSTOM_RECHARGE_POINTS_PER_USD = 100;
14
+ export interface CustomRechargePackage {
15
+ id: "custom";
16
+ points: number;
17
+ price: number;
18
+ custom: true;
19
+ }
20
+ export type RechargePackage = FixedRechargePackage | CustomRechargePackage;
21
+ export type RechargePackageId = FixedRechargePackage["id"] | CustomRechargePackage["id"];
21
22
  export type PointsLedgerType = "all" | "income" | "expense";
22
23
  export type PointsLedgerSource = "all" | "recharge" | "gift";
23
24
  export type PointsLedgerBadgeKind = "recharge" | "gift" | "deducted" | "expired";
package/dist/index.d.ts CHANGED
@@ -1,6 +1,8 @@
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 type { ManturHeaderLabels, ManturHeaderProps, ManturHeaderUser, ManturPaymentMethod, ManturProfileValues, ManturRole, ManturTenant, ManturTenantAuthContext, ManturTenantContextDetail, ManturUserPoints, } from "./types";