@opengis/pay 1.3.0 → 1.3.2
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/config.js +71 -4
- package/package.json +5 -4
- package/plugin.js +1 -1
- package/server/plugins/pg/funcs/getPG.js +1 -1
- package/server/plugins/pg/funcs/getPGAsync.js +1 -1
- package/server/routes/liqpay/controllers/liqpay.status.js +2 -2
- package/server/routes/portmone/controllers/portmone.status.js +2 -2
package/config.js
CHANGED
|
@@ -1,7 +1,74 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
import dotenv from 'dotenv';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
dotenv.config(); // load .env for node, not required for bun
|
|
5
|
+
|
|
6
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
7
|
+
|
|
8
|
+
function unflattenObject(flatObj) {
|
|
9
|
+
const res = Object.keys(flatObj || {}).reduce((acc, key) => {
|
|
10
|
+
const keys = key.split('.');
|
|
11
|
+
keys.reduce((nestedObj, part, index) => {
|
|
12
|
+
if (index === keys.length - 1) {
|
|
13
|
+
// json array
|
|
14
|
+
if (typeof flatObj[key] === 'string' && flatObj[key].startsWith('[') && flatObj[key] !== ('[object Object]')) {
|
|
15
|
+
try {
|
|
16
|
+
nestedObj[part] = JSON.parse(flatObj[key] || '{}');
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
console.warn(`Error parsing JSON for key ${key}:`, err.toString());
|
|
20
|
+
nestedObj[part] = flatObj[key]; // fallback to original value if parsing fails
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
else if (['true', 'false'].includes(flatObj[key]) || (!isNaN(flatObj[key]) && key !== 'auth.uid')) {
|
|
24
|
+
try {
|
|
25
|
+
nestedObj[part] = JSON.parse(flatObj[key] || '{}');
|
|
26
|
+
}
|
|
27
|
+
catch (err) {
|
|
28
|
+
console.warn(`Error parsing JSON for key ${key}:`, err.toString());
|
|
29
|
+
nestedObj[part] = flatObj[key]; // fallback to original value if parsing fails
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
nestedObj[part] = flatObj[key];
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
nestedObj[part] = nestedObj[part] || {};
|
|
38
|
+
}
|
|
39
|
+
return nestedObj[part];
|
|
40
|
+
}, acc);
|
|
41
|
+
return acc;
|
|
42
|
+
}, {});
|
|
43
|
+
console.log('unflattened');
|
|
44
|
+
return res;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const fileName = ['config.json', '/data/local/config.json'].find(el => (existsSync(el) ? el : null));
|
|
48
|
+
const config = fileName ? JSON.parse(readFileSync(fileName)) : {};
|
|
49
|
+
|
|
50
|
+
const { skipKeys = ['windir'] } = config;
|
|
51
|
+
|
|
52
|
+
// npm run dev === cross-env NODE_ENV=development
|
|
53
|
+
// alt: node --env=development
|
|
54
|
+
Object.assign(config, {
|
|
55
|
+
storageList: {},
|
|
56
|
+
allTemplates: config?.allTemplates || {},
|
|
57
|
+
skipCheckPolicyRoutes: [],
|
|
58
|
+
env: process.env?.NODE_ENV,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
if (process.env?.NODE_ENV && existsSync(`.env.${process.env.NODE_ENV}`)) {
|
|
62
|
+
dotenv.config({ path: `.env.${process.env.NODE_ENV}` }); // load .env.{{production}} etc. for node, not required for bun
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function loadEnvConfig() {
|
|
66
|
+
// node --env-file-if-exists=.env.dev --env-file-if-exists=.env server
|
|
67
|
+
if (config.trace) { console.log(Object.keys(process.env)); }
|
|
68
|
+
const configKeys = Object.keys(process.env).filter(key => !key.startsWith('npm_') && !skipKeys.includes(key) && (key.charAt(0) === key.charAt(0)?.toLowerCase?.() || key.includes('.'))).reduce((acc, curr) => ({ ...acc, [curr]: process.env[curr] }), {});
|
|
69
|
+
Object.assign(config, unflattenObject(configKeys));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
loadEnvConfig();
|
|
6
73
|
|
|
7
74
|
export default config;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opengis/pay",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "pay plugins for billing",
|
|
6
6
|
"main": "plugin.js",
|
|
@@ -13,14 +13,13 @@
|
|
|
13
13
|
"utils.js"
|
|
14
14
|
],
|
|
15
15
|
"scripts": {
|
|
16
|
+
"patch": "npm version patch && git push && npm publish",
|
|
16
17
|
"test": "node --test",
|
|
17
18
|
"start": "node --watch-path=server server",
|
|
18
19
|
"admin": "set NODE_ENV=admin&& npm run start",
|
|
19
20
|
"lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore"
|
|
20
21
|
},
|
|
21
22
|
"dependencies": {
|
|
22
|
-
"fastify": "5.3.3",
|
|
23
|
-
"fastify-plugin": "5.0.1",
|
|
24
23
|
"ioredis": "5.3.2",
|
|
25
24
|
"liqpayjs-sdk": "3.3.1",
|
|
26
25
|
"nodemailer": "6.5.0",
|
|
@@ -28,9 +27,11 @@
|
|
|
28
27
|
"request-promise": "4.2.6"
|
|
29
28
|
},
|
|
30
29
|
"devDependencies": {
|
|
30
|
+
"fastify": "5.3.3",
|
|
31
|
+
"fastify-plugin": "5.0.1",
|
|
31
32
|
"eslint": "8.49.0",
|
|
32
33
|
"eslint-config-airbnb": "19.0.4"
|
|
33
34
|
},
|
|
34
35
|
"author": "Softpro",
|
|
35
36
|
"license": "ISC"
|
|
36
|
-
}
|
|
37
|
+
}
|
package/plugin.js
CHANGED
|
@@ -16,7 +16,7 @@ const dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
|
16
16
|
async function plugin(app, config = {}) {
|
|
17
17
|
config.prefix = config.prefix || '/api';
|
|
18
18
|
|
|
19
|
-
const pg = await getPGAsync(config.pg
|
|
19
|
+
const pg = await getPGAsync(config.pg ? { ...config.pg, name: 'client' } : {});
|
|
20
20
|
|
|
21
21
|
app.register(import('./server/plugins/hook.js'), config);
|
|
22
22
|
app.register(import('./server/routes/portmone/index.mjs'), config);
|
|
@@ -10,7 +10,7 @@ import init from './init.js';
|
|
|
10
10
|
import getDBParams from './getDBParams.js';
|
|
11
11
|
|
|
12
12
|
function getPG(param) {
|
|
13
|
-
if (!config.pg) return null;
|
|
13
|
+
if (!config.pg && !param?.database && !pgClients[param.name || 'client']) return null; // env support?
|
|
14
14
|
const {
|
|
15
15
|
user, password, host, port, db, database, name: origin,
|
|
16
16
|
} = (typeof param === 'string' ? getDBParams(param) : param || {});
|
|
@@ -10,7 +10,7 @@ import init from './init.js';
|
|
|
10
10
|
import getDBParams from './getDBParams.js';
|
|
11
11
|
|
|
12
12
|
async function getPGAsync(param) {
|
|
13
|
-
if (!config.pg) return null;
|
|
13
|
+
if (!config.pg && !param?.database && !pgClients[param.name || 'client']) return null;
|
|
14
14
|
|
|
15
15
|
const {
|
|
16
16
|
user, password, host, port, db, database, name: origin,
|
|
@@ -12,7 +12,7 @@ import sendNotification from '../../../utils/sendNotification.js';
|
|
|
12
12
|
import checkStatus from '../utils/check.status.js';
|
|
13
13
|
|
|
14
14
|
const dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
15
|
-
const ptBody = readFileSync(path.join(dirname, '../../../../module/pay/pt/marketplace-service-payment-client-template.html'));
|
|
15
|
+
const ptBody = readFileSync(path.join(dirname, '../../../../module/pay/pt/marketplace-service-payment-client-template.html'), { encoding: 'utf8' });
|
|
16
16
|
|
|
17
17
|
const newDate = () => {
|
|
18
18
|
const date = new Date();
|
|
@@ -176,7 +176,7 @@ export default async function liqpayStatus(req, reply) {
|
|
|
176
176
|
});
|
|
177
177
|
|
|
178
178
|
if (to) {
|
|
179
|
-
const pt = ptBody
|
|
179
|
+
const pt = (ptBody || 'empty template')
|
|
180
180
|
.replace(/{{domain}}/g, req.hostname)
|
|
181
181
|
.replace(/{{total_balance}}/g, +(refillSum || 0) + (+totalBalance || 0))
|
|
182
182
|
.replace(/{{username}}/g, to)
|
|
@@ -10,7 +10,7 @@ import dataUpdate from '../../../plugins/crud/dataUpdate.js';
|
|
|
10
10
|
|
|
11
11
|
import sendNotification from '../../../utils/sendNotification.js';
|
|
12
12
|
|
|
13
|
-
const ptBody = readFileSync(path.join(dirname, '../../../../module/pay/pt/marketplace-service-payment-client-template.html'));
|
|
13
|
+
const ptBody = readFileSync(path.join(dirname, '../../../../module/pay/pt/marketplace-service-payment-client-template.html'), { encoding: 'utf8' });
|
|
14
14
|
|
|
15
15
|
const newDate = () => {
|
|
16
16
|
const date = new Date();
|
|
@@ -146,7 +146,7 @@ export default async function portmoneStatus(req, reply) {
|
|
|
146
146
|
);
|
|
147
147
|
|
|
148
148
|
if (to) {
|
|
149
|
-
const pt = ptBody
|
|
149
|
+
const pt = (ptBody || 'empty template')
|
|
150
150
|
.replace(/{{domain}}/g, req.hostname)
|
|
151
151
|
.replace(/{{total_balance}}/g, +(refillSum || 0) + (+totalBalance || 0))
|
|
152
152
|
.replace(/{{username}}/g, to)
|