@nvwa-app/sdk-functions 6.0.31 → 6.0.33
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 +5 -6
- package/dist/index.d.ts +5 -6
- package/dist/index.js +20 -30
- package/dist/index.mjs +20 -29
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { drizzle } from 'drizzle-orm/postgres-js';
|
|
2
2
|
|
|
3
|
-
declare function
|
|
4
|
-
declare function getDb(urlOverride?: string): ReturnType<typeof drizzle>;
|
|
3
|
+
declare function getDb(): ReturnType<typeof drizzle>;
|
|
5
4
|
|
|
6
5
|
interface AuthUser {
|
|
7
6
|
id: string;
|
|
@@ -23,8 +22,8 @@ declare function getRequestUser(req: Request, baseUrlOverride?: string): Promise
|
|
|
23
22
|
type PaymentPlatform = "web" | "uniapp" | "wechat-miniprogram";
|
|
24
23
|
interface PaymentGatewayClientOptions {
|
|
25
24
|
baseUrl: string;
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
/** Project key (PAYMENT_PROJECT_KEY) for project-side auth; gateway validates via X-Payment-Project-Key */
|
|
26
|
+
projectKey: string;
|
|
28
27
|
}
|
|
29
28
|
interface CreateOrderParams {
|
|
30
29
|
bizOrderId: string;
|
|
@@ -69,7 +68,7 @@ interface GetAvailableProvidersOptions {
|
|
|
69
68
|
configured?: string[];
|
|
70
69
|
}
|
|
71
70
|
declare function getAvailableProviders(options?: GetAvailableProvidersOptions): string[];
|
|
72
|
-
/** 单例:Functions 内 getPayment() 使用 env PAYMENT_GATEWAY_URL、
|
|
71
|
+
/** 单例:Functions 内 getPayment() 使用 env PAYMENT_GATEWAY_URL、PAYMENT_PROJECT_KEY。 */
|
|
73
72
|
declare function getPayment(options?: PaymentGatewayClientOptions): PaymentGatewayClient;
|
|
74
73
|
|
|
75
|
-
export { type AuthUser, type CreateOrderParams, type CreateOrderResult, type GetAvailableProvidersOptions, type GetOrderResult, type PaymentGatewayClient, type PaymentGatewayClientOptions, type PaymentPlatform,
|
|
74
|
+
export { type AuthUser, type CreateOrderParams, type CreateOrderResult, type GetAvailableProvidersOptions, type GetOrderResult, type PaymentGatewayClient, type PaymentGatewayClientOptions, type PaymentPlatform, createPaymentClient, filterProvidersByPlatform, getAvailableProviders, getConfiguredProviders, getDb, getPayment, getRequestUser, providerSupportedPlatforms };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { drizzle } from 'drizzle-orm/postgres-js';
|
|
2
2
|
|
|
3
|
-
declare function
|
|
4
|
-
declare function getDb(urlOverride?: string): ReturnType<typeof drizzle>;
|
|
3
|
+
declare function getDb(): ReturnType<typeof drizzle>;
|
|
5
4
|
|
|
6
5
|
interface AuthUser {
|
|
7
6
|
id: string;
|
|
@@ -23,8 +22,8 @@ declare function getRequestUser(req: Request, baseUrlOverride?: string): Promise
|
|
|
23
22
|
type PaymentPlatform = "web" | "uniapp" | "wechat-miniprogram";
|
|
24
23
|
interface PaymentGatewayClientOptions {
|
|
25
24
|
baseUrl: string;
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
/** Project key (PAYMENT_PROJECT_KEY) for project-side auth; gateway validates via X-Payment-Project-Key */
|
|
26
|
+
projectKey: string;
|
|
28
27
|
}
|
|
29
28
|
interface CreateOrderParams {
|
|
30
29
|
bizOrderId: string;
|
|
@@ -69,7 +68,7 @@ interface GetAvailableProvidersOptions {
|
|
|
69
68
|
configured?: string[];
|
|
70
69
|
}
|
|
71
70
|
declare function getAvailableProviders(options?: GetAvailableProvidersOptions): string[];
|
|
72
|
-
/** 单例:Functions 内 getPayment() 使用 env PAYMENT_GATEWAY_URL、
|
|
71
|
+
/** 单例:Functions 内 getPayment() 使用 env PAYMENT_GATEWAY_URL、PAYMENT_PROJECT_KEY。 */
|
|
73
72
|
declare function getPayment(options?: PaymentGatewayClientOptions): PaymentGatewayClient;
|
|
74
73
|
|
|
75
|
-
export { type AuthUser, type CreateOrderParams, type CreateOrderResult, type GetAvailableProvidersOptions, type GetOrderResult, type PaymentGatewayClient, type PaymentGatewayClientOptions, type PaymentPlatform,
|
|
74
|
+
export { type AuthUser, type CreateOrderParams, type CreateOrderResult, type GetAvailableProvidersOptions, type GetOrderResult, type PaymentGatewayClient, type PaymentGatewayClientOptions, type PaymentPlatform, createPaymentClient, filterProvidersByPlatform, getAvailableProviders, getConfiguredProviders, getDb, getPayment, getRequestUser, providerSupportedPlatforms };
|
package/dist/index.js
CHANGED
|
@@ -30,7 +30,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
createDb: () => createDb,
|
|
34
33
|
createPaymentClient: () => createPaymentClient,
|
|
35
34
|
filterProvidersByPlatform: () => filterProvidersByPlatform,
|
|
36
35
|
getAvailableProviders: () => getAvailableProviders,
|
|
@@ -56,15 +55,13 @@ function getEnv(key) {
|
|
|
56
55
|
|
|
57
56
|
// src/db.ts
|
|
58
57
|
function getDatabaseUrl() {
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
const
|
|
62
|
-
const
|
|
63
|
-
const endpoint = getEnv("DB_ENDPOINT");
|
|
64
|
-
const database = getEnv("DB_DATABASE");
|
|
58
|
+
const user = getEnv("PG_DB_USER");
|
|
59
|
+
const password = getEnv("PG_DB_PASSWORD");
|
|
60
|
+
const endpoint = getEnv("PG_DB_ENDPOINT");
|
|
61
|
+
const database = getEnv("PG_DB_DATABASE");
|
|
65
62
|
if (!user || !password || !endpoint || !database) {
|
|
66
63
|
throw new Error(
|
|
67
|
-
"Database config missing: set
|
|
64
|
+
"Database config missing: set PG_DB_USER, PG_DB_PASSWORD, PG_DB_ENDPOINT, PG_DB_DATABASE"
|
|
68
65
|
);
|
|
69
66
|
}
|
|
70
67
|
const safeUser = encodeURIComponent(user);
|
|
@@ -72,13 +69,8 @@ function getDatabaseUrl() {
|
|
|
72
69
|
return `postgresql://${safeUser}:${safePassword}@${endpoint}/${database}`;
|
|
73
70
|
}
|
|
74
71
|
var _db = null;
|
|
75
|
-
function
|
|
76
|
-
|
|
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());
|
|
72
|
+
function getDb() {
|
|
73
|
+
if (!_db) _db = (0, import_postgres_js.drizzle)((0, import_postgres.default)(getDatabaseUrl(), { max: 1 }));
|
|
82
74
|
return _db;
|
|
83
75
|
}
|
|
84
76
|
|
|
@@ -114,23 +106,22 @@ function resolveBaseUrl(explicit) {
|
|
|
114
106
|
if (!url) throw new Error("PAYMENT_GATEWAY_URL is not set; payment gateway client requires it");
|
|
115
107
|
return url.replace(/\/$/, "");
|
|
116
108
|
}
|
|
117
|
-
function
|
|
118
|
-
const
|
|
119
|
-
if (!
|
|
120
|
-
return
|
|
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");
|
|
109
|
+
function resolveProjectKey(explicit) {
|
|
110
|
+
const key = explicit ?? getEnv("PAYMENT_PROJECT_KEY");
|
|
111
|
+
if (!key) throw new Error("PAYMENT_PROJECT_KEY is not set; payment gateway client requires it");
|
|
112
|
+
return key;
|
|
125
113
|
}
|
|
114
|
+
var AUTH_HEADER = "X-Payment-Project-Key";
|
|
126
115
|
function createPaymentClient(options) {
|
|
127
116
|
const baseUrl = resolveBaseUrl(options?.baseUrl);
|
|
128
|
-
const
|
|
129
|
-
const
|
|
117
|
+
const projectKey = resolveProjectKey(options?.projectKey);
|
|
118
|
+
const authHeaders = {
|
|
119
|
+
[AUTH_HEADER]: projectKey
|
|
120
|
+
};
|
|
130
121
|
async function post(path, body) {
|
|
131
|
-
const res = await
|
|
122
|
+
const res = await fetch(`${baseUrl}${path}`, {
|
|
132
123
|
method: "POST",
|
|
133
|
-
headers: { "Content-Type": "application/json",
|
|
124
|
+
headers: { "Content-Type": "application/json", ...authHeaders },
|
|
134
125
|
body: JSON.stringify(body ?? {})
|
|
135
126
|
});
|
|
136
127
|
const text = await res.text();
|
|
@@ -146,9 +137,9 @@ function createPaymentClient(options) {
|
|
|
146
137
|
return data.data;
|
|
147
138
|
}
|
|
148
139
|
async function get(path) {
|
|
149
|
-
const res = await
|
|
140
|
+
const res = await fetch(`${baseUrl}${path}`, {
|
|
150
141
|
method: "GET",
|
|
151
|
-
headers:
|
|
142
|
+
headers: authHeaders
|
|
152
143
|
});
|
|
153
144
|
const text = await res.text();
|
|
154
145
|
let json;
|
|
@@ -221,7 +212,6 @@ function getPayment(options) {
|
|
|
221
212
|
}
|
|
222
213
|
// Annotate the CommonJS export names for ESM import in node:
|
|
223
214
|
0 && (module.exports = {
|
|
224
|
-
createDb,
|
|
225
215
|
createPaymentClient,
|
|
226
216
|
filterProvidersByPlatform,
|
|
227
217
|
getAvailableProviders,
|
package/dist/index.mjs
CHANGED
|
@@ -12,15 +12,13 @@ function getEnv(key) {
|
|
|
12
12
|
|
|
13
13
|
// src/db.ts
|
|
14
14
|
function getDatabaseUrl() {
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const endpoint = getEnv("DB_ENDPOINT");
|
|
20
|
-
const database = getEnv("DB_DATABASE");
|
|
15
|
+
const user = getEnv("PG_DB_USER");
|
|
16
|
+
const password = getEnv("PG_DB_PASSWORD");
|
|
17
|
+
const endpoint = getEnv("PG_DB_ENDPOINT");
|
|
18
|
+
const database = getEnv("PG_DB_DATABASE");
|
|
21
19
|
if (!user || !password || !endpoint || !database) {
|
|
22
20
|
throw new Error(
|
|
23
|
-
"Database config missing: set
|
|
21
|
+
"Database config missing: set PG_DB_USER, PG_DB_PASSWORD, PG_DB_ENDPOINT, PG_DB_DATABASE"
|
|
24
22
|
);
|
|
25
23
|
}
|
|
26
24
|
const safeUser = encodeURIComponent(user);
|
|
@@ -28,13 +26,8 @@ function getDatabaseUrl() {
|
|
|
28
26
|
return `postgresql://${safeUser}:${safePassword}@${endpoint}/${database}`;
|
|
29
27
|
}
|
|
30
28
|
var _db = null;
|
|
31
|
-
function
|
|
32
|
-
|
|
33
|
-
return drizzle(client);
|
|
34
|
-
}
|
|
35
|
-
function getDb(urlOverride) {
|
|
36
|
-
if (urlOverride) return createDb(urlOverride);
|
|
37
|
-
if (!_db) _db = createDb(getDatabaseUrl());
|
|
29
|
+
function getDb() {
|
|
30
|
+
if (!_db) _db = drizzle(postgres(getDatabaseUrl(), { max: 1 }));
|
|
38
31
|
return _db;
|
|
39
32
|
}
|
|
40
33
|
|
|
@@ -70,23 +63,22 @@ function resolveBaseUrl(explicit) {
|
|
|
70
63
|
if (!url) throw new Error("PAYMENT_GATEWAY_URL is not set; payment gateway client requires it");
|
|
71
64
|
return url.replace(/\/$/, "");
|
|
72
65
|
}
|
|
73
|
-
function
|
|
74
|
-
const
|
|
75
|
-
if (!
|
|
76
|
-
return
|
|
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");
|
|
66
|
+
function resolveProjectKey(explicit) {
|
|
67
|
+
const key = explicit ?? getEnv("PAYMENT_PROJECT_KEY");
|
|
68
|
+
if (!key) throw new Error("PAYMENT_PROJECT_KEY is not set; payment gateway client requires it");
|
|
69
|
+
return key;
|
|
81
70
|
}
|
|
71
|
+
var AUTH_HEADER = "X-Payment-Project-Key";
|
|
82
72
|
function createPaymentClient(options) {
|
|
83
73
|
const baseUrl = resolveBaseUrl(options?.baseUrl);
|
|
84
|
-
const
|
|
85
|
-
const
|
|
74
|
+
const projectKey = resolveProjectKey(options?.projectKey);
|
|
75
|
+
const authHeaders = {
|
|
76
|
+
[AUTH_HEADER]: projectKey
|
|
77
|
+
};
|
|
86
78
|
async function post(path, body) {
|
|
87
|
-
const res = await
|
|
79
|
+
const res = await fetch(`${baseUrl}${path}`, {
|
|
88
80
|
method: "POST",
|
|
89
|
-
headers: { "Content-Type": "application/json",
|
|
81
|
+
headers: { "Content-Type": "application/json", ...authHeaders },
|
|
90
82
|
body: JSON.stringify(body ?? {})
|
|
91
83
|
});
|
|
92
84
|
const text = await res.text();
|
|
@@ -102,9 +94,9 @@ function createPaymentClient(options) {
|
|
|
102
94
|
return data.data;
|
|
103
95
|
}
|
|
104
96
|
async function get(path) {
|
|
105
|
-
const res = await
|
|
97
|
+
const res = await fetch(`${baseUrl}${path}`, {
|
|
106
98
|
method: "GET",
|
|
107
|
-
headers:
|
|
99
|
+
headers: authHeaders
|
|
108
100
|
});
|
|
109
101
|
const text = await res.text();
|
|
110
102
|
let json;
|
|
@@ -176,7 +168,6 @@ function getPayment(options) {
|
|
|
176
168
|
return _payment;
|
|
177
169
|
}
|
|
178
170
|
export {
|
|
179
|
-
createDb,
|
|
180
171
|
createPaymentClient,
|
|
181
172
|
filterProvidersByPlatform,
|
|
182
173
|
getAvailableProviders,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nvwa-app/sdk-functions",
|
|
3
|
-
"version": "6.0.
|
|
3
|
+
"version": "6.0.33",
|
|
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",
|