@nvwa-app/sdk-functions 6.41.0 → 6.42.0
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/index.d.mts +21 -3
- package/dist/index.d.ts +21 -3
- package/dist/index.js +41 -1
- package/dist/index.mjs +38 -1
- package/package.json +3 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { drizzle } from 'drizzle-orm/postgres-js';
|
|
2
|
+
import { CreatePaymentOrderRequest, ProjectPlatformType, PaymentOrderResult } from '@nvwa-app/sdk-shared';
|
|
3
|
+
export { CreatePaymentOrderRequest, PaymentClientContext, PaymentOrderResult, ProjectPlatformType, toPaymentOrderResultFromGateway } from '@nvwa-app/sdk-shared';
|
|
2
4
|
|
|
3
5
|
declare function getDb(): ReturnType<typeof drizzle>;
|
|
4
6
|
|
|
@@ -20,8 +22,6 @@ declare function getRequestUser(req: Request, baseUrlOverride?: string): Promise
|
|
|
20
22
|
|
|
21
23
|
/** 支付端类型:与 integrations/payment 中的 supportedPlatforms 一致,用于按端过滤可用 provider。 */
|
|
22
24
|
type PaymentPlatform = "web" | "uniapp" | "wechat-miniprogram" | "alipay-miniprogram";
|
|
23
|
-
/** 项目平台类型(透传到 payment-gateway 的 platformType 字段)。 */
|
|
24
|
-
type ProjectPlatformType = "DesktopWeb" | "MobileWeb" | "AndroidApp" | "IosApp" | "HarmonyApp" | "WechatMiniProgram" | "AlipayMiniProgram" | "DouyinMiniProgram";
|
|
25
25
|
interface PaymentGatewayClientOptions {
|
|
26
26
|
baseUrl: string;
|
|
27
27
|
/** Project key (PAYMENT_PROJECT_KEY) for project-side auth; gateway validates via X-Payment-Project-Key */
|
|
@@ -89,6 +89,24 @@ interface GetAvailableProvidersOptions {
|
|
|
89
89
|
configured?: string[];
|
|
90
90
|
}
|
|
91
91
|
declare function getAvailableProviders(options?: GetAvailableProvidersOptions): string[];
|
|
92
|
+
/** 服务端创建支付单时与 `CreatePaymentOrderRequest` 合并的字段(回调 URL、密钥、IP 等)。 */
|
|
93
|
+
interface CreatePaymentOrderServerOptions {
|
|
94
|
+
successNotifyUrl: string;
|
|
95
|
+
successNotifySecret?: string;
|
|
96
|
+
clientIp?: string;
|
|
97
|
+
workspaceId?: string;
|
|
98
|
+
projectId?: string;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* 将业务 API 请求体转为网关 `CreateOrderParams`。
|
|
102
|
+
*/
|
|
103
|
+
declare function buildCreateOrderParams(body: CreatePaymentOrderRequest, server: CreatePaymentOrderServerOptions): CreateOrderParams;
|
|
104
|
+
/**
|
|
105
|
+
* 业务创建支付单:合并请求体与 `CreatePaymentOrderServerOptions` 后调网关,返回 `@nvwa-app/sdk-shared` 的 `PaymentOrderResult`(前端可直接 `requestPayment`)。
|
|
106
|
+
*/
|
|
107
|
+
declare function createPaymentOrderForBusiness(gateway: PaymentGatewayClient, body: CreatePaymentOrderRequest, server: CreatePaymentOrderServerOptions, resultOptions?: {
|
|
108
|
+
order?: Record<string, unknown>;
|
|
109
|
+
}): Promise<PaymentOrderResult>;
|
|
92
110
|
/** 单例:Functions 内 getPayment() 使用 env PAYMENT_GATEWAY_URL、PAYMENT_PROJECT_KEY。 */
|
|
93
111
|
declare function getPayment(options?: PaymentGatewayClientOptions): PaymentGatewayClient;
|
|
94
112
|
|
|
@@ -111,4 +129,4 @@ interface CapabilityExecuteResponse<Data = unknown> {
|
|
|
111
129
|
*/
|
|
112
130
|
declare function executeCapability<Result = unknown>(capabilityName: string, param?: unknown, options?: ExecuteCapabilityOptions): Promise<Result | undefined>;
|
|
113
131
|
|
|
114
|
-
export { type AuthUser, type CapabilityExecuteResponse, type CreateOrderParams, type CreateOrderResult, type ExecuteCapabilityOptions, type GetAvailableProvidersOptions, type GetOrderResult, PAYMENT_SUCCESS_NOTIFY_SIGNATURE_HEADER, type PaymentGatewayClient, type PaymentGatewayClientOptions, type PaymentPlatform, type PaymentSuccessNotifyPayload, createPaymentClient, executeCapability, filterProvidersByPlatform, getAvailableProviders, getConfiguredProviders, getDb, getPayment, getRequestUser, parseSuccessNotifyPayload, providerSupportedPlatforms, verifyAndParseSuccessNotifyRequest, verifySuccessNotifySignature };
|
|
132
|
+
export { type AuthUser, type CapabilityExecuteResponse, type CreateOrderParams, type CreateOrderResult, type CreatePaymentOrderServerOptions, type ExecuteCapabilityOptions, type GetAvailableProvidersOptions, type GetOrderResult, PAYMENT_SUCCESS_NOTIFY_SIGNATURE_HEADER, type PaymentGatewayClient, type PaymentGatewayClientOptions, type PaymentPlatform, type PaymentSuccessNotifyPayload, buildCreateOrderParams, createPaymentClient, createPaymentOrderForBusiness, executeCapability, filterProvidersByPlatform, getAvailableProviders, getConfiguredProviders, getDb, getPayment, getRequestUser, parseSuccessNotifyPayload, providerSupportedPlatforms, verifyAndParseSuccessNotifyRequest, verifySuccessNotifySignature };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { drizzle } from 'drizzle-orm/postgres-js';
|
|
2
|
+
import { CreatePaymentOrderRequest, ProjectPlatformType, PaymentOrderResult } from '@nvwa-app/sdk-shared';
|
|
3
|
+
export { CreatePaymentOrderRequest, PaymentClientContext, PaymentOrderResult, ProjectPlatformType, toPaymentOrderResultFromGateway } from '@nvwa-app/sdk-shared';
|
|
2
4
|
|
|
3
5
|
declare function getDb(): ReturnType<typeof drizzle>;
|
|
4
6
|
|
|
@@ -20,8 +22,6 @@ declare function getRequestUser(req: Request, baseUrlOverride?: string): Promise
|
|
|
20
22
|
|
|
21
23
|
/** 支付端类型:与 integrations/payment 中的 supportedPlatforms 一致,用于按端过滤可用 provider。 */
|
|
22
24
|
type PaymentPlatform = "web" | "uniapp" | "wechat-miniprogram" | "alipay-miniprogram";
|
|
23
|
-
/** 项目平台类型(透传到 payment-gateway 的 platformType 字段)。 */
|
|
24
|
-
type ProjectPlatformType = "DesktopWeb" | "MobileWeb" | "AndroidApp" | "IosApp" | "HarmonyApp" | "WechatMiniProgram" | "AlipayMiniProgram" | "DouyinMiniProgram";
|
|
25
25
|
interface PaymentGatewayClientOptions {
|
|
26
26
|
baseUrl: string;
|
|
27
27
|
/** Project key (PAYMENT_PROJECT_KEY) for project-side auth; gateway validates via X-Payment-Project-Key */
|
|
@@ -89,6 +89,24 @@ interface GetAvailableProvidersOptions {
|
|
|
89
89
|
configured?: string[];
|
|
90
90
|
}
|
|
91
91
|
declare function getAvailableProviders(options?: GetAvailableProvidersOptions): string[];
|
|
92
|
+
/** 服务端创建支付单时与 `CreatePaymentOrderRequest` 合并的字段(回调 URL、密钥、IP 等)。 */
|
|
93
|
+
interface CreatePaymentOrderServerOptions {
|
|
94
|
+
successNotifyUrl: string;
|
|
95
|
+
successNotifySecret?: string;
|
|
96
|
+
clientIp?: string;
|
|
97
|
+
workspaceId?: string;
|
|
98
|
+
projectId?: string;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* 将业务 API 请求体转为网关 `CreateOrderParams`。
|
|
102
|
+
*/
|
|
103
|
+
declare function buildCreateOrderParams(body: CreatePaymentOrderRequest, server: CreatePaymentOrderServerOptions): CreateOrderParams;
|
|
104
|
+
/**
|
|
105
|
+
* 业务创建支付单:合并请求体与 `CreatePaymentOrderServerOptions` 后调网关,返回 `@nvwa-app/sdk-shared` 的 `PaymentOrderResult`(前端可直接 `requestPayment`)。
|
|
106
|
+
*/
|
|
107
|
+
declare function createPaymentOrderForBusiness(gateway: PaymentGatewayClient, body: CreatePaymentOrderRequest, server: CreatePaymentOrderServerOptions, resultOptions?: {
|
|
108
|
+
order?: Record<string, unknown>;
|
|
109
|
+
}): Promise<PaymentOrderResult>;
|
|
92
110
|
/** 单例:Functions 内 getPayment() 使用 env PAYMENT_GATEWAY_URL、PAYMENT_PROJECT_KEY。 */
|
|
93
111
|
declare function getPayment(options?: PaymentGatewayClientOptions): PaymentGatewayClient;
|
|
94
112
|
|
|
@@ -111,4 +129,4 @@ interface CapabilityExecuteResponse<Data = unknown> {
|
|
|
111
129
|
*/
|
|
112
130
|
declare function executeCapability<Result = unknown>(capabilityName: string, param?: unknown, options?: ExecuteCapabilityOptions): Promise<Result | undefined>;
|
|
113
131
|
|
|
114
|
-
export { type AuthUser, type CapabilityExecuteResponse, type CreateOrderParams, type CreateOrderResult, type ExecuteCapabilityOptions, type GetAvailableProvidersOptions, type GetOrderResult, PAYMENT_SUCCESS_NOTIFY_SIGNATURE_HEADER, type PaymentGatewayClient, type PaymentGatewayClientOptions, type PaymentPlatform, type PaymentSuccessNotifyPayload, createPaymentClient, executeCapability, filterProvidersByPlatform, getAvailableProviders, getConfiguredProviders, getDb, getPayment, getRequestUser, parseSuccessNotifyPayload, providerSupportedPlatforms, verifyAndParseSuccessNotifyRequest, verifySuccessNotifySignature };
|
|
132
|
+
export { type AuthUser, type CapabilityExecuteResponse, type CreateOrderParams, type CreateOrderResult, type CreatePaymentOrderServerOptions, type ExecuteCapabilityOptions, type GetAvailableProvidersOptions, type GetOrderResult, PAYMENT_SUCCESS_NOTIFY_SIGNATURE_HEADER, type PaymentGatewayClient, type PaymentGatewayClientOptions, type PaymentPlatform, type PaymentSuccessNotifyPayload, buildCreateOrderParams, createPaymentClient, createPaymentOrderForBusiness, executeCapability, filterProvidersByPlatform, getAvailableProviders, getConfiguredProviders, getDb, getPayment, getRequestUser, parseSuccessNotifyPayload, providerSupportedPlatforms, verifyAndParseSuccessNotifyRequest, verifySuccessNotifySignature };
|
package/dist/index.js
CHANGED
|
@@ -31,7 +31,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
PAYMENT_SUCCESS_NOTIFY_SIGNATURE_HEADER: () => PAYMENT_SUCCESS_NOTIFY_SIGNATURE_HEADER,
|
|
34
|
+
buildCreateOrderParams: () => buildCreateOrderParams,
|
|
34
35
|
createPaymentClient: () => createPaymentClient,
|
|
36
|
+
createPaymentOrderForBusiness: () => createPaymentOrderForBusiness,
|
|
35
37
|
executeCapability: () => executeCapability,
|
|
36
38
|
filterProvidersByPlatform: () => filterProvidersByPlatform,
|
|
37
39
|
getAvailableProviders: () => getAvailableProviders,
|
|
@@ -41,6 +43,7 @@ __export(index_exports, {
|
|
|
41
43
|
getRequestUser: () => getRequestUser,
|
|
42
44
|
parseSuccessNotifyPayload: () => parseSuccessNotifyPayload,
|
|
43
45
|
providerSupportedPlatforms: () => providerSupportedPlatforms,
|
|
46
|
+
toPaymentOrderResultFromGateway: () => import_sdk_shared2.toPaymentOrderResultFromGateway,
|
|
44
47
|
verifyAndParseSuccessNotifyRequest: () => verifyAndParseSuccessNotifyRequest,
|
|
45
48
|
verifySuccessNotifySignature: () => verifySuccessNotifySignature
|
|
46
49
|
});
|
|
@@ -101,9 +104,12 @@ async function getRequestUser(req, baseUrlOverride) {
|
|
|
101
104
|
}
|
|
102
105
|
|
|
103
106
|
// src/payment.ts
|
|
107
|
+
var import_sdk_shared = require("@nvwa-app/sdk-shared");
|
|
108
|
+
var import_sdk_shared2 = require("@nvwa-app/sdk-shared");
|
|
104
109
|
var PROVIDER_SUPPORTED_PLATFORMS = {
|
|
105
110
|
"wechat-pay": ["web", "uniapp", "wechat-miniprogram"],
|
|
106
|
-
"alipay": ["web", "uniapp"],
|
|
111
|
+
"alipay-web": ["web", "uniapp"],
|
|
112
|
+
"alipay-mobile-web": ["web", "uniapp"],
|
|
107
113
|
"alipay-miniprogram": ["alipay-miniprogram"],
|
|
108
114
|
"stripe": ["web"]
|
|
109
115
|
};
|
|
@@ -275,6 +281,37 @@ function getAvailableProviders(options) {
|
|
|
275
281
|
const configured = options?.configured ?? getConfiguredProviders();
|
|
276
282
|
return filterProvidersByPlatform(configured, options?.platform);
|
|
277
283
|
}
|
|
284
|
+
function buildCreateOrderParams(body, server) {
|
|
285
|
+
return {
|
|
286
|
+
bizOrderId: body.bizOrderId,
|
|
287
|
+
amount: body.amount,
|
|
288
|
+
currency: body.currency ?? "cny",
|
|
289
|
+
providerId: body.providerId,
|
|
290
|
+
platformUserId: body.client.platformUserId,
|
|
291
|
+
platformType: body.client.platformType,
|
|
292
|
+
metadata: body.metadata,
|
|
293
|
+
returnUrl: body.returnUrl,
|
|
294
|
+
successNotifyUrl: server.successNotifyUrl,
|
|
295
|
+
successNotifySecret: server.successNotifySecret,
|
|
296
|
+
clientIp: server.clientIp,
|
|
297
|
+
workspaceId: server.workspaceId,
|
|
298
|
+
projectId: server.projectId
|
|
299
|
+
};
|
|
300
|
+
}
|
|
301
|
+
async function createPaymentOrderForBusiness(gateway, body, server, resultOptions) {
|
|
302
|
+
const params = buildCreateOrderParams(body, server);
|
|
303
|
+
const data = await gateway.createOrder(params);
|
|
304
|
+
return (0, import_sdk_shared.toPaymentOrderResultFromGateway)(
|
|
305
|
+
{
|
|
306
|
+
platformOrderId: data.platformOrderId,
|
|
307
|
+
payParams: data.payParams
|
|
308
|
+
},
|
|
309
|
+
{
|
|
310
|
+
orderId: body.bizOrderId,
|
|
311
|
+
order: resultOptions?.order
|
|
312
|
+
}
|
|
313
|
+
);
|
|
314
|
+
}
|
|
278
315
|
var _payment = null;
|
|
279
316
|
function getPayment(options) {
|
|
280
317
|
if (options) return createPaymentClient(options);
|
|
@@ -372,7 +409,9 @@ ${projectCode}`;
|
|
|
372
409
|
// Annotate the CommonJS export names for ESM import in node:
|
|
373
410
|
0 && (module.exports = {
|
|
374
411
|
PAYMENT_SUCCESS_NOTIFY_SIGNATURE_HEADER,
|
|
412
|
+
buildCreateOrderParams,
|
|
375
413
|
createPaymentClient,
|
|
414
|
+
createPaymentOrderForBusiness,
|
|
376
415
|
executeCapability,
|
|
377
416
|
filterProvidersByPlatform,
|
|
378
417
|
getAvailableProviders,
|
|
@@ -382,6 +421,7 @@ ${projectCode}`;
|
|
|
382
421
|
getRequestUser,
|
|
383
422
|
parseSuccessNotifyPayload,
|
|
384
423
|
providerSupportedPlatforms,
|
|
424
|
+
toPaymentOrderResultFromGateway,
|
|
385
425
|
verifyAndParseSuccessNotifyRequest,
|
|
386
426
|
verifySuccessNotifySignature
|
|
387
427
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -53,9 +53,12 @@ async function getRequestUser(req, baseUrlOverride) {
|
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
// src/payment.ts
|
|
56
|
+
import { toPaymentOrderResultFromGateway } from "@nvwa-app/sdk-shared";
|
|
57
|
+
import { toPaymentOrderResultFromGateway as toPaymentOrderResultFromGateway2 } from "@nvwa-app/sdk-shared";
|
|
56
58
|
var PROVIDER_SUPPORTED_PLATFORMS = {
|
|
57
59
|
"wechat-pay": ["web", "uniapp", "wechat-miniprogram"],
|
|
58
|
-
"alipay": ["web", "uniapp"],
|
|
60
|
+
"alipay-web": ["web", "uniapp"],
|
|
61
|
+
"alipay-mobile-web": ["web", "uniapp"],
|
|
59
62
|
"alipay-miniprogram": ["alipay-miniprogram"],
|
|
60
63
|
"stripe": ["web"]
|
|
61
64
|
};
|
|
@@ -227,6 +230,37 @@ function getAvailableProviders(options) {
|
|
|
227
230
|
const configured = options?.configured ?? getConfiguredProviders();
|
|
228
231
|
return filterProvidersByPlatform(configured, options?.platform);
|
|
229
232
|
}
|
|
233
|
+
function buildCreateOrderParams(body, server) {
|
|
234
|
+
return {
|
|
235
|
+
bizOrderId: body.bizOrderId,
|
|
236
|
+
amount: body.amount,
|
|
237
|
+
currency: body.currency ?? "cny",
|
|
238
|
+
providerId: body.providerId,
|
|
239
|
+
platformUserId: body.client.platformUserId,
|
|
240
|
+
platformType: body.client.platformType,
|
|
241
|
+
metadata: body.metadata,
|
|
242
|
+
returnUrl: body.returnUrl,
|
|
243
|
+
successNotifyUrl: server.successNotifyUrl,
|
|
244
|
+
successNotifySecret: server.successNotifySecret,
|
|
245
|
+
clientIp: server.clientIp,
|
|
246
|
+
workspaceId: server.workspaceId,
|
|
247
|
+
projectId: server.projectId
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
async function createPaymentOrderForBusiness(gateway, body, server, resultOptions) {
|
|
251
|
+
const params = buildCreateOrderParams(body, server);
|
|
252
|
+
const data = await gateway.createOrder(params);
|
|
253
|
+
return toPaymentOrderResultFromGateway(
|
|
254
|
+
{
|
|
255
|
+
platformOrderId: data.platformOrderId,
|
|
256
|
+
payParams: data.payParams
|
|
257
|
+
},
|
|
258
|
+
{
|
|
259
|
+
orderId: body.bizOrderId,
|
|
260
|
+
order: resultOptions?.order
|
|
261
|
+
}
|
|
262
|
+
);
|
|
263
|
+
}
|
|
230
264
|
var _payment = null;
|
|
231
265
|
function getPayment(options) {
|
|
232
266
|
if (options) return createPaymentClient(options);
|
|
@@ -323,7 +357,9 @@ ${projectCode}`;
|
|
|
323
357
|
}
|
|
324
358
|
export {
|
|
325
359
|
PAYMENT_SUCCESS_NOTIFY_SIGNATURE_HEADER,
|
|
360
|
+
buildCreateOrderParams,
|
|
326
361
|
createPaymentClient,
|
|
362
|
+
createPaymentOrderForBusiness,
|
|
327
363
|
executeCapability,
|
|
328
364
|
filterProvidersByPlatform,
|
|
329
365
|
getAvailableProviders,
|
|
@@ -333,6 +369,7 @@ export {
|
|
|
333
369
|
getRequestUser,
|
|
334
370
|
parseSuccessNotifyPayload,
|
|
335
371
|
providerSupportedPlatforms,
|
|
372
|
+
toPaymentOrderResultFromGateway2 as toPaymentOrderResultFromGateway,
|
|
336
373
|
verifyAndParseSuccessNotifyRequest,
|
|
337
374
|
verifySuccessNotifySignature
|
|
338
375
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nvwa-app/sdk-functions",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.42.0",
|
|
4
4
|
"description": "NVWA Edge Functions SDK: db, payment gateway, auth, provider list. Use in Deno: import from 'npm:@nvwa-app/sdk-functions'.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
+
"@nvwa-app/sdk-shared": "file:../shared",
|
|
27
28
|
"drizzle-orm": "^0.44.7",
|
|
28
29
|
"postgres": "^3.4.8"
|
|
29
30
|
},
|
|
@@ -46,6 +47,7 @@
|
|
|
46
47
|
"minify": false,
|
|
47
48
|
"splitting": false,
|
|
48
49
|
"external": [
|
|
50
|
+
"@nvwa-app/sdk-shared",
|
|
49
51
|
"drizzle-orm",
|
|
50
52
|
"drizzle-orm/postgres-js",
|
|
51
53
|
"postgres"
|