@nvwa-app/sdk-shared 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.
@@ -0,0 +1,69 @@
1
+ /** 项目平台类型:支付与 app config 等链路统一使用。 */
2
+ type ProjectPlatformType = "DesktopWeb" | "MobileWeb" | "AndroidApp" | "IosApp" | "HarmonyApp" | "WechatMiniProgram" | "AlipayMiniProgram" | "DouyinMiniProgram";
3
+ declare const PROJECT_PLATFORM_TYPES: ProjectPlatformType[];
4
+ declare function isProjectPlatformType(value: string): value is ProjectPlatformType;
5
+
6
+ /**
7
+ * 前端收集后随创建支付单请求传给后端,映射网关 `platformType` / `platformUserId` 等。
8
+ * 由 `collectPaymentClientContext`(本包)或 `Nvwa.preparePaymentContext`(sdk-core)生成。
9
+ */
10
+ interface PaymentClientContext {
11
+ platformType: ProjectPlatformType;
12
+ platformUserId?: string;
13
+ appId?: string;
14
+ unionid?: string;
15
+ }
16
+ /**
17
+ * 业务创建支付单 API 的请求体(前端 → 可信后端)。
18
+ * 服务端用 `@nvwa-app/sdk-functions` 的 `buildCreateOrderParams` / `createPaymentOrderForBusiness` 合并 env 字段后调网关。
19
+ */
20
+ interface CreatePaymentOrderRequest {
21
+ client: PaymentClientContext;
22
+ bizOrderId: string;
23
+ amount: number;
24
+ currency?: string;
25
+ providerId: string;
26
+ metadata?: Record<string, unknown>;
27
+ returnUrl?: string;
28
+ }
29
+ /** 与 payment-gateway create 返回、`@nvwa-app/sdk-functions` 的 `CreateOrderResult` 对齐。 */
30
+ interface PaymentGatewayCreateOrderResult {
31
+ platformOrderId: string;
32
+ payParams: Record<string, unknown>;
33
+ }
34
+ /**
35
+ * 建单接口返回给前端的结构(JSON 友好);`payParams` 由网关下发,前端交给 `requestPayment`。
36
+ * sdk-core 的 `PayParams` 与此结构兼容(含 `Record<string, unknown>`)。
37
+ */
38
+ interface PaymentOrderResult {
39
+ orderId?: string;
40
+ platformOrderId?: string;
41
+ payParams: Record<string, unknown>;
42
+ codeUrl?: string;
43
+ formHtml?: string;
44
+ order?: Record<string, unknown>;
45
+ }
46
+ /**
47
+ * 将网关建单结果转为 `PaymentOrderResult`。
48
+ */
49
+ declare function toPaymentOrderResultFromGateway(gateway: PaymentGatewayCreateOrderResult, options?: {
50
+ orderId?: string;
51
+ order?: Record<string, unknown>;
52
+ }): PaymentOrderResult;
53
+
54
+ /** 与 `AuthClient.getMiniProgramIdentity`(sdk-core)非 null 返回值形状一致。 */
55
+ type MiniProgramIdentityForPayment = {
56
+ platformType: ProjectPlatformType;
57
+ appId: string;
58
+ platformUserId: string;
59
+ unionid?: string;
60
+ };
61
+ /**
62
+ * 收集支付客户端上下文:非小程序仅 `platformType`;微信/支付宝小程序在提供 `getMiniProgramIdentity` 时填入 openid 等。
63
+ */
64
+ declare function collectPaymentClientContext(options: {
65
+ platformType: ProjectPlatformType;
66
+ getMiniProgramIdentity?: () => Promise<MiniProgramIdentityForPayment | null>;
67
+ }): Promise<PaymentClientContext>;
68
+
69
+ export { type CreatePaymentOrderRequest, PROJECT_PLATFORM_TYPES, type PaymentClientContext, type PaymentGatewayCreateOrderResult, type PaymentOrderResult, type ProjectPlatformType, collectPaymentClientContext, isProjectPlatformType, toPaymentOrderResultFromGateway };
@@ -0,0 +1,69 @@
1
+ /** 项目平台类型:支付与 app config 等链路统一使用。 */
2
+ type ProjectPlatformType = "DesktopWeb" | "MobileWeb" | "AndroidApp" | "IosApp" | "HarmonyApp" | "WechatMiniProgram" | "AlipayMiniProgram" | "DouyinMiniProgram";
3
+ declare const PROJECT_PLATFORM_TYPES: ProjectPlatformType[];
4
+ declare function isProjectPlatformType(value: string): value is ProjectPlatformType;
5
+
6
+ /**
7
+ * 前端收集后随创建支付单请求传给后端,映射网关 `platformType` / `platformUserId` 等。
8
+ * 由 `collectPaymentClientContext`(本包)或 `Nvwa.preparePaymentContext`(sdk-core)生成。
9
+ */
10
+ interface PaymentClientContext {
11
+ platformType: ProjectPlatformType;
12
+ platformUserId?: string;
13
+ appId?: string;
14
+ unionid?: string;
15
+ }
16
+ /**
17
+ * 业务创建支付单 API 的请求体(前端 → 可信后端)。
18
+ * 服务端用 `@nvwa-app/sdk-functions` 的 `buildCreateOrderParams` / `createPaymentOrderForBusiness` 合并 env 字段后调网关。
19
+ */
20
+ interface CreatePaymentOrderRequest {
21
+ client: PaymentClientContext;
22
+ bizOrderId: string;
23
+ amount: number;
24
+ currency?: string;
25
+ providerId: string;
26
+ metadata?: Record<string, unknown>;
27
+ returnUrl?: string;
28
+ }
29
+ /** 与 payment-gateway create 返回、`@nvwa-app/sdk-functions` 的 `CreateOrderResult` 对齐。 */
30
+ interface PaymentGatewayCreateOrderResult {
31
+ platformOrderId: string;
32
+ payParams: Record<string, unknown>;
33
+ }
34
+ /**
35
+ * 建单接口返回给前端的结构(JSON 友好);`payParams` 由网关下发,前端交给 `requestPayment`。
36
+ * sdk-core 的 `PayParams` 与此结构兼容(含 `Record<string, unknown>`)。
37
+ */
38
+ interface PaymentOrderResult {
39
+ orderId?: string;
40
+ platformOrderId?: string;
41
+ payParams: Record<string, unknown>;
42
+ codeUrl?: string;
43
+ formHtml?: string;
44
+ order?: Record<string, unknown>;
45
+ }
46
+ /**
47
+ * 将网关建单结果转为 `PaymentOrderResult`。
48
+ */
49
+ declare function toPaymentOrderResultFromGateway(gateway: PaymentGatewayCreateOrderResult, options?: {
50
+ orderId?: string;
51
+ order?: Record<string, unknown>;
52
+ }): PaymentOrderResult;
53
+
54
+ /** 与 `AuthClient.getMiniProgramIdentity`(sdk-core)非 null 返回值形状一致。 */
55
+ type MiniProgramIdentityForPayment = {
56
+ platformType: ProjectPlatformType;
57
+ appId: string;
58
+ platformUserId: string;
59
+ unionid?: string;
60
+ };
61
+ /**
62
+ * 收集支付客户端上下文:非小程序仅 `platformType`;微信/支付宝小程序在提供 `getMiniProgramIdentity` 时填入 openid 等。
63
+ */
64
+ declare function collectPaymentClientContext(options: {
65
+ platformType: ProjectPlatformType;
66
+ getMiniProgramIdentity?: () => Promise<MiniProgramIdentityForPayment | null>;
67
+ }): Promise<PaymentClientContext>;
68
+
69
+ export { type CreatePaymentOrderRequest, PROJECT_PLATFORM_TYPES, type PaymentClientContext, type PaymentGatewayCreateOrderResult, type PaymentOrderResult, type ProjectPlatformType, collectPaymentClientContext, isProjectPlatformType, toPaymentOrderResultFromGateway };
package/dist/index.js ADDED
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ PROJECT_PLATFORM_TYPES: () => PROJECT_PLATFORM_TYPES,
24
+ collectPaymentClientContext: () => collectPaymentClientContext,
25
+ isProjectPlatformType: () => isProjectPlatformType,
26
+ toPaymentOrderResultFromGateway: () => toPaymentOrderResultFromGateway
27
+ });
28
+ module.exports = __toCommonJS(index_exports);
29
+
30
+ // src/platform.ts
31
+ var PROJECT_PLATFORM_TYPES = [
32
+ "DesktopWeb",
33
+ "MobileWeb",
34
+ "AndroidApp",
35
+ "IosApp",
36
+ "HarmonyApp",
37
+ "WechatMiniProgram",
38
+ "AlipayMiniProgram",
39
+ "DouyinMiniProgram"
40
+ ];
41
+ function isProjectPlatformType(value) {
42
+ return PROJECT_PLATFORM_TYPES.includes(value);
43
+ }
44
+
45
+ // src/payment-order.ts
46
+ function toPaymentOrderResultFromGateway(gateway, options) {
47
+ const payParams = gateway.payParams;
48
+ return {
49
+ orderId: options?.orderId,
50
+ platformOrderId: gateway.platformOrderId,
51
+ payParams,
52
+ codeUrl: typeof payParams.codeUrl === "string" ? payParams.codeUrl : void 0,
53
+ formHtml: typeof payParams.formHtml === "string" ? payParams.formHtml : void 0,
54
+ order: options?.order
55
+ };
56
+ }
57
+
58
+ // src/payment-client-context.ts
59
+ async function collectPaymentClientContext(options) {
60
+ const { platformType, getMiniProgramIdentity } = options;
61
+ if (platformType !== "WechatMiniProgram" && platformType !== "AlipayMiniProgram") {
62
+ return { platformType };
63
+ }
64
+ if (!getMiniProgramIdentity) {
65
+ return { platformType };
66
+ }
67
+ const identity = await getMiniProgramIdentity();
68
+ if (!identity) {
69
+ return { platformType };
70
+ }
71
+ return {
72
+ platformType: identity.platformType,
73
+ platformUserId: identity.platformUserId,
74
+ appId: identity.appId,
75
+ unionid: identity.unionid
76
+ };
77
+ }
78
+ // Annotate the CommonJS export names for ESM import in node:
79
+ 0 && (module.exports = {
80
+ PROJECT_PLATFORM_TYPES,
81
+ collectPaymentClientContext,
82
+ isProjectPlatformType,
83
+ toPaymentOrderResultFromGateway
84
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,54 @@
1
+ // src/platform.ts
2
+ var PROJECT_PLATFORM_TYPES = [
3
+ "DesktopWeb",
4
+ "MobileWeb",
5
+ "AndroidApp",
6
+ "IosApp",
7
+ "HarmonyApp",
8
+ "WechatMiniProgram",
9
+ "AlipayMiniProgram",
10
+ "DouyinMiniProgram"
11
+ ];
12
+ function isProjectPlatformType(value) {
13
+ return PROJECT_PLATFORM_TYPES.includes(value);
14
+ }
15
+
16
+ // src/payment-order.ts
17
+ function toPaymentOrderResultFromGateway(gateway, options) {
18
+ const payParams = gateway.payParams;
19
+ return {
20
+ orderId: options?.orderId,
21
+ platformOrderId: gateway.platformOrderId,
22
+ payParams,
23
+ codeUrl: typeof payParams.codeUrl === "string" ? payParams.codeUrl : void 0,
24
+ formHtml: typeof payParams.formHtml === "string" ? payParams.formHtml : void 0,
25
+ order: options?.order
26
+ };
27
+ }
28
+
29
+ // src/payment-client-context.ts
30
+ async function collectPaymentClientContext(options) {
31
+ const { platformType, getMiniProgramIdentity } = options;
32
+ if (platformType !== "WechatMiniProgram" && platformType !== "AlipayMiniProgram") {
33
+ return { platformType };
34
+ }
35
+ if (!getMiniProgramIdentity) {
36
+ return { platformType };
37
+ }
38
+ const identity = await getMiniProgramIdentity();
39
+ if (!identity) {
40
+ return { platformType };
41
+ }
42
+ return {
43
+ platformType: identity.platformType,
44
+ platformUserId: identity.platformUserId,
45
+ appId: identity.appId,
46
+ unionid: identity.unionid
47
+ };
48
+ }
49
+ export {
50
+ PROJECT_PLATFORM_TYPES,
51
+ collectPaymentClientContext,
52
+ isProjectPlatformType,
53
+ toPaymentOrderResultFromGateway
54
+ };
package/package.json ADDED
@@ -0,0 +1,56 @@
1
+ {
2
+ "name": "@nvwa-app/sdk-shared",
3
+ "version": "6.42.0",
4
+ "description": "NVWA SDK 共享层:跨端/Functions 共用的类型与轻量工具(无 UI、无 PostgREST)。",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.mjs",
7
+ "types": "dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.mjs",
11
+ "require": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ }
14
+ },
15
+ "files": [
16
+ "dist/**/*"
17
+ ],
18
+ "scripts": {
19
+ "build": "tsup",
20
+ "dev": "tsup --watch",
21
+ "prepublishOnly": "npm run build"
22
+ },
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "https://github.com/nvwa-project/nvwa-coder.git",
29
+ "directory": "packages/sdk/shared"
30
+ },
31
+ "devDependencies": {
32
+ "@types/node": "^24.3.0",
33
+ "tsup": "^8.1.0",
34
+ "typescript": "^5.9.2"
35
+ },
36
+ "tsup": {
37
+ "entry": [
38
+ "src/index.ts"
39
+ ],
40
+ "outDir": "dist",
41
+ "clean": true,
42
+ "dts": true,
43
+ "format": [
44
+ "esm",
45
+ "cjs"
46
+ ],
47
+ "minify": false,
48
+ "splitting": false
49
+ },
50
+ "keywords": [
51
+ "nvwa",
52
+ "sdk",
53
+ "types"
54
+ ],
55
+ "license": "ISC"
56
+ }