@laiye_packages/uci 1.0.5 → 1.0.7

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.
@@ -1,5 +1,5 @@
1
1
  import { LYObject } from '../../object';
2
- import { LYAppHttpClient, type IHeaderProvider } from '../../http';
2
+ import { LYAppHttpClient, LYOrganizationHttpClient, type IHeaderProvider } from '../../http';
3
3
  import type { LYAppPermission } from '../../permission';
4
4
  import { LYCrypto } from '../../crypto';
5
5
  import { LYi18n, ILYi18n, LYKeyofLang } from '../../i18n';
@@ -7,6 +7,7 @@ import { ILYStorageSync, ILYStorage } from '../../storage';
7
7
  import { LYEnv } from '../../env';
8
8
  export declare const TENANT_APP_NAME = "tenant";
9
9
  export declare const ORGANIZATION_APP_NAME = "organization";
10
+ export declare const BILL_APP_NAME = "billing";
10
11
  export interface LYAppRemoteModule<Host, LYComponents> {
11
12
  default(host: Host): LYComponents | Promise<LYComponents>;
12
13
  }
@@ -77,3 +78,6 @@ export declare class LYBaseApp extends LYObject {
77
78
  getComponent<T>(componentName: string): Promise<T>;
78
79
  private loadRemoteComponents;
79
80
  }
81
+ export declare class LYBaseOrganizationApp extends LYBaseApp {
82
+ protected _createHttpClient(): LYOrganizationHttpClient;
83
+ }
@@ -0,0 +1,41 @@
1
+ import type { LYAppHttpClient } from '../../../http';
2
+ import { ICreatePlatformParams, ICreateProductParams, IGetOrdersParams, IGetOrdersResponse, IGetPlatformsParam, IGetPlatformsResponse, IGetPricesParams, IGetPricesResponse, IGetProductResponse, IGetProductsParams, IPlatformItem, IQueryPriceRequest, PriceCommon, PriceItem, ProductItem, OnlyAdminOrderItem, IQueryPriceResponse } from './types';
3
+ export declare class LYAdminApi {
4
+ private _httpClient;
5
+ constructor(httpClient: LYAppHttpClient);
6
+ getProducts(params: IGetProductsParams): Promise<IGetProductResponse>;
7
+ createProduct(product: ICreateProductParams): Promise<{
8
+ id: string;
9
+ }>;
10
+ updateProduct(id: string, product: ICreateProductParams): Promise<{
11
+ count: string;
12
+ }>;
13
+ delProduct(id: string): Promise<{
14
+ count: string;
15
+ }>;
16
+ query(id: string): Promise<ProductItem>;
17
+ getPrices(param: IGetPricesParams): Promise<IGetPricesResponse>;
18
+ createPrice(price: PriceItem): Promise<{
19
+ id: string;
20
+ }>;
21
+ updatePrice(id: string, price: PriceCommon): Promise<{
22
+ count: string;
23
+ }>;
24
+ delPrice(id: string): Promise<{
25
+ count: string;
26
+ }>;
27
+ queryPrice(param: IQueryPriceRequest): Promise<IQueryPriceResponse>;
28
+ getPlatforms(param: IGetPlatformsParam): Promise<IGetPlatformsResponse>;
29
+ createPlatform(platform: ICreatePlatformParams): Promise<{
30
+ id: string;
31
+ }>;
32
+ updatePlatform(id: string, platform: ICreatePlatformParams): Promise<{
33
+ count: string;
34
+ }>;
35
+ delPlatform(id: string): Promise<{
36
+ count: string;
37
+ }>;
38
+ queryPlatform(id: string): Promise<IPlatformItem>;
39
+ getOrders(param: IGetOrdersParams): Promise<IGetOrdersResponse>;
40
+ getOrderDetails(id: string): Promise<OnlyAdminOrderItem>;
41
+ }
@@ -0,0 +1,258 @@
1
+ export type OrderStatus = "pending" | "completed" | "failed" | "paid" | "expired" | "cancelled" | "refunded" | "refunding";
2
+ export interface IGetProductsParams {
3
+ product_type: string;
4
+ is_active: boolean;
5
+ offset: number;
6
+ size: number;
7
+ }
8
+ export type Range = {
9
+ offset: number;
10
+ size: number;
11
+ total: number;
12
+ };
13
+ export type ProductItem = {
14
+ id: string;
15
+ name: string;
16
+ description: string;
17
+ product_type: string;
18
+ app_name: string;
19
+ is_free: boolean;
20
+ external_product_id: string;
21
+ is_active: boolean;
22
+ display_order: number;
23
+ base_benefit_config?: Record<string, any>;
24
+ product_metadata?: Record<string, any>;
25
+ create_at?: string;
26
+ updated_at?: string;
27
+ };
28
+ export interface IGetProductResponse {
29
+ range: Range;
30
+ list: ProductItem[];
31
+ }
32
+ export interface ICreateProductParams {
33
+ name: string;
34
+ description: string;
35
+ product_type: string;
36
+ app_name: string;
37
+ is_free: boolean;
38
+ external_product_id: string;
39
+ is_active: boolean;
40
+ display_order: number;
41
+ base_benefit_config?: Record<string, any>;
42
+ product_metadata?: Record<string, any>;
43
+ }
44
+ export interface IGetPricesParams {
45
+ product_id: string;
46
+ is_active: boolean;
47
+ offset: number;
48
+ size: number;
49
+ }
50
+ export type PriceCommon = {
51
+ name: string;
52
+ description: string;
53
+ amount: number;
54
+ discount_amount: number;
55
+ min_amount: number;
56
+ max_amount: number;
57
+ is_active: boolean;
58
+ display_order: number;
59
+ extra_benefit_config: Record<string, any>;
60
+ external_price_id: string;
61
+ price_metadata: Record<string, any>;
62
+ };
63
+ export type PriceItem = {
64
+ id: string;
65
+ product_id: string;
66
+ app_name: string;
67
+ price_type: string;
68
+ currency: string;
69
+ billing_cycle: string;
70
+ interval_count: number;
71
+ created_at?: string;
72
+ updated_at?: string;
73
+ } & PriceCommon;
74
+ export interface IGetPricesResponse {
75
+ range: Range;
76
+ list: PriceItem[];
77
+ }
78
+ export interface IGetProductByAppParams {
79
+ app_name: string;
80
+ product_type?: string;
81
+ offset?: number;
82
+ size?: number;
83
+ }
84
+ export type ProductPriceItem = {
85
+ id: string;
86
+ name: string;
87
+ description: string;
88
+ price_type: string;
89
+ amount: number;
90
+ currency: string;
91
+ min_amount: number;
92
+ max_amount: number;
93
+ discount_amount: number;
94
+ billing_cycle: string;
95
+ interval_count: number;
96
+ is_active: boolean;
97
+ display_order: number;
98
+ };
99
+ export interface IGetProductByAppResponse {
100
+ range: Range;
101
+ list: (ProductItem & {
102
+ prices: ProductPriceItem[];
103
+ })[];
104
+ }
105
+ export interface GetPlatformListResponse {
106
+ range: Range;
107
+ list: {
108
+ id: string;
109
+ type: string;
110
+ name: string;
111
+ }[];
112
+ }
113
+ export interface IgetOrderStatusResponse {
114
+ id: string;
115
+ order_no: string;
116
+ status: string;
117
+ actual_amount: number;
118
+ currency: string;
119
+ created_at: string;
120
+ }
121
+ export interface IGetUserOrdersParams {
122
+ offset?: number;
123
+ size?: number;
124
+ status?: OrderStatus;
125
+ app_name?: string;
126
+ tenant_name: string;
127
+ order_no?: string;
128
+ }
129
+ export interface IOrderItem {
130
+ id: string;
131
+ order_no: string;
132
+ app_name: string;
133
+ product_id: string;
134
+ price_id: string;
135
+ actual_amount: number;
136
+ currency: string;
137
+ platform_id: string;
138
+ status: string;
139
+ created_at: string;
140
+ }
141
+ export interface IGetUserOrdersResponse {
142
+ range: Range;
143
+ list: IOrderItem[];
144
+ }
145
+ export interface IPurchasesParams {
146
+ price_id: string;
147
+ quantity: number;
148
+ platform_id: string;
149
+ custom_amount?: number;
150
+ }
151
+ export interface IPurchasesResponse {
152
+ order_id: string;
153
+ order_no: string;
154
+ product_name: string;
155
+ price_name: string;
156
+ actual_amount: number;
157
+ currency: string;
158
+ platform_name: string;
159
+ payment_url: string;
160
+ qr_code_url: string;
161
+ payment_form: string;
162
+ expires_at: string;
163
+ }
164
+ export interface IQueryPriceRequest {
165
+ product_id?: string;
166
+ is_active?: boolean;
167
+ offset?: number;
168
+ size?: number;
169
+ }
170
+ export interface IQueryPriceResponse {
171
+ range: Range;
172
+ list: PriceItem[];
173
+ }
174
+ export interface IGetPlatformsParam {
175
+ is_active?: boolean;
176
+ offset?: number;
177
+ size?: number;
178
+ }
179
+ export interface IPlatformItem {
180
+ id: string;
181
+ type: string;
182
+ name: string;
183
+ display_name: string;
184
+ description: string;
185
+ config_data: Record<string, any>;
186
+ webhook_url: string;
187
+ return_url: string;
188
+ notify_url: string;
189
+ is_active: boolean;
190
+ created_at: string;
191
+ updated_at: string;
192
+ }
193
+ export interface IGetPlatformsResponse {
194
+ range: Range;
195
+ list: IPlatformItem[];
196
+ }
197
+ export interface ICreatePlatformParams {
198
+ type?: string;
199
+ name?: string;
200
+ display_name: string;
201
+ description: string;
202
+ config_data: {
203
+ app_id: string;
204
+ app_private_key: string;
205
+ alipay_public_key: string;
206
+ gateway_url: string;
207
+ sign_type: string;
208
+ debug: boolean;
209
+ app_notify_url: string;
210
+ return_url: string;
211
+ };
212
+ webhook_url: string;
213
+ return_url: string;
214
+ notify_url: string;
215
+ is_active: boolean;
216
+ }
217
+ export interface IGetOrdersParams {
218
+ product_type?: string;
219
+ app_name?: string;
220
+ status?: OrderStatus;
221
+ user_id?: string;
222
+ offset?: number;
223
+ size?: number;
224
+ }
225
+ export interface OnlyAdminOrderItem {
226
+ id: string;
227
+ order_no: string;
228
+ user_id: string;
229
+ app_name: string;
230
+ product_id: string;
231
+ price_id: string;
232
+ product_type: string;
233
+ subscription_id: string;
234
+ subscription_invoice_type: string;
235
+ quantity: number;
236
+ discount_amount: number;
237
+ actual_amount: number;
238
+ currency: string;
239
+ platform_id: string;
240
+ platform_type: string;
241
+ external_order_id: string;
242
+ external_payment_data: Record<string, any>;
243
+ status: string;
244
+ created_at: string;
245
+ updated_at: string;
246
+ paid_at: string;
247
+ completed_at: string;
248
+ failed_at: string;
249
+ cancelled_at: string;
250
+ expires_at: string;
251
+ error_message: string;
252
+ retry_count: number;
253
+ order_metadata: Record<string, any>;
254
+ }
255
+ export interface IGetOrdersResponse {
256
+ range: Range;
257
+ list: OnlyAdminOrderItem[];
258
+ }
@@ -0,0 +1,18 @@
1
+ import type { LYAppHttpClient, LYResultResponse } from '../../../http';
2
+ import { GetPlatformListResponse, IgetOrderStatusResponse, IGetProductByAppParams, IGetProductByAppResponse, IGetUserOrdersParams, IGetUserOrdersResponse, IPurchasesParams, IPurchasesResponse } from './types';
3
+ export declare class LYUserApi {
4
+ private _httpClient;
5
+ constructor(httpClient: LYAppHttpClient);
6
+ getProductsByApp(param: IGetProductByAppParams): Promise<IGetProductByAppResponse>;
7
+ getPlatformList(): Promise<GetPlatformListResponse>;
8
+ getOrderStatus(id: string): Promise<IgetOrderStatusResponse>;
9
+ getOrders(params: IGetUserOrdersParams): Promise<LYResultResponse<IGetUserOrdersResponse, import("../../../http/error").LYBasicResultCode>>;
10
+ purchases(params: IPurchasesParams): Promise<IPurchasesResponse>;
11
+ webhooks(): Promise<void>;
12
+ subscription(param: any): Promise<any>;
13
+ getSubscriptionByApp(param: any): Promise<any>;
14
+ cancelSubscription(param: any): Promise<any>;
15
+ releaseSchedule(id: string, param: any): Promise<any>;
16
+ previewPurchase(id: string, price_id: string): Promise<any>;
17
+ changeSubscription(id: string, param: any): Promise<any>;
18
+ }
@@ -0,0 +1,16 @@
1
+ import { LYBaseOrganizationApp } from '../../base';
2
+ import { LYAdminApi } from '../api/admin';
3
+ import { LYUserApi } from '../api/user';
4
+ import { LYOrder } from './order';
5
+ declare class LYBillApp extends LYBaseOrganizationApp {
6
+ static _instance?: LYBillApp;
7
+ private _userApi;
8
+ private _adminApi;
9
+ constructor(name: string, version: string, description: string);
10
+ get userApi(): LYUserApi;
11
+ get adminApi(): LYAdminApi;
12
+ static get instance(): LYBillApp;
13
+ createOrder(): LYOrder;
14
+ changeSubscription(id: string, param: any): void;
15
+ }
16
+ export { LYBillApp, LYOrder };
@@ -0,0 +1,70 @@
1
+ import { LYObject, ILYEvents, LYEvents } from '../../../object';
2
+ import { IPurchasesParams, IPurchasesResponse, OrderStatus } from '../api/types';
3
+ import { LYUserApi } from '../api/user';
4
+ /**
5
+ * 订单事件定义
6
+ */
7
+ type LYOrderEvents = {
8
+ "status": (status: OrderStatus, orderId: string) => void;
9
+ };
10
+ /**
11
+ * 订单类 - 管理单个订单的生命周期
12
+ */
13
+ export declare class LYOrder extends LYObject implements ILYEvents<LYOrderEvents> {
14
+ on: LYEvents<LYOrderEvents>['on'];
15
+ emit: LYEvents<LYOrderEvents>['emit'];
16
+ private _userApi;
17
+ private _status;
18
+ private _pollTimer;
19
+ private _pollInterval;
20
+ private _isPolling;
21
+ private _data;
22
+ constructor(userApi: LYUserApi);
23
+ /**
24
+ * 获取订单ID
25
+ */
26
+ get id(): string;
27
+ get no(): string;
28
+ get productName(): string;
29
+ get priceName(): string;
30
+ get actualAmount(): number;
31
+ get currency(): string;
32
+ get platformName(): string;
33
+ get paymentUrl(): string;
34
+ get qrCodeUrl(): string;
35
+ get paymentForm(): string;
36
+ get expiresAt(): string;
37
+ /**
38
+ * 获取订单状态
39
+ */
40
+ get status(): OrderStatus;
41
+ /**
42
+ * 更新订单状态
43
+ */
44
+ private _updateStatus;
45
+ /**
46
+ * 支付方法 - 调用 purchases 接口并开始轮询
47
+ */
48
+ pay(params: IPurchasesParams): Promise<IPurchasesResponse>;
49
+ /**
50
+ * 开始轮询
51
+ */
52
+ private _startPolling;
53
+ /**
54
+ * 执行轮询
55
+ */
56
+ private _doPoll;
57
+ /**
58
+ * 停止轮询
59
+ */
60
+ private _stopPolling;
61
+ /**
62
+ * 销毁订单实例
63
+ */
64
+ destroy(): void;
65
+ /**
66
+ * 刷新订单状态(手动触发,用于用户点击刷新按钮)
67
+ */
68
+ refresh(): Promise<OrderStatus>;
69
+ }
70
+ export {};
@@ -0,0 +1 @@
1
+ export * from './app';
@@ -1,5 +1,5 @@
1
1
  import { LYEnv } from '../env';
2
- import { LYBaseApp, ORGANIZATION_APP_NAME, TENANT_APP_NAME } from './base';
2
+ import { BILL_APP_NAME, LYBaseApp, LYBaseOrganizationApp, ORGANIZATION_APP_NAME, TENANT_APP_NAME } from './base';
3
3
  import { LYOrganizationApp, SSOConfig } from './organization';
4
4
  import { LYTenantApp } from './tenant';
5
5
  import { LYTenantSession } from './tenant/session';
@@ -8,7 +8,9 @@ import { LYGatewayAuthorizer } from './organization/authorizer/gateway';
8
8
  import { LYDirectAuthorizer } from './organization/authorizer/direct';
9
9
  import { LYRedirectAuthorizer } from './organization/authorizer/redirect';
10
10
  import { LYTenantAuthorizer } from './tenant/authorizer';
11
- declare class LYApp extends LYBaseApp {
11
+ import { LYBillApp, LYOrder } from './bill';
12
+ declare class LYApp extends LYBaseOrganizationApp {
12
13
  }
13
14
  export type { SSOConfig };
14
- export { LYApp, LYBaseApp, LYTenantApp, LYOrganizationApp, LYTenantSession, TENANT_APP_NAME, ORGANIZATION_APP_NAME, LYEnv, LYWebAuthorizer, LYGatewayAuthorizer, LYDirectAuthorizer, LYRedirectAuthorizer, LYTenantAuthorizer };
15
+ export * from "./bill/api/types";
16
+ export { LYApp, LYBaseApp, LYTenantApp, LYOrganizationApp, LYTenantSession, TENANT_APP_NAME, ORGANIZATION_APP_NAME, BILL_APP_NAME, LYBillApp, LYOrder, LYEnv, LYWebAuthorizer, LYGatewayAuthorizer, LYDirectAuthorizer, LYRedirectAuthorizer, LYTenantAuthorizer };
@@ -1,4 +1,4 @@
1
- import { LYBaseApp } from '../../base';
1
+ import { LYBaseOrganizationApp } from '../../base';
2
2
  import { LYSessionApi } from '../api/session';
3
3
  import type { SSOConfig } from '../api/session';
4
4
  import { LYUserApi } from '../api/user';
@@ -6,8 +6,7 @@ import type { LYBaseAuthorizer } from '../authorizer/base';
6
6
  import { LYLicenseApi } from '../api/license';
7
7
  import { LYOEMApi } from '../api/oem';
8
8
  import { LYVerificationCodesApi } from '../api/verificationCodes';
9
- import { LYAppHttpClient } from '../../../http';
10
- declare class LYOrganizationApp extends LYBaseApp {
9
+ declare class LYOrganizationApp extends LYBaseOrganizationApp {
11
10
  static _instance?: LYOrganizationApp;
12
11
  private _sessionApi;
13
12
  private _userApi;
@@ -17,7 +16,6 @@ declare class LYOrganizationApp extends LYBaseApp {
17
16
  private _verificationCodesApi;
18
17
  constructor(name: string, version: string, description: string);
19
18
  static get instance(): LYOrganizationApp;
20
- _createHttpClient(): LYAppHttpClient;
21
19
  get sessionApi(): LYSessionApi;
22
20
  get userApi(): LYUserApi;
23
21
  get oemApi(): LYOEMApi;