@nvwa-app/sdk-functions 6.0.31

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,75 @@
1
+ import { drizzle } from 'drizzle-orm/postgres-js';
2
+
3
+ declare function createDb(url: string): ReturnType<typeof drizzle>;
4
+ declare function getDb(urlOverride?: string): ReturnType<typeof drizzle>;
5
+
6
+ interface AuthUser {
7
+ id: string;
8
+ name?: string;
9
+ email?: string;
10
+ username?: string;
11
+ displayUsername?: string;
12
+ phoneNumber?: string;
13
+ role?: string;
14
+ image?: string;
15
+ [k: string]: unknown;
16
+ }
17
+ /**
18
+ * 从 Request 的 Authorization: Bearer 取 token,请求 GET /auth/session,返回当前用户或 null。
19
+ */
20
+ declare function getRequestUser(req: Request, baseUrlOverride?: string): Promise<AuthUser | null>;
21
+
22
+ /** 支付端类型:与 integrations/payment 中的 supportedPlatforms 一致,用于按端过滤可用 provider。 */
23
+ type PaymentPlatform = "web" | "uniapp" | "wechat-miniprogram";
24
+ interface PaymentGatewayClientOptions {
25
+ baseUrl: string;
26
+ token: string;
27
+ fetchImpl?: (input: string, init?: RequestInit) => Promise<Response>;
28
+ }
29
+ interface CreateOrderParams {
30
+ bizOrderId: string;
31
+ amount: number;
32
+ currency?: string;
33
+ providerId: string;
34
+ clientIp?: string;
35
+ returnUrl?: string;
36
+ successNotifyUrl: string;
37
+ successNotifySecret?: string;
38
+ metadata?: Record<string, unknown>;
39
+ workspaceId?: string;
40
+ projectId?: string;
41
+ }
42
+ interface CreateOrderResult {
43
+ platformOrderId: string;
44
+ payParams: Record<string, unknown> | {
45
+ codeUrl?: string;
46
+ formHtml?: string;
47
+ clientSecret?: string;
48
+ };
49
+ }
50
+ interface GetOrderResult {
51
+ platformOrderId: string;
52
+ providerId: string;
53
+ providerOrderId?: string;
54
+ status: string;
55
+ amount: number;
56
+ currency: string;
57
+ raw: Record<string, unknown>;
58
+ }
59
+ interface PaymentGatewayClient {
60
+ createOrder(params: CreateOrderParams): Promise<CreateOrderResult>;
61
+ getOrder(platformOrderId: string): Promise<GetOrderResult>;
62
+ }
63
+ declare function createPaymentClient(options?: PaymentGatewayClientOptions): PaymentGatewayClient;
64
+ declare function filterProvidersByPlatform(configured: string[], platform?: PaymentPlatform): string[];
65
+ declare const providerSupportedPlatforms: Record<string, PaymentPlatform[]>;
66
+ declare function getConfiguredProviders(): string[];
67
+ interface GetAvailableProvidersOptions {
68
+ platform?: PaymentPlatform;
69
+ configured?: string[];
70
+ }
71
+ declare function getAvailableProviders(options?: GetAvailableProvidersOptions): string[];
72
+ /** 单例:Functions 内 getPayment() 使用 env PAYMENT_GATEWAY_URL、PAYMENT_GATEWAY_INTERNAL_TOKEN。 */
73
+ declare function getPayment(options?: PaymentGatewayClientOptions): PaymentGatewayClient;
74
+
75
+ export { type AuthUser, type CreateOrderParams, type CreateOrderResult, type GetAvailableProvidersOptions, type GetOrderResult, type PaymentGatewayClient, type PaymentGatewayClientOptions, type PaymentPlatform, createDb, createPaymentClient, filterProvidersByPlatform, getAvailableProviders, getConfiguredProviders, getDb, getPayment, getRequestUser, providerSupportedPlatforms };
@@ -0,0 +1,75 @@
1
+ import { drizzle } from 'drizzle-orm/postgres-js';
2
+
3
+ declare function createDb(url: string): ReturnType<typeof drizzle>;
4
+ declare function getDb(urlOverride?: string): ReturnType<typeof drizzle>;
5
+
6
+ interface AuthUser {
7
+ id: string;
8
+ name?: string;
9
+ email?: string;
10
+ username?: string;
11
+ displayUsername?: string;
12
+ phoneNumber?: string;
13
+ role?: string;
14
+ image?: string;
15
+ [k: string]: unknown;
16
+ }
17
+ /**
18
+ * 从 Request 的 Authorization: Bearer 取 token,请求 GET /auth/session,返回当前用户或 null。
19
+ */
20
+ declare function getRequestUser(req: Request, baseUrlOverride?: string): Promise<AuthUser | null>;
21
+
22
+ /** 支付端类型:与 integrations/payment 中的 supportedPlatforms 一致,用于按端过滤可用 provider。 */
23
+ type PaymentPlatform = "web" | "uniapp" | "wechat-miniprogram";
24
+ interface PaymentGatewayClientOptions {
25
+ baseUrl: string;
26
+ token: string;
27
+ fetchImpl?: (input: string, init?: RequestInit) => Promise<Response>;
28
+ }
29
+ interface CreateOrderParams {
30
+ bizOrderId: string;
31
+ amount: number;
32
+ currency?: string;
33
+ providerId: string;
34
+ clientIp?: string;
35
+ returnUrl?: string;
36
+ successNotifyUrl: string;
37
+ successNotifySecret?: string;
38
+ metadata?: Record<string, unknown>;
39
+ workspaceId?: string;
40
+ projectId?: string;
41
+ }
42
+ interface CreateOrderResult {
43
+ platformOrderId: string;
44
+ payParams: Record<string, unknown> | {
45
+ codeUrl?: string;
46
+ formHtml?: string;
47
+ clientSecret?: string;
48
+ };
49
+ }
50
+ interface GetOrderResult {
51
+ platformOrderId: string;
52
+ providerId: string;
53
+ providerOrderId?: string;
54
+ status: string;
55
+ amount: number;
56
+ currency: string;
57
+ raw: Record<string, unknown>;
58
+ }
59
+ interface PaymentGatewayClient {
60
+ createOrder(params: CreateOrderParams): Promise<CreateOrderResult>;
61
+ getOrder(platformOrderId: string): Promise<GetOrderResult>;
62
+ }
63
+ declare function createPaymentClient(options?: PaymentGatewayClientOptions): PaymentGatewayClient;
64
+ declare function filterProvidersByPlatform(configured: string[], platform?: PaymentPlatform): string[];
65
+ declare const providerSupportedPlatforms: Record<string, PaymentPlatform[]>;
66
+ declare function getConfiguredProviders(): string[];
67
+ interface GetAvailableProvidersOptions {
68
+ platform?: PaymentPlatform;
69
+ configured?: string[];
70
+ }
71
+ declare function getAvailableProviders(options?: GetAvailableProvidersOptions): string[];
72
+ /** 单例:Functions 内 getPayment() 使用 env PAYMENT_GATEWAY_URL、PAYMENT_GATEWAY_INTERNAL_TOKEN。 */
73
+ declare function getPayment(options?: PaymentGatewayClientOptions): PaymentGatewayClient;
74
+
75
+ export { type AuthUser, type CreateOrderParams, type CreateOrderResult, type GetAvailableProvidersOptions, type GetOrderResult, type PaymentGatewayClient, type PaymentGatewayClientOptions, type PaymentPlatform, createDb, createPaymentClient, filterProvidersByPlatform, getAvailableProviders, getConfiguredProviders, getDb, getPayment, getRequestUser, providerSupportedPlatforms };
package/dist/index.js ADDED
@@ -0,0 +1,233 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ createDb: () => createDb,
34
+ createPaymentClient: () => createPaymentClient,
35
+ filterProvidersByPlatform: () => filterProvidersByPlatform,
36
+ getAvailableProviders: () => getAvailableProviders,
37
+ getConfiguredProviders: () => getConfiguredProviders,
38
+ getDb: () => getDb,
39
+ getPayment: () => getPayment,
40
+ getRequestUser: () => getRequestUser,
41
+ providerSupportedPlatforms: () => providerSupportedPlatforms
42
+ });
43
+ module.exports = __toCommonJS(index_exports);
44
+
45
+ // src/db.ts
46
+ var import_postgres_js = require("drizzle-orm/postgres-js");
47
+ var import_postgres = __toESM(require("postgres"));
48
+
49
+ // src/env.ts
50
+ function getEnv(key) {
51
+ if (typeof globalThis.Deno !== "undefined") {
52
+ return globalThis.Deno.env.get(key);
53
+ }
54
+ return globalThis.process?.env?.[key];
55
+ }
56
+
57
+ // src/db.ts
58
+ function getDatabaseUrl() {
59
+ const url = getEnv("DATABASE_URL");
60
+ if (url) return url;
61
+ const user = getEnv("DB_USER");
62
+ const password = getEnv("DB_PASSWORD");
63
+ const endpoint = getEnv("DB_ENDPOINT");
64
+ const database = getEnv("DB_DATABASE");
65
+ if (!user || !password || !endpoint || !database) {
66
+ throw new Error(
67
+ "Database config missing: set DATABASE_URL or DB_USER, DB_PASSWORD, DB_ENDPOINT, DB_DATABASE"
68
+ );
69
+ }
70
+ const safeUser = encodeURIComponent(user);
71
+ const safePassword = encodeURIComponent(password);
72
+ return `postgresql://${safeUser}:${safePassword}@${endpoint}/${database}`;
73
+ }
74
+ var _db = null;
75
+ function createDb(url) {
76
+ const client = (0, import_postgres.default)(url, { max: 1 });
77
+ return (0, import_postgres_js.drizzle)(client);
78
+ }
79
+ function getDb(urlOverride) {
80
+ if (urlOverride) return createDb(urlOverride);
81
+ if (!_db) _db = createDb(getDatabaseUrl());
82
+ return _db;
83
+ }
84
+
85
+ // src/auth.ts
86
+ function getBaseUrl(override) {
87
+ const url = override ?? getEnv("PROJECT_BACKEND_URL");
88
+ if (url) return url.replace(/\/$/, "");
89
+ throw new Error("PROJECT_BACKEND_URL is not set; getRequestUser requires it to call /auth/session");
90
+ }
91
+ async function getRequestUser(req, baseUrlOverride) {
92
+ const bearer = req.headers.get("Authorization")?.trim();
93
+ if (!bearer?.startsWith("Bearer ")) return null;
94
+ const token = bearer.slice(7);
95
+ if (!token) return null;
96
+ const base = getBaseUrl(baseUrlOverride);
97
+ const res = await fetch(`${base}/auth/session`, {
98
+ method: "GET",
99
+ headers: { Authorization: `Bearer ${token}` }
100
+ });
101
+ if (!res.ok) return null;
102
+ const data = await res.json();
103
+ return data?.user ?? null;
104
+ }
105
+
106
+ // src/payment.ts
107
+ var PROVIDER_SUPPORTED_PLATFORMS = {
108
+ "wechat-pay": ["web", "uniapp", "wechat-miniprogram"],
109
+ "alipay": ["web", "uniapp"],
110
+ "stripe": ["web"]
111
+ };
112
+ function resolveBaseUrl(explicit) {
113
+ const url = explicit ?? getEnv("PAYMENT_GATEWAY_URL");
114
+ if (!url) throw new Error("PAYMENT_GATEWAY_URL is not set; payment gateway client requires it");
115
+ return url.replace(/\/$/, "");
116
+ }
117
+ function resolveToken(explicit) {
118
+ const token = explicit ?? getEnv("PAYMENT_GATEWAY_INTERNAL_TOKEN");
119
+ if (!token) throw new Error("PAYMENT_GATEWAY_INTERNAL_TOKEN is not set; payment gateway client requires it");
120
+ return token;
121
+ }
122
+ function getDefaultFetch() {
123
+ if (typeof fetch === "function") return (input, init) => fetch(input, init);
124
+ throw new Error("Global fetch is not available; provide fetchImpl in PaymentGatewayClientOptions");
125
+ }
126
+ function createPaymentClient(options) {
127
+ const baseUrl = resolveBaseUrl(options?.baseUrl);
128
+ const token = resolveToken(options?.token);
129
+ const doFetch = options?.fetchImpl ?? getDefaultFetch();
130
+ async function post(path, body) {
131
+ const res = await doFetch(`${baseUrl}${path}`, {
132
+ method: "POST",
133
+ headers: { "Content-Type": "application/json", "Authorization": `Bearer ${token}`, "X-Internal-Token": token },
134
+ body: JSON.stringify(body ?? {})
135
+ });
136
+ const text = await res.text();
137
+ let json;
138
+ try {
139
+ json = text ? JSON.parse(text) : {};
140
+ } catch {
141
+ throw new Error(`Gateway POST ${path} failed: ${res.status} ${text}`);
142
+ }
143
+ if (!res.ok) throw new Error(json.error ?? `Gateway POST ${path} failed: ${res.status}`);
144
+ const data = json;
145
+ if (data.ok === false) throw new Error(data.error ?? `Gateway POST ${path} returned ok=false`);
146
+ return data.data;
147
+ }
148
+ async function get(path) {
149
+ const res = await doFetch(`${baseUrl}${path}`, {
150
+ method: "GET",
151
+ headers: { "Authorization": `Bearer ${token}`, "X-Internal-Token": token }
152
+ });
153
+ const text = await res.text();
154
+ let json;
155
+ try {
156
+ json = text ? JSON.parse(text) : {};
157
+ } catch {
158
+ throw new Error(`Gateway GET ${path} failed: ${res.status} ${text}`);
159
+ }
160
+ if (!res.ok) throw new Error(json.error ?? `Gateway GET ${path} failed: ${res.status}`);
161
+ const data = json;
162
+ if (data.ok === false) throw new Error(data.error ?? `Gateway GET ${path} returned ok=false`);
163
+ return data.data;
164
+ }
165
+ return {
166
+ async createOrder(params) {
167
+ const payload = {
168
+ workspaceId: params.workspaceId,
169
+ projectId: params.projectId,
170
+ bizOrderId: params.bizOrderId,
171
+ amount: params.amount,
172
+ currency: params.currency ?? "cny",
173
+ providerId: params.providerId,
174
+ clientIp: params.clientIp,
175
+ returnUrl: params.returnUrl,
176
+ successNotifyUrl: params.successNotifyUrl,
177
+ successNotifySecret: params.successNotifySecret,
178
+ metadata: params.metadata
179
+ };
180
+ const data = await post("/api/platform/payment/create", payload);
181
+ return { platformOrderId: data.platformOrderId, payParams: data.payParams };
182
+ },
183
+ async getOrder(platformOrderId) {
184
+ const data = await get(`/api/platform/payment/orders/${encodeURIComponent(platformOrderId)}`);
185
+ return {
186
+ platformOrderId: String(data.platformOrderId ?? platformOrderId),
187
+ providerId: String(data.providerId ?? ""),
188
+ providerOrderId: typeof data.providerOrderId === "string" ? data.providerOrderId : void 0,
189
+ status: String(data.status ?? "pending"),
190
+ amount: Number(data.amount ?? 0),
191
+ currency: String(data.currency ?? "cny"),
192
+ raw: data
193
+ };
194
+ }
195
+ };
196
+ }
197
+ function filterProvidersByPlatform(configured, platform) {
198
+ if (!platform) return [...configured];
199
+ return configured.filter((id) => {
200
+ const platforms = PROVIDER_SUPPORTED_PLATFORMS[id];
201
+ if (!platforms || platforms.length === 0) return true;
202
+ return platforms.includes(platform);
203
+ });
204
+ }
205
+ var providerSupportedPlatforms = PROVIDER_SUPPORTED_PLATFORMS;
206
+ var PAYMENT_PROVIDERS_ENV_KEY = "PAYMENT_PROVIDERS";
207
+ function getConfiguredProviders() {
208
+ const raw = getEnv(PAYMENT_PROVIDERS_ENV_KEY);
209
+ if (!raw || typeof raw !== "string") return [];
210
+ return raw.split(",").map((s) => s.trim()).filter(Boolean);
211
+ }
212
+ function getAvailableProviders(options) {
213
+ const configured = options?.configured ?? getConfiguredProviders();
214
+ return filterProvidersByPlatform(configured, options?.platform);
215
+ }
216
+ var _payment = null;
217
+ function getPayment(options) {
218
+ if (options) return createPaymentClient(options);
219
+ if (!_payment) _payment = createPaymentClient();
220
+ return _payment;
221
+ }
222
+ // Annotate the CommonJS export names for ESM import in node:
223
+ 0 && (module.exports = {
224
+ createDb,
225
+ createPaymentClient,
226
+ filterProvidersByPlatform,
227
+ getAvailableProviders,
228
+ getConfiguredProviders,
229
+ getDb,
230
+ getPayment,
231
+ getRequestUser,
232
+ providerSupportedPlatforms
233
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,188 @@
1
+ // src/db.ts
2
+ import { drizzle } from "drizzle-orm/postgres-js";
3
+ import postgres from "postgres";
4
+
5
+ // src/env.ts
6
+ function getEnv(key) {
7
+ if (typeof globalThis.Deno !== "undefined") {
8
+ return globalThis.Deno.env.get(key);
9
+ }
10
+ return globalThis.process?.env?.[key];
11
+ }
12
+
13
+ // src/db.ts
14
+ function getDatabaseUrl() {
15
+ const url = getEnv("DATABASE_URL");
16
+ if (url) return url;
17
+ const user = getEnv("DB_USER");
18
+ const password = getEnv("DB_PASSWORD");
19
+ const endpoint = getEnv("DB_ENDPOINT");
20
+ const database = getEnv("DB_DATABASE");
21
+ if (!user || !password || !endpoint || !database) {
22
+ throw new Error(
23
+ "Database config missing: set DATABASE_URL or DB_USER, DB_PASSWORD, DB_ENDPOINT, DB_DATABASE"
24
+ );
25
+ }
26
+ const safeUser = encodeURIComponent(user);
27
+ const safePassword = encodeURIComponent(password);
28
+ return `postgresql://${safeUser}:${safePassword}@${endpoint}/${database}`;
29
+ }
30
+ var _db = null;
31
+ function createDb(url) {
32
+ const client = postgres(url, { max: 1 });
33
+ return drizzle(client);
34
+ }
35
+ function getDb(urlOverride) {
36
+ if (urlOverride) return createDb(urlOverride);
37
+ if (!_db) _db = createDb(getDatabaseUrl());
38
+ return _db;
39
+ }
40
+
41
+ // src/auth.ts
42
+ function getBaseUrl(override) {
43
+ const url = override ?? getEnv("PROJECT_BACKEND_URL");
44
+ if (url) return url.replace(/\/$/, "");
45
+ throw new Error("PROJECT_BACKEND_URL is not set; getRequestUser requires it to call /auth/session");
46
+ }
47
+ async function getRequestUser(req, baseUrlOverride) {
48
+ const bearer = req.headers.get("Authorization")?.trim();
49
+ if (!bearer?.startsWith("Bearer ")) return null;
50
+ const token = bearer.slice(7);
51
+ if (!token) return null;
52
+ const base = getBaseUrl(baseUrlOverride);
53
+ const res = await fetch(`${base}/auth/session`, {
54
+ method: "GET",
55
+ headers: { Authorization: `Bearer ${token}` }
56
+ });
57
+ if (!res.ok) return null;
58
+ const data = await res.json();
59
+ return data?.user ?? null;
60
+ }
61
+
62
+ // src/payment.ts
63
+ var PROVIDER_SUPPORTED_PLATFORMS = {
64
+ "wechat-pay": ["web", "uniapp", "wechat-miniprogram"],
65
+ "alipay": ["web", "uniapp"],
66
+ "stripe": ["web"]
67
+ };
68
+ function resolveBaseUrl(explicit) {
69
+ const url = explicit ?? getEnv("PAYMENT_GATEWAY_URL");
70
+ if (!url) throw new Error("PAYMENT_GATEWAY_URL is not set; payment gateway client requires it");
71
+ return url.replace(/\/$/, "");
72
+ }
73
+ function resolveToken(explicit) {
74
+ const token = explicit ?? getEnv("PAYMENT_GATEWAY_INTERNAL_TOKEN");
75
+ if (!token) throw new Error("PAYMENT_GATEWAY_INTERNAL_TOKEN is not set; payment gateway client requires it");
76
+ return token;
77
+ }
78
+ function getDefaultFetch() {
79
+ if (typeof fetch === "function") return (input, init) => fetch(input, init);
80
+ throw new Error("Global fetch is not available; provide fetchImpl in PaymentGatewayClientOptions");
81
+ }
82
+ function createPaymentClient(options) {
83
+ const baseUrl = resolveBaseUrl(options?.baseUrl);
84
+ const token = resolveToken(options?.token);
85
+ const doFetch = options?.fetchImpl ?? getDefaultFetch();
86
+ async function post(path, body) {
87
+ const res = await doFetch(`${baseUrl}${path}`, {
88
+ method: "POST",
89
+ headers: { "Content-Type": "application/json", "Authorization": `Bearer ${token}`, "X-Internal-Token": token },
90
+ body: JSON.stringify(body ?? {})
91
+ });
92
+ const text = await res.text();
93
+ let json;
94
+ try {
95
+ json = text ? JSON.parse(text) : {};
96
+ } catch {
97
+ throw new Error(`Gateway POST ${path} failed: ${res.status} ${text}`);
98
+ }
99
+ if (!res.ok) throw new Error(json.error ?? `Gateway POST ${path} failed: ${res.status}`);
100
+ const data = json;
101
+ if (data.ok === false) throw new Error(data.error ?? `Gateway POST ${path} returned ok=false`);
102
+ return data.data;
103
+ }
104
+ async function get(path) {
105
+ const res = await doFetch(`${baseUrl}${path}`, {
106
+ method: "GET",
107
+ headers: { "Authorization": `Bearer ${token}`, "X-Internal-Token": token }
108
+ });
109
+ const text = await res.text();
110
+ let json;
111
+ try {
112
+ json = text ? JSON.parse(text) : {};
113
+ } catch {
114
+ throw new Error(`Gateway GET ${path} failed: ${res.status} ${text}`);
115
+ }
116
+ if (!res.ok) throw new Error(json.error ?? `Gateway GET ${path} failed: ${res.status}`);
117
+ const data = json;
118
+ if (data.ok === false) throw new Error(data.error ?? `Gateway GET ${path} returned ok=false`);
119
+ return data.data;
120
+ }
121
+ return {
122
+ async createOrder(params) {
123
+ const payload = {
124
+ workspaceId: params.workspaceId,
125
+ projectId: params.projectId,
126
+ bizOrderId: params.bizOrderId,
127
+ amount: params.amount,
128
+ currency: params.currency ?? "cny",
129
+ providerId: params.providerId,
130
+ clientIp: params.clientIp,
131
+ returnUrl: params.returnUrl,
132
+ successNotifyUrl: params.successNotifyUrl,
133
+ successNotifySecret: params.successNotifySecret,
134
+ metadata: params.metadata
135
+ };
136
+ const data = await post("/api/platform/payment/create", payload);
137
+ return { platformOrderId: data.platformOrderId, payParams: data.payParams };
138
+ },
139
+ async getOrder(platformOrderId) {
140
+ const data = await get(`/api/platform/payment/orders/${encodeURIComponent(platformOrderId)}`);
141
+ return {
142
+ platformOrderId: String(data.platformOrderId ?? platformOrderId),
143
+ providerId: String(data.providerId ?? ""),
144
+ providerOrderId: typeof data.providerOrderId === "string" ? data.providerOrderId : void 0,
145
+ status: String(data.status ?? "pending"),
146
+ amount: Number(data.amount ?? 0),
147
+ currency: String(data.currency ?? "cny"),
148
+ raw: data
149
+ };
150
+ }
151
+ };
152
+ }
153
+ function filterProvidersByPlatform(configured, platform) {
154
+ if (!platform) return [...configured];
155
+ return configured.filter((id) => {
156
+ const platforms = PROVIDER_SUPPORTED_PLATFORMS[id];
157
+ if (!platforms || platforms.length === 0) return true;
158
+ return platforms.includes(platform);
159
+ });
160
+ }
161
+ var providerSupportedPlatforms = PROVIDER_SUPPORTED_PLATFORMS;
162
+ var PAYMENT_PROVIDERS_ENV_KEY = "PAYMENT_PROVIDERS";
163
+ function getConfiguredProviders() {
164
+ const raw = getEnv(PAYMENT_PROVIDERS_ENV_KEY);
165
+ if (!raw || typeof raw !== "string") return [];
166
+ return raw.split(",").map((s) => s.trim()).filter(Boolean);
167
+ }
168
+ function getAvailableProviders(options) {
169
+ const configured = options?.configured ?? getConfiguredProviders();
170
+ return filterProvidersByPlatform(configured, options?.platform);
171
+ }
172
+ var _payment = null;
173
+ function getPayment(options) {
174
+ if (options) return createPaymentClient(options);
175
+ if (!_payment) _payment = createPaymentClient();
176
+ return _payment;
177
+ }
178
+ export {
179
+ createDb,
180
+ createPaymentClient,
181
+ filterProvidersByPlatform,
182
+ getAvailableProviders,
183
+ getConfiguredProviders,
184
+ getDb,
185
+ getPayment,
186
+ getRequestUser,
187
+ providerSupportedPlatforms
188
+ };
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@nvwa-app/sdk-functions",
3
+ "version": "6.0.31",
4
+ "description": "NVWA Edge Functions SDK: db, payment gateway, auth, provider list. Use in Deno: import from 'npm:@nvwa-app/sdk-functions'.",
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
+ "dependencies": {
27
+ "drizzle-orm": "^0.44.7",
28
+ "postgres": "^3.4.8"
29
+ },
30
+ "devDependencies": {
31
+ "@types/node": "^22.0.0",
32
+ "tsup": "^8.1.0",
33
+ "typescript": "^5.6.0"
34
+ },
35
+ "tsup": {
36
+ "entry": [
37
+ "src/index.ts"
38
+ ],
39
+ "outDir": "dist",
40
+ "clean": true,
41
+ "dts": true,
42
+ "format": [
43
+ "esm",
44
+ "cjs"
45
+ ],
46
+ "minify": false,
47
+ "splitting": false,
48
+ "external": [
49
+ "drizzle-orm",
50
+ "drizzle-orm/postgres-js",
51
+ "postgres"
52
+ ]
53
+ },
54
+ "keywords": [
55
+ "nvwa",
56
+ "edge-functions",
57
+ "deno",
58
+ "payment",
59
+ "drizzle"
60
+ ],
61
+ "license": "ISC"
62
+ }