xpine 0.0.11 → 0.0.13

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 CHANGED
@@ -30,7 +30,14 @@ export default {}
30
30
 
31
31
  ## Env
32
32
 
33
- `import { setupEnv } from 'xpine';`
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
- function setupEnv() {
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
- function setupEnv() {
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()}`);
@@ -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,wBAAgB,QAAQ,SAEvB"}
1
+ {"version":3,"file":"env.d.ts","sourceRoot":"","sources":["../../../src/util/env.ts"],"names":[],"mappings":"AAKA,wBAAsB,QAAQ,kBAK7B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xpine",
3
- "version": "0.0.11",
3
+ "version": "0.0.13",
4
4
  "main": "dist/index.js",
5
5
  "dependencies": {
6
6
  "@aws-sdk/client-secrets-manager": "^3.758.0",
package/tsconfig.json CHANGED
@@ -30,8 +30,7 @@
30
30
  "types": []
31
31
  },
32
32
  "include": [
33
- "src/**/*.ts",
34
- "index.ts"
33
+ "src/**/*.ts"
35
34
  ],
36
35
  "exclude": [
37
36
  "node_modules",
package/index.ts DELETED
@@ -1,7 +0,0 @@
1
- export * from './src/runDevServer';
2
- export * from './src/express';
3
- export * from './src/util/env';
4
- export * from './src/util/get-config';
5
- export * from './src/scripts/build';
6
- export * from './src/auth';
7
- export * from './src/util/html';