@choiceform/shared-auth 0.1.22 → 0.1.24
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/dist/core.d.ts +3 -0
- package/dist/core.d.ts.map +1 -1
- package/dist/core.js +9 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -1
- package/dist/init.d.ts +3 -0
- package/dist/init.d.ts.map +1 -1
- package/dist/services/api-key-service.d.ts +29 -0
- package/dist/services/api-key-service.d.ts.map +1 -0
- package/dist/services/api-key-service.js +140 -0
- package/dist/services/credit-service.d.ts +33 -0
- package/dist/services/credit-service.d.ts.map +1 -0
- package/dist/services/credit-service.js +228 -0
- package/dist/services/index.d.ts +5 -1
- package/dist/services/index.d.ts.map +1 -1
- package/dist/services/index.js +3 -0
- package/dist/services/referral-service.d.ts +4 -47
- package/dist/services/referral-service.d.ts.map +1 -1
- package/dist/services/referral-service.js +81 -25
- package/dist/services/stripe-service.d.ts +39 -0
- package/dist/services/stripe-service.d.ts.map +1 -0
- package/dist/services/stripe-service.js +291 -0
- package/dist/types/api-key.d.ts +174 -0
- package/dist/types/api-key.d.ts.map +1 -0
- package/dist/types/api-key.js +10 -0
- package/dist/types/credit.d.ts +226 -0
- package/dist/types/credit.d.ts.map +1 -0
- package/dist/types/credit.js +12 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/referral.d.ts +85 -0
- package/dist/types/referral.d.ts.map +1 -0
- package/dist/types/referral.js +10 -0
- package/dist/types/stripe.d.ts +275 -0
- package/dist/types/stripe.d.ts.map +1 -0
- package/dist/types/stripe.js +10 -0
- package/dist/utils/error-mapper.d.ts +15 -0
- package/dist/utils/error-mapper.d.ts.map +1 -0
- package/dist/utils/error-mapper.js +27 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -0
- package/dist/utils/query-string.d.ts +24 -0
- package/dist/utils/query-string.d.ts.map +1 -0
- package/dist/utils/query-string.js +30 -0
- package/package.json +11 -9
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stripe 类型定义
|
|
3
|
+
*
|
|
4
|
+
* 提供 Stripe 相关的类型定义:
|
|
5
|
+
* - 订阅管理
|
|
6
|
+
* - 产品和价格
|
|
7
|
+
* - 计划
|
|
8
|
+
* - 账单门户
|
|
9
|
+
*/
|
|
10
|
+
/** 客户类型 */
|
|
11
|
+
export type StripeCustomerType = "user" | "organization";
|
|
12
|
+
/** 计划计费间隔 */
|
|
13
|
+
export type StripePlanInterval = "day" | "week" | "month" | "year";
|
|
14
|
+
/** Stripe 产品 */
|
|
15
|
+
export interface StripeProduct {
|
|
16
|
+
/** 是否激活 */
|
|
17
|
+
active: boolean;
|
|
18
|
+
/** 创建时间 */
|
|
19
|
+
createdAt: string;
|
|
20
|
+
/** 描述 */
|
|
21
|
+
description: string | null;
|
|
22
|
+
/** 唯一标识符 */
|
|
23
|
+
id: string;
|
|
24
|
+
/** 图片 URL 列表 */
|
|
25
|
+
images: string[];
|
|
26
|
+
/** 是否为生产模式 */
|
|
27
|
+
livemode: boolean;
|
|
28
|
+
/** 元数据 */
|
|
29
|
+
metadata: Record<string, string> | null;
|
|
30
|
+
/** 产品名称 */
|
|
31
|
+
name: string;
|
|
32
|
+
/** 关联的计划列表 (可选包含) */
|
|
33
|
+
plans?: StripePlan[];
|
|
34
|
+
/** 关联的价格列表 (可选包含) */
|
|
35
|
+
prices?: StripePrice[];
|
|
36
|
+
/** Stripe 产品 ID */
|
|
37
|
+
stripeId: string;
|
|
38
|
+
/** 更新时间 */
|
|
39
|
+
updatedAt: string;
|
|
40
|
+
}
|
|
41
|
+
/** 列出产品请求 */
|
|
42
|
+
export interface ListStripeProductsRequest {
|
|
43
|
+
/** 是否激活 */
|
|
44
|
+
active?: string | null;
|
|
45
|
+
/** 应用 ID */
|
|
46
|
+
applicationId?: string | null;
|
|
47
|
+
/** 包含关联数据 (prices, plans) */
|
|
48
|
+
include?: string | null;
|
|
49
|
+
/** 是否为生产模式 */
|
|
50
|
+
livemode?: string | null;
|
|
51
|
+
/** 产品类型 */
|
|
52
|
+
type?: string | null;
|
|
53
|
+
}
|
|
54
|
+
/** Stripe 价格 */
|
|
55
|
+
export interface StripePrice {
|
|
56
|
+
/** 是否激活 */
|
|
57
|
+
active: boolean;
|
|
58
|
+
/** 创建时间 */
|
|
59
|
+
createdAt: string;
|
|
60
|
+
/** 货币 */
|
|
61
|
+
currency: string;
|
|
62
|
+
/** 唯一标识符 */
|
|
63
|
+
id: string;
|
|
64
|
+
/** 是否为生产模式 */
|
|
65
|
+
livemode: boolean;
|
|
66
|
+
/** 元数据 */
|
|
67
|
+
metadata: Record<string, string> | null;
|
|
68
|
+
/** 关联的产品 (可选包含) */
|
|
69
|
+
product?: StripeProduct;
|
|
70
|
+
/** 产品 ID */
|
|
71
|
+
productId: string;
|
|
72
|
+
/** Stripe 价格 ID */
|
|
73
|
+
stripeId: string;
|
|
74
|
+
/** Stripe 产品 ID */
|
|
75
|
+
stripeProductId: string;
|
|
76
|
+
/** 价格类型 */
|
|
77
|
+
type: string;
|
|
78
|
+
/** 单价 (分) */
|
|
79
|
+
unitAmount: number | null;
|
|
80
|
+
/** 更新时间 */
|
|
81
|
+
updatedAt: string;
|
|
82
|
+
}
|
|
83
|
+
/** 列出价格请求 */
|
|
84
|
+
export interface ListStripePricesRequest {
|
|
85
|
+
/** 是否激活 */
|
|
86
|
+
active?: string | null;
|
|
87
|
+
/** 包含关联数据 (product) */
|
|
88
|
+
include?: string | null;
|
|
89
|
+
/** 是否为生产模式 */
|
|
90
|
+
livemode?: string | null;
|
|
91
|
+
}
|
|
92
|
+
/** Stripe 计划 */
|
|
93
|
+
export interface StripePlan {
|
|
94
|
+
/** 是否激活 */
|
|
95
|
+
active: boolean;
|
|
96
|
+
/** 金额 (分) */
|
|
97
|
+
amount: number | null;
|
|
98
|
+
/** 创建时间 */
|
|
99
|
+
createdAt: string;
|
|
100
|
+
/** 货币 */
|
|
101
|
+
currency: string;
|
|
102
|
+
/** 唯一标识符 */
|
|
103
|
+
id: string;
|
|
104
|
+
/** 计费间隔 */
|
|
105
|
+
interval: StripePlanInterval;
|
|
106
|
+
/** 计费间隔数量 */
|
|
107
|
+
intervalCount: number;
|
|
108
|
+
/** 是否为生产模式 */
|
|
109
|
+
livemode: boolean;
|
|
110
|
+
/** 元数据 */
|
|
111
|
+
metadata: Record<string, string> | null;
|
|
112
|
+
/** 计划名称 */
|
|
113
|
+
name: string;
|
|
114
|
+
/** 关联的产品 (可选包含) */
|
|
115
|
+
product?: StripeProduct;
|
|
116
|
+
/** 产品 ID */
|
|
117
|
+
productId: string;
|
|
118
|
+
/** Stripe 计划 ID */
|
|
119
|
+
stripeId: string;
|
|
120
|
+
/** Stripe 产品 ID */
|
|
121
|
+
stripeProductId: string;
|
|
122
|
+
/** 试用天数 */
|
|
123
|
+
trialPeriodDays: number | null;
|
|
124
|
+
/** 更新时间 */
|
|
125
|
+
updatedAt: string;
|
|
126
|
+
}
|
|
127
|
+
/** 列出计划请求 */
|
|
128
|
+
export interface ListStripePlansRequest {
|
|
129
|
+
/** 是否激活 */
|
|
130
|
+
active?: string | null;
|
|
131
|
+
/** 应用 ID */
|
|
132
|
+
applicationId?: string | null;
|
|
133
|
+
/** 包含关联数据 (product) */
|
|
134
|
+
include?: string | null;
|
|
135
|
+
/** 是否为一次性付款 */
|
|
136
|
+
isOneoff?: boolean | null;
|
|
137
|
+
/** 是否为生产模式 */
|
|
138
|
+
livemode?: string | null;
|
|
139
|
+
}
|
|
140
|
+
/** 升级订阅请求 */
|
|
141
|
+
export interface UpgradeSubscriptionRequest {
|
|
142
|
+
/** 是否年付 */
|
|
143
|
+
annual?: boolean | null;
|
|
144
|
+
/** 取消 URL */
|
|
145
|
+
cancelUrl: string;
|
|
146
|
+
/** 客户类型 */
|
|
147
|
+
customerType?: StripeCustomerType | null;
|
|
148
|
+
/** 禁用重定向 */
|
|
149
|
+
disableRedirect: boolean;
|
|
150
|
+
/** 语言 */
|
|
151
|
+
locale?: string | null;
|
|
152
|
+
/** 元数据 */
|
|
153
|
+
metadata?: string | null;
|
|
154
|
+
/** 计划名称 */
|
|
155
|
+
plan: string;
|
|
156
|
+
/** 引用 ID */
|
|
157
|
+
referenceId?: string | null;
|
|
158
|
+
/** 返回 URL */
|
|
159
|
+
returnUrl?: string | null;
|
|
160
|
+
/** 座位数 */
|
|
161
|
+
seats?: number | null;
|
|
162
|
+
/** 成功 URL */
|
|
163
|
+
successUrl: string;
|
|
164
|
+
/** 订阅 ID */
|
|
165
|
+
subscriptionId?: string | null;
|
|
166
|
+
}
|
|
167
|
+
/** 取消订阅请求 */
|
|
168
|
+
export interface CancelSubscriptionRequest {
|
|
169
|
+
/** 客户类型 */
|
|
170
|
+
customerType?: StripeCustomerType | null;
|
|
171
|
+
/** 禁用重定向 */
|
|
172
|
+
disableRedirect: boolean;
|
|
173
|
+
/** 引用 ID */
|
|
174
|
+
referenceId?: string | null;
|
|
175
|
+
/** 返回 URL */
|
|
176
|
+
returnUrl: string;
|
|
177
|
+
/** 订阅 ID */
|
|
178
|
+
subscriptionId?: string | null;
|
|
179
|
+
}
|
|
180
|
+
/** 恢复订阅请求 */
|
|
181
|
+
export interface RestoreSubscriptionRequest {
|
|
182
|
+
/** 客户类型 */
|
|
183
|
+
customerType?: StripeCustomerType | null;
|
|
184
|
+
/** 引用 ID */
|
|
185
|
+
referenceId?: string | null;
|
|
186
|
+
/** 订阅 ID */
|
|
187
|
+
subscriptionId?: string | null;
|
|
188
|
+
}
|
|
189
|
+
/** 创建账单门户请求 */
|
|
190
|
+
export interface CreateBillingPortalRequest {
|
|
191
|
+
/** 客户类型 */
|
|
192
|
+
customerType?: StripeCustomerType | null;
|
|
193
|
+
/** 禁用重定向 */
|
|
194
|
+
disableRedirect: boolean;
|
|
195
|
+
/** 语言 */
|
|
196
|
+
locale?: string | null;
|
|
197
|
+
/** 引用 ID */
|
|
198
|
+
referenceId?: string | null;
|
|
199
|
+
/** 返回 URL */
|
|
200
|
+
returnUrl: string;
|
|
201
|
+
}
|
|
202
|
+
/** 订阅操作响应 (包含重定向 URL) */
|
|
203
|
+
export interface SubscriptionActionResponse {
|
|
204
|
+
/** 重定向 URL */
|
|
205
|
+
url?: string;
|
|
206
|
+
}
|
|
207
|
+
/** Stripe 操作错误类型 */
|
|
208
|
+
export type StripeErrorType = "bad_request" | "unauthorized" | "forbidden" | "not_found" | "rate_limited" | "unknown";
|
|
209
|
+
/** 基础操作结果 */
|
|
210
|
+
export interface StripeResult {
|
|
211
|
+
/** 错误类型 */
|
|
212
|
+
error: StripeErrorType | undefined;
|
|
213
|
+
/** 是否成功 */
|
|
214
|
+
success: boolean;
|
|
215
|
+
}
|
|
216
|
+
/** 带重定向 URL 的操作结果 */
|
|
217
|
+
export interface StripeRedirectResult extends StripeResult {
|
|
218
|
+
/** 重定向 URL */
|
|
219
|
+
url: string | undefined;
|
|
220
|
+
}
|
|
221
|
+
/** 列出产品结果 */
|
|
222
|
+
export interface ListStripeProductsResult {
|
|
223
|
+
/** 错误类型 */
|
|
224
|
+
error: StripeErrorType | undefined;
|
|
225
|
+
/** 产品列表 */
|
|
226
|
+
products: StripeProduct[];
|
|
227
|
+
/** 是否成功 */
|
|
228
|
+
success: boolean;
|
|
229
|
+
}
|
|
230
|
+
/** 获取产品结果 */
|
|
231
|
+
export interface GetStripeProductResult {
|
|
232
|
+
/** 错误类型 */
|
|
233
|
+
error: StripeErrorType | undefined;
|
|
234
|
+
/** 产品数据 */
|
|
235
|
+
product: StripeProduct | undefined;
|
|
236
|
+
/** 是否成功 */
|
|
237
|
+
success: boolean;
|
|
238
|
+
}
|
|
239
|
+
/** 列出价格结果 */
|
|
240
|
+
export interface ListStripePricesResult {
|
|
241
|
+
/** 错误类型 */
|
|
242
|
+
error: StripeErrorType | undefined;
|
|
243
|
+
/** 价格列表 */
|
|
244
|
+
prices: StripePrice[];
|
|
245
|
+
/** 是否成功 */
|
|
246
|
+
success: boolean;
|
|
247
|
+
}
|
|
248
|
+
/** 获取价格结果 */
|
|
249
|
+
export interface GetStripePriceResult {
|
|
250
|
+
/** 错误类型 */
|
|
251
|
+
error: StripeErrorType | undefined;
|
|
252
|
+
/** 价格数据 */
|
|
253
|
+
price: StripePrice | undefined;
|
|
254
|
+
/** 是否成功 */
|
|
255
|
+
success: boolean;
|
|
256
|
+
}
|
|
257
|
+
/** 列出计划结果 */
|
|
258
|
+
export interface ListStripePlansResult {
|
|
259
|
+
/** 错误类型 */
|
|
260
|
+
error: StripeErrorType | undefined;
|
|
261
|
+
/** 计划列表 */
|
|
262
|
+
plans: StripePlan[];
|
|
263
|
+
/** 是否成功 */
|
|
264
|
+
success: boolean;
|
|
265
|
+
}
|
|
266
|
+
/** 获取计划结果 */
|
|
267
|
+
export interface GetStripePlanResult {
|
|
268
|
+
/** 错误类型 */
|
|
269
|
+
error: StripeErrorType | undefined;
|
|
270
|
+
/** 计划数据 */
|
|
271
|
+
plan: StripePlan | undefined;
|
|
272
|
+
/** 是否成功 */
|
|
273
|
+
success: boolean;
|
|
274
|
+
}
|
|
275
|
+
//# sourceMappingURL=stripe.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripe.d.ts","sourceRoot":"","sources":["../../src/types/stripe.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,WAAW;AACX,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,cAAc,CAAA;AAExD,aAAa;AACb,MAAM,MAAM,kBAAkB,GAAG,KAAK,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAA;AAIlE,gBAAgB;AAChB,MAAM,WAAW,aAAa;IAC5B,WAAW;IACX,MAAM,EAAE,OAAO,CAAA;IACf,WAAW;IACX,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS;IACT,WAAW,EAAE,MAAM,GAAG,IAAI,CAAA;IAC1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CAAA;IACzB,WAAW;IACX,OAAO,EAAE,OAAO,CAAA;CACjB;AAED,aAAa;AACb,MAAM,WAAW,sBAAsB;IACrC,WAAW;IACX,KAAK,EAAE,eAAe,GAAG,SAAS,CAAA;IAClC,WAAW;IACX,OAAO,EAAE,aAAa,GAAG,SAAS,CAAA;IAClC,WAAW;IACX,OAAO,EAAE,OAAO,CAAA;CACjB;AAED,aAAa;AACb,MAAM,WAAW,sBAAsB;IACrC,WAAW;IACX,KAAK,EAAE,eAAe,GAAG,SAAS,CAAA;IAClC,WAAW;IACX,MAAM,EAAE,WAAW,EAAE,CAAA;IACrB,WAAW;IACX,OAAO,EAAE,OAAO,CAAA;CACjB;AAED,aAAa;AACb,MAAM,WAAW,oBAAoB;IACnC,WAAW;IACX,KAAK,EAAE,eAAe,GAAG,SAAS,CAAA;IAClC,WAAW;IACX,KAAK,EAAE,WAAW,GAAG,SAAS,CAAA;IAC9B,WAAW;IACX,OAAO,EAAE,OAAO,CAAA;CACjB;AAED,aAAa;AACb,MAAM,WAAW,qBAAqB;IACpC,WAAW;IACX,KAAK,EAAE,eAAe,GAAG,SAAS,CAAA;IAClC,WAAW;IACX,KAAK,EAAE,UAAU,EAAE,CAAA;IACnB,WAAW;IACX,OAAO,EAAE,OAAO,CAAA;CACjB;AAED,aAAa;AACb,MAAM,WAAW,mBAAmB;IAClC,WAAW;IACX,KAAK,EAAE,eAAe,GAAG,SAAS,CAAA;IAClC,WAAW;IACX,IAAI,EAAE,UAAU,GAAG,SAAS,CAAA;IAC5B,WAAW;IACX,OAAO,EAAE,OAAO,CAAA;CACjB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP 错误映射工具
|
|
3
|
+
*
|
|
4
|
+
* 提供统一的 HTTP 状态码到错误类型的映射
|
|
5
|
+
*/
|
|
6
|
+
/** 通用 HTTP 错误类型 */
|
|
7
|
+
export type HttpErrorType = "bad_request" | "unauthorized" | "forbidden" | "not_found" | "rate_limited" | "unknown";
|
|
8
|
+
/**
|
|
9
|
+
* 将 HTTP 状态码映射为错误类型
|
|
10
|
+
*
|
|
11
|
+
* @param status - HTTP 状态码
|
|
12
|
+
* @returns 对应的错误类型
|
|
13
|
+
*/
|
|
14
|
+
export declare function mapHttpStatusToError(status: number): HttpErrorType;
|
|
15
|
+
//# sourceMappingURL=error-mapper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-mapper.d.ts","sourceRoot":"","sources":["../../src/utils/error-mapper.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,mBAAmB;AACnB,MAAM,MAAM,aAAa,GACrB,aAAa,GACb,cAAc,GACd,WAAW,GACX,WAAW,GACX,cAAc,GACd,SAAS,CAAA;AAEb;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,CAelE"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HTTP 错误映射工具
|
|
3
|
+
*
|
|
4
|
+
* 提供统一的 HTTP 状态码到错误类型的映射
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* 将 HTTP 状态码映射为错误类型
|
|
8
|
+
*
|
|
9
|
+
* @param status - HTTP 状态码
|
|
10
|
+
* @returns 对应的错误类型
|
|
11
|
+
*/
|
|
12
|
+
export function mapHttpStatusToError(status) {
|
|
13
|
+
switch (status) {
|
|
14
|
+
case 400:
|
|
15
|
+
return "bad_request";
|
|
16
|
+
case 401:
|
|
17
|
+
return "unauthorized";
|
|
18
|
+
case 403:
|
|
19
|
+
return "forbidden";
|
|
20
|
+
case 404:
|
|
21
|
+
return "not_found";
|
|
22
|
+
case 429:
|
|
23
|
+
return "rate_limited";
|
|
24
|
+
default:
|
|
25
|
+
return "unknown";
|
|
26
|
+
}
|
|
27
|
+
}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -5,4 +5,6 @@ export { toISOString } from "./date";
|
|
|
5
5
|
export { isDev, getEnvVar, getAuthBaseUrl } from "./env";
|
|
6
6
|
export { extractSessionUser } from "./user-mapper";
|
|
7
7
|
export { isValidEmail, parseAuthError, isTokenExpiredError, getNameFromEmail, buildAuthUrl, buildAuthPath, clearAuthParams, AUTH_ERROR_CODES, type AuthErrorCode, type ParsedAuthError, } from "./auth-utils";
|
|
8
|
+
export { buildQueryString, type QueryParamValue, } from "./query-string";
|
|
9
|
+
export { mapHttpStatusToError, type HttpErrorType, } from "./error-mapper";
|
|
8
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AACpC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAClD,OAAO,EACL,YAAY,EACZ,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,KAAK,aAAa,EAClB,KAAK,eAAe,GACrB,MAAM,cAAc,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AACpC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,MAAM,OAAO,CAAA;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAClD,OAAO,EACL,YAAY,EACZ,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,YAAY,EACZ,aAAa,EACb,eAAe,EACf,gBAAgB,EAChB,KAAK,aAAa,EAClB,KAAK,eAAe,GACrB,MAAM,cAAc,CAAA;AACrB,OAAO,EACL,gBAAgB,EAChB,KAAK,eAAe,GACrB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EACL,oBAAoB,EACpB,KAAK,aAAa,GACnB,MAAM,gBAAgB,CAAA"}
|
package/dist/utils/index.js
CHANGED
|
@@ -5,3 +5,5 @@ export { toISOString } from "./date";
|
|
|
5
5
|
export { isDev, getEnvVar, getAuthBaseUrl } from "./env";
|
|
6
6
|
export { extractSessionUser } from "./user-mapper";
|
|
7
7
|
export { isValidEmail, parseAuthError, isTokenExpiredError, getNameFromEmail, buildAuthUrl, buildAuthPath, clearAuthParams, AUTH_ERROR_CODES, } from "./auth-utils";
|
|
8
|
+
export { buildQueryString, } from "./query-string";
|
|
9
|
+
export { mapHttpStatusToError, } from "./error-mapper";
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 查询字符串工具
|
|
3
|
+
*
|
|
4
|
+
* 提供统一的 URL 查询字符串构建功能
|
|
5
|
+
*/
|
|
6
|
+
/** 查询参数值类型 */
|
|
7
|
+
export type QueryParamValue = string | number | boolean | undefined | null;
|
|
8
|
+
/**
|
|
9
|
+
* 构建 URL 查询字符串
|
|
10
|
+
*
|
|
11
|
+
* @param params - 查询参数对象
|
|
12
|
+
* @returns 格式化的查询字符串(包含 ? 前缀),如果没有参数则返回空字符串
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* buildQueryString({ name: "test", active: true, page: undefined })
|
|
17
|
+
* // Returns: "?name=test&active=true"
|
|
18
|
+
*
|
|
19
|
+
* buildQueryString({})
|
|
20
|
+
* // Returns: ""
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export declare function buildQueryString(params: Record<string, QueryParamValue>): string;
|
|
24
|
+
//# sourceMappingURL=query-string.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-string.d.ts","sourceRoot":"","sources":["../../src/utils/query-string.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,cAAc;AACd,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,SAAS,GAAG,IAAI,CAAA;AAE1E;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC,GACtC,MAAM,CAiBR"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 查询字符串工具
|
|
3
|
+
*
|
|
4
|
+
* 提供统一的 URL 查询字符串构建功能
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* 构建 URL 查询字符串
|
|
8
|
+
*
|
|
9
|
+
* @param params - 查询参数对象
|
|
10
|
+
* @returns 格式化的查询字符串(包含 ? 前缀),如果没有参数则返回空字符串
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* buildQueryString({ name: "test", active: true, page: undefined })
|
|
15
|
+
* // Returns: "?name=test&active=true"
|
|
16
|
+
*
|
|
17
|
+
* buildQueryString({})
|
|
18
|
+
* // Returns: ""
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export function buildQueryString(params) {
|
|
22
|
+
const entries = Object.entries(params).filter(([, v]) => v !== undefined && v !== null);
|
|
23
|
+
if (entries.length === 0) {
|
|
24
|
+
return "";
|
|
25
|
+
}
|
|
26
|
+
const queryString = entries
|
|
27
|
+
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(String(value))}`)
|
|
28
|
+
.join("&");
|
|
29
|
+
return `?${queryString}`;
|
|
30
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@choiceform/shared-auth",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.24",
|
|
4
4
|
"description": "Shared authentication package for Choiceform projects",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -16,6 +16,14 @@
|
|
|
16
16
|
"dist",
|
|
17
17
|
"README.md"
|
|
18
18
|
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc",
|
|
21
|
+
"dev": "tsc --watch",
|
|
22
|
+
"clean": "rimraf dist",
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"test:watch": "vitest",
|
|
25
|
+
"prepublishOnly": "pnpm run build"
|
|
26
|
+
},
|
|
19
27
|
"repository": {
|
|
20
28
|
"type": "git",
|
|
21
29
|
"url": "git+https://github.com/choiceform/automation.git",
|
|
@@ -56,11 +64,5 @@
|
|
|
56
64
|
"typescript": "^5.5.3",
|
|
57
65
|
"vitest": "^3.2.4"
|
|
58
66
|
},
|
|
59
|
-
"
|
|
60
|
-
|
|
61
|
-
"dev": "tsc --watch",
|
|
62
|
-
"clean": "rimraf dist",
|
|
63
|
-
"test": "vitest run",
|
|
64
|
-
"test:watch": "vitest"
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
+
"packageManager": "pnpm@10.25.0+sha512.5e82639027af37cf832061bcc6d639c219634488e0f2baebe785028a793de7b525ffcd3f7ff574f5e9860654e098fe852ba8ac5dd5cefe1767d23a020a92f501"
|
|
68
|
+
}
|