@notifiles/sdk 1.2.0 → 1.3.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@notifiles/sdk",
3
3
  "type": "module",
4
- "version": "1.2.0",
4
+ "version": "1.3.0",
5
5
  "description": "",
6
6
  "author": {
7
7
  "name": "adoucoure",
@@ -1,6 +1,28 @@
1
1
  import fs from "fs"
2
2
  import checkFileExists from "./checkFileExists.js"
3
3
 
4
+ const expandEnvPlaceholders = (value) => {
5
+ if (typeof value === 'string') {
6
+ return value.replace(/\$\{process\.env\.([A-Z0-9_]+)\}/g, (match, envKey) => {
7
+ const envValue = process.env[envKey]
8
+ return envValue !== undefined ? envValue : match
9
+ })
10
+ }
11
+
12
+ if (Array.isArray(value)) {
13
+ return value.map(expandEnvPlaceholders)
14
+ }
15
+
16
+ if (value && typeof value === 'object') {
17
+ return Object.entries(value).reduce((acc, [key, val]) => {
18
+ acc[key] = expandEnvPlaceholders(val)
19
+ return acc
20
+ }, {})
21
+ }
22
+
23
+ return value
24
+ }
25
+
4
26
  export default async _url => {
5
27
  // try {
6
28
  if (!(await checkFileExists(_url))) {
@@ -8,7 +30,7 @@ export default async _url => {
8
30
  }
9
31
  const fileUrl = new URL(_url, import.meta.url)
10
32
  const parsedPackageJSON = JSON.parse(await fs.promises.readFile(fileUrl, 'utf8'))
11
- return parsedPackageJSON
33
+ return expandEnvPlaceholders(parsedPackageJSON)
12
34
  // } catch (e) {
13
35
  // console.log("[notifiles]", `importJSONAsync → `, e)
14
36
  // return null