@nvwa-app/sdk-shared 6.46.0 → 6.48.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 CHANGED
@@ -66,4 +66,17 @@ declare function collectPaymentClientContext(options: {
66
66
  getMiniProgramIdentity?: () => Promise<MiniProgramIdentityForPayment | null>;
67
67
  }): Promise<PaymentClientContext>;
68
68
 
69
- export { type CreatePaymentOrderRequest, PROJECT_PLATFORM_TYPES, type PaymentClientContext, type PaymentGatewayCreateOrderResult, type PaymentOrderResult, type ProjectPlatformType, collectPaymentClientContext, isProjectPlatformType, toPaymentOrderResultFromGateway };
69
+ type ParseCreatePaymentOrderRequestResult = {
70
+ ok: true;
71
+ request: CreatePaymentOrderRequest;
72
+ } | {
73
+ ok: false;
74
+ error: string;
75
+ };
76
+ /**
77
+ * 校验并解析业务「创建支付单」请求体(与 `CreatePaymentOrderRequest` 一致)。
78
+ * Edge Function 可先 `parseCreatePaymentOrderRequest(await req.json())`,再 `buildCreateOrderParams`。
79
+ */
80
+ declare function parseCreatePaymentOrderRequest(input: unknown): ParseCreatePaymentOrderRequestResult;
81
+
82
+ export { type CreatePaymentOrderRequest, PROJECT_PLATFORM_TYPES, type ParseCreatePaymentOrderRequestResult, type PaymentClientContext, type PaymentGatewayCreateOrderResult, type PaymentOrderResult, type ProjectPlatformType, collectPaymentClientContext, isProjectPlatformType, parseCreatePaymentOrderRequest, toPaymentOrderResultFromGateway };
package/dist/index.d.ts CHANGED
@@ -66,4 +66,17 @@ declare function collectPaymentClientContext(options: {
66
66
  getMiniProgramIdentity?: () => Promise<MiniProgramIdentityForPayment | null>;
67
67
  }): Promise<PaymentClientContext>;
68
68
 
69
- export { type CreatePaymentOrderRequest, PROJECT_PLATFORM_TYPES, type PaymentClientContext, type PaymentGatewayCreateOrderResult, type PaymentOrderResult, type ProjectPlatformType, collectPaymentClientContext, isProjectPlatformType, toPaymentOrderResultFromGateway };
69
+ type ParseCreatePaymentOrderRequestResult = {
70
+ ok: true;
71
+ request: CreatePaymentOrderRequest;
72
+ } | {
73
+ ok: false;
74
+ error: string;
75
+ };
76
+ /**
77
+ * 校验并解析业务「创建支付单」请求体(与 `CreatePaymentOrderRequest` 一致)。
78
+ * Edge Function 可先 `parseCreatePaymentOrderRequest(await req.json())`,再 `buildCreateOrderParams`。
79
+ */
80
+ declare function parseCreatePaymentOrderRequest(input: unknown): ParseCreatePaymentOrderRequestResult;
81
+
82
+ export { type CreatePaymentOrderRequest, PROJECT_PLATFORM_TYPES, type ParseCreatePaymentOrderRequestResult, type PaymentClientContext, type PaymentGatewayCreateOrderResult, type PaymentOrderResult, type ProjectPlatformType, collectPaymentClientContext, isProjectPlatformType, parseCreatePaymentOrderRequest, toPaymentOrderResultFromGateway };
package/dist/index.js CHANGED
@@ -23,6 +23,7 @@ __export(index_exports, {
23
23
  PROJECT_PLATFORM_TYPES: () => PROJECT_PLATFORM_TYPES,
24
24
  collectPaymentClientContext: () => collectPaymentClientContext,
25
25
  isProjectPlatformType: () => isProjectPlatformType,
26
+ parseCreatePaymentOrderRequest: () => parseCreatePaymentOrderRequest,
26
27
  toPaymentOrderResultFromGateway: () => toPaymentOrderResultFromGateway
27
28
  });
28
29
  module.exports = __toCommonJS(index_exports);
@@ -75,10 +76,78 @@ async function collectPaymentClientContext(options) {
75
76
  unionid: identity.unionid
76
77
  };
77
78
  }
79
+
80
+ // src/parse-create-payment-order-request.ts
81
+ function trimStr(v) {
82
+ return typeof v === "string" ? v.trim() : "";
83
+ }
84
+ function parseCreatePaymentOrderRequest(input) {
85
+ if (!input || typeof input !== "object" || Array.isArray(input)) {
86
+ return { ok: false, error: "Request body must be a JSON object" };
87
+ }
88
+ const body = input;
89
+ const clientRaw = body.client;
90
+ if (!clientRaw || typeof clientRaw !== "object" || Array.isArray(clientRaw)) {
91
+ return {
92
+ ok: false,
93
+ error: "client is required and must be an object with platformType (use collectPaymentClientContext / nvwa.payment.collectPaymentClientContext)"
94
+ };
95
+ }
96
+ const cr = clientRaw;
97
+ const platformTypeRaw = trimStr(cr.platformType);
98
+ if (!platformTypeRaw) {
99
+ return { ok: false, error: "client.platformType is required and must be non-empty" };
100
+ }
101
+ if (!isProjectPlatformType(platformTypeRaw)) {
102
+ return {
103
+ ok: false,
104
+ error: "client.platformType is invalid; use a valid ProjectPlatformType (e.g. DesktopWeb, MobileWeb, WechatMiniProgram)"
105
+ };
106
+ }
107
+ const client = { platformType: platformTypeRaw };
108
+ const puid = trimStr(cr.platformUserId);
109
+ if (puid) client.platformUserId = puid;
110
+ const appId = trimStr(cr.appId);
111
+ if (appId) client.appId = appId;
112
+ const unionid = trimStr(cr.unionid);
113
+ if (unionid) client.unionid = unionid;
114
+ const providerId = trimStr(body.providerId);
115
+ if (!providerId) {
116
+ return { ok: false, error: "providerId is required" };
117
+ }
118
+ const bizOrderId = trimStr(body.bizOrderId);
119
+ if (!bizOrderId) {
120
+ return { ok: false, error: "bizOrderId is required" };
121
+ }
122
+ const amount = body.amount;
123
+ if (typeof amount !== "number" || !Number.isFinite(amount) || amount <= 0) {
124
+ return { ok: false, error: "amount must be a positive number" };
125
+ }
126
+ const currencyRaw = trimStr(body.currency);
127
+ const returnUrlRaw = trimStr(body.returnUrl);
128
+ let metadata;
129
+ if (body.metadata != null) {
130
+ if (typeof body.metadata !== "object" || Array.isArray(body.metadata)) {
131
+ return { ok: false, error: "metadata must be a plain object when provided" };
132
+ }
133
+ metadata = { ...body.metadata };
134
+ }
135
+ const request = {
136
+ client,
137
+ bizOrderId,
138
+ amount,
139
+ providerId,
140
+ ...currencyRaw ? { currency: currencyRaw } : {},
141
+ ...returnUrlRaw ? { returnUrl: returnUrlRaw } : {},
142
+ ...metadata ? { metadata } : {}
143
+ };
144
+ return { ok: true, request };
145
+ }
78
146
  // Annotate the CommonJS export names for ESM import in node:
79
147
  0 && (module.exports = {
80
148
  PROJECT_PLATFORM_TYPES,
81
149
  collectPaymentClientContext,
82
150
  isProjectPlatformType,
151
+ parseCreatePaymentOrderRequest,
83
152
  toPaymentOrderResultFromGateway
84
153
  });
package/dist/index.mjs CHANGED
@@ -46,9 +46,77 @@ async function collectPaymentClientContext(options) {
46
46
  unionid: identity.unionid
47
47
  };
48
48
  }
49
+
50
+ // src/parse-create-payment-order-request.ts
51
+ function trimStr(v) {
52
+ return typeof v === "string" ? v.trim() : "";
53
+ }
54
+ function parseCreatePaymentOrderRequest(input) {
55
+ if (!input || typeof input !== "object" || Array.isArray(input)) {
56
+ return { ok: false, error: "Request body must be a JSON object" };
57
+ }
58
+ const body = input;
59
+ const clientRaw = body.client;
60
+ if (!clientRaw || typeof clientRaw !== "object" || Array.isArray(clientRaw)) {
61
+ return {
62
+ ok: false,
63
+ error: "client is required and must be an object with platformType (use collectPaymentClientContext / nvwa.payment.collectPaymentClientContext)"
64
+ };
65
+ }
66
+ const cr = clientRaw;
67
+ const platformTypeRaw = trimStr(cr.platformType);
68
+ if (!platformTypeRaw) {
69
+ return { ok: false, error: "client.platformType is required and must be non-empty" };
70
+ }
71
+ if (!isProjectPlatformType(platformTypeRaw)) {
72
+ return {
73
+ ok: false,
74
+ error: "client.platformType is invalid; use a valid ProjectPlatformType (e.g. DesktopWeb, MobileWeb, WechatMiniProgram)"
75
+ };
76
+ }
77
+ const client = { platformType: platformTypeRaw };
78
+ const puid = trimStr(cr.platformUserId);
79
+ if (puid) client.platformUserId = puid;
80
+ const appId = trimStr(cr.appId);
81
+ if (appId) client.appId = appId;
82
+ const unionid = trimStr(cr.unionid);
83
+ if (unionid) client.unionid = unionid;
84
+ const providerId = trimStr(body.providerId);
85
+ if (!providerId) {
86
+ return { ok: false, error: "providerId is required" };
87
+ }
88
+ const bizOrderId = trimStr(body.bizOrderId);
89
+ if (!bizOrderId) {
90
+ return { ok: false, error: "bizOrderId is required" };
91
+ }
92
+ const amount = body.amount;
93
+ if (typeof amount !== "number" || !Number.isFinite(amount) || amount <= 0) {
94
+ return { ok: false, error: "amount must be a positive number" };
95
+ }
96
+ const currencyRaw = trimStr(body.currency);
97
+ const returnUrlRaw = trimStr(body.returnUrl);
98
+ let metadata;
99
+ if (body.metadata != null) {
100
+ if (typeof body.metadata !== "object" || Array.isArray(body.metadata)) {
101
+ return { ok: false, error: "metadata must be a plain object when provided" };
102
+ }
103
+ metadata = { ...body.metadata };
104
+ }
105
+ const request = {
106
+ client,
107
+ bizOrderId,
108
+ amount,
109
+ providerId,
110
+ ...currencyRaw ? { currency: currencyRaw } : {},
111
+ ...returnUrlRaw ? { returnUrl: returnUrlRaw } : {},
112
+ ...metadata ? { metadata } : {}
113
+ };
114
+ return { ok: true, request };
115
+ }
49
116
  export {
50
117
  PROJECT_PLATFORM_TYPES,
51
118
  collectPaymentClientContext,
52
119
  isProjectPlatformType,
120
+ parseCreatePaymentOrderRequest,
53
121
  toPaymentOrderResultFromGateway
54
122
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nvwa-app/sdk-shared",
3
- "version": "6.46.0",
3
+ "version": "6.48.0",
4
4
  "description": "NVWA SDK 共享层:跨端/Functions 共用的类型与轻量工具(无 UI、无 PostgREST)。",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",