@opengis/pay 1.3.1 → 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 +3 -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,6 +13,7 @@
|
|
|
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",
|
|
@@ -33,4 +34,4 @@
|
|
|
33
34
|
},
|
|
34
35
|
"author": "Softpro",
|
|
35
36
|
"license": "ISC"
|
|
36
|
-
}
|
|
37
|
+
}
|