xpine 0.0.12 → 0.0.14
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/README.md +8 -1
- package/dist/index.js +25 -2
- package/dist/src/scripts/xpine-dev.js +25 -2
- package/dist/src/util/env.d.ts +1 -1
- package/dist/src/util/env.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -30,7 +30,14 @@ export default {}
|
|
|
30
30
|
|
|
31
31
|
## Env
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
```
|
|
34
|
+
import { setupEnv } from 'xpine';
|
|
35
|
+
|
|
36
|
+
await setupEnv();
|
|
37
|
+
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
setupEnv also supports AWS secrets manager. Simply add SECRETS_NAME=your_aws_secret_name to your .env.{stage} file
|
|
34
41
|
|
|
35
42
|
## Router
|
|
36
43
|
|
package/dist/index.js
CHANGED
|
@@ -427,12 +427,35 @@ import path5 from "path";
|
|
|
427
427
|
// src/util/env.ts
|
|
428
428
|
import dotenv from "dotenv";
|
|
429
429
|
import path4 from "path";
|
|
430
|
-
|
|
430
|
+
import { GetSecretValueCommand, SecretsManagerClient } from "@aws-sdk/client-secrets-manager";
|
|
431
|
+
async function setupEnv() {
|
|
432
|
+
if (process.env.HAS_SETUP_ENV) return;
|
|
431
433
|
dotenv.config({ path: path4.join(config.rootDir, `./.env.${process.env.STAGE || "dev"}`) });
|
|
434
|
+
await loadSecretsManagerSecrets();
|
|
435
|
+
process.env.HAS_SETUP_ENV = "true";
|
|
436
|
+
}
|
|
437
|
+
async function loadSecretsManagerSecrets() {
|
|
438
|
+
if (!process.env.SECRET_NAME) return;
|
|
439
|
+
try {
|
|
440
|
+
const client = new SecretsManagerClient();
|
|
441
|
+
const command = new GetSecretValueCommand({
|
|
442
|
+
SecretId: process.env.SECRET_NAME
|
|
443
|
+
});
|
|
444
|
+
const response = await client.send(command);
|
|
445
|
+
if (!response?.SecretString) throw Error;
|
|
446
|
+
const secretValue = JSON.parse(response.SecretString);
|
|
447
|
+
if (!secretValue || typeof secretValue !== "object") throw Error;
|
|
448
|
+
Object.keys(secretValue).forEach((key) => {
|
|
449
|
+
process.env[key] = secretValue[key];
|
|
450
|
+
});
|
|
451
|
+
} catch (err) {
|
|
452
|
+
console.error(`Could not load secret: ${process.env.SECRET_NAME}`);
|
|
453
|
+
return null;
|
|
454
|
+
}
|
|
432
455
|
}
|
|
433
456
|
|
|
434
457
|
// src/runDevServer.ts
|
|
435
|
-
setupEnv();
|
|
458
|
+
await setupEnv();
|
|
436
459
|
async function runDevServer() {
|
|
437
460
|
process.env.NODE_ENV = "development";
|
|
438
461
|
const startServer = await import(config.serverDistAppPath + `?cache=${Date.now()}`);
|
|
@@ -429,12 +429,35 @@ import path5 from "path";
|
|
|
429
429
|
// src/util/env.ts
|
|
430
430
|
import dotenv from "dotenv";
|
|
431
431
|
import path4 from "path";
|
|
432
|
-
|
|
432
|
+
import { GetSecretValueCommand, SecretsManagerClient } from "@aws-sdk/client-secrets-manager";
|
|
433
|
+
async function setupEnv() {
|
|
434
|
+
if (process.env.HAS_SETUP_ENV) return;
|
|
433
435
|
dotenv.config({ path: path4.join(config.rootDir, `./.env.${process.env.STAGE || "dev"}`) });
|
|
436
|
+
await loadSecretsManagerSecrets();
|
|
437
|
+
process.env.HAS_SETUP_ENV = "true";
|
|
438
|
+
}
|
|
439
|
+
async function loadSecretsManagerSecrets() {
|
|
440
|
+
if (!process.env.SECRET_NAME) return;
|
|
441
|
+
try {
|
|
442
|
+
const client = new SecretsManagerClient();
|
|
443
|
+
const command = new GetSecretValueCommand({
|
|
444
|
+
SecretId: process.env.SECRET_NAME
|
|
445
|
+
});
|
|
446
|
+
const response = await client.send(command);
|
|
447
|
+
if (!response?.SecretString) throw Error;
|
|
448
|
+
const secretValue = JSON.parse(response.SecretString);
|
|
449
|
+
if (!secretValue || typeof secretValue !== "object") throw Error;
|
|
450
|
+
Object.keys(secretValue).forEach((key) => {
|
|
451
|
+
process.env[key] = secretValue[key];
|
|
452
|
+
});
|
|
453
|
+
} catch (err) {
|
|
454
|
+
console.error(`Could not load secret: ${process.env.SECRET_NAME}`);
|
|
455
|
+
return null;
|
|
456
|
+
}
|
|
434
457
|
}
|
|
435
458
|
|
|
436
459
|
// src/runDevServer.ts
|
|
437
|
-
setupEnv();
|
|
460
|
+
await setupEnv();
|
|
438
461
|
async function runDevServer() {
|
|
439
462
|
process.env.NODE_ENV = "development";
|
|
440
463
|
const startServer = await import(config.serverDistAppPath + `?cache=${Date.now()}`);
|
package/dist/src/util/env.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function setupEnv(): void
|
|
1
|
+
export declare function setupEnv(): Promise<void>;
|
|
2
2
|
//# sourceMappingURL=env.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../../src/util/env.ts"],"names":[],"mappings":"AAKA,
|
|
1
|
+
{"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../../src/util/env.ts"],"names":[],"mappings":"AAKA,wBAAsB,QAAQ,kBAK7B"}
|