@onivoro/server-aws-sts 24.13.0 → 24.14.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/jest.config.ts ADDED
@@ -0,0 +1,11 @@
1
+ /* eslint-disable */
2
+ export default {
3
+ displayName: 'lib-server-aws-sts',
4
+ preset: '../../../jest.preset.js',
5
+ testEnvironment: 'node',
6
+ transform: {
7
+ '^.+\\.[tj]s$': ['ts-jest', { tsconfig: '<rootDir>/tsconfig.spec.json' }],
8
+ },
9
+ moduleFileExtensions: ['ts', 'js', 'html'],
10
+ coverageDirectory: '../../../coverage/libs/server/aws-sts',
11
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onivoro/server-aws-sts",
3
- "version": "24.13.0",
3
+ "version": "24.14.0",
4
4
  "type": "commonjs",
5
5
  "main": "./index.js",
6
6
  "types": "./index.d.ts",
@@ -9,18 +9,12 @@
9
9
  "url": "https://github.com/onivoro/monorepo.git"
10
10
  },
11
11
  "dependencies": {
12
- "@onivoro/server-aws-credential-providers": "24.13.0",
13
- "@onivoro/server-common": "24.13.0",
12
+ "@onivoro/server-aws-credential-providers": "24.14.0",
13
+ "@onivoro/server-common": "24.14.0",
14
14
  "tslib": "^2.3.0"
15
15
  },
16
16
  "peerDependencies": {
17
17
  "@aws-sdk/client-sts": "~3.782.0",
18
18
  "@nestjs/common": "~10.4.6"
19
- },
20
- "files": [
21
- "**/*.js",
22
- "**/*.d.ts",
23
- "**/*.js.map",
24
- "README.md"
25
- ]
19
+ }
26
20
  }
package/project.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "lib-server-aws-sts",
3
+ "$schema": "../../../node_modules/nx/schemas/project-schema.json",
4
+ "sourceRoot": "libs/server/aws-sts/src",
5
+ "projectType": "library",
6
+ "targets": {
7
+ "build": {
8
+ "executor": "@nx/js:tsc",
9
+ "outputs": ["{options.outputPath}"],
10
+ "options": {
11
+ "outputPath": "dist/libs/server/aws-sts",
12
+ "main": "libs/server/aws-sts/src/index.ts",
13
+ "tsConfig": "libs/server/aws-sts/tsconfig.lib.json",
14
+ "assets": [
15
+ "libs/server/aws-sts/README.md",
16
+ "libs/server/aws-sts/package.json"
17
+ ],
18
+ "declaration": true,
19
+ "updateBuildableProjectPackageJsonDependencies": true,
20
+ "rootDir": "libs/server/aws-sts/src"
21
+ }
22
+ },
23
+ "publish": {
24
+ "executor": "@nx/js:npm",
25
+ "outputs": [],
26
+ "dependsOn": ["build"],
27
+ "options": {
28
+ "packageRoot": "dist/libs/server/aws-sts"
29
+ }
30
+ }
31
+ },
32
+ "tags": []
33
+ }
package/src/index.ts ADDED
@@ -0,0 +1,5 @@
1
+ export * from './lib/classes/server-aws-sts-config.class';
2
+
3
+ export * from './lib/services/sts.service';
4
+
5
+ export * from './lib/server-aws-sts.module';
@@ -0,0 +1,4 @@
1
+ export class ServerAwsStsConfig {
2
+ AWS_PROFILE?: string;
3
+ AWS_REGION: string;
4
+ }
@@ -0,0 +1,33 @@
1
+ import { Module } from '@nestjs/common';
2
+ import { moduleFactory } from '@onivoro/server-common';
3
+ import { STSClient } from '@aws-sdk/client-sts';
4
+ import { StsService } from './services/sts.service';
5
+ import { ServerAwsStsConfig } from './classes/server-aws-sts-config.class';
6
+ import { AwsCredentials, ServerAwsCredentialProvidersModule } from '@onivoro/server-aws-credential-providers';
7
+
8
+ let stsClient: STSClient | null = null;
9
+
10
+ @Module({})
11
+ export class ServerAwsStsModule {
12
+ static configure(config: ServerAwsStsConfig) {
13
+ return moduleFactory({
14
+ module: ServerAwsStsModule,
15
+ imports: [ServerAwsCredentialProvidersModule.configure(config)],
16
+ providers: [
17
+ {
18
+ provide: STSClient,
19
+ useFactory: (credentials: AwsCredentials) => stsClient
20
+ ? stsClient
21
+ : stsClient = new STSClient({
22
+ region: config.AWS_REGION,
23
+ logger: console,
24
+ credentials
25
+ }),
26
+ inject: [AwsCredentials]
27
+ },
28
+ { provide: ServerAwsStsConfig, useValue: config },
29
+ StsService
30
+ ]
31
+ })
32
+ }
33
+ }
@@ -0,0 +1,13 @@
1
+ import { Injectable } from '@nestjs/common';
2
+ import { GetCallerIdentityCommand, STSClient } from '@aws-sdk/client-sts';
3
+ import { ServerAwsStsConfig } from '../classes/server-aws-sts-config.class';
4
+
5
+ @Injectable()
6
+ export class StsService {
7
+ constructor(public readonly stsClient: STSClient, private config: ServerAwsStsConfig) { }
8
+
9
+ async getAccountId() {
10
+ const response = await this.stsClient.send(new GetCallerIdentityCommand({}));
11
+ return response.Account;
12
+ }
13
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,16 @@
1
+ {
2
+ "extends": "../../../tsconfig.server.json",
3
+ "compilerOptions": {
4
+ "outDir": "../../../dist/out-tsc"
5
+ },
6
+ "files": [],
7
+ "include": [],
8
+ "references": [
9
+ {
10
+ "path": "./tsconfig.lib.json"
11
+ },
12
+ {
13
+ "path": "./tsconfig.spec.json"
14
+ }
15
+ ]
16
+ }
@@ -0,0 +1,10 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "./src",
5
+ "outDir": "../../dist/libs/server/aws-sts",
6
+ "declaration": true
7
+ },
8
+ "exclude": ["jest.config.ts", "**/*.spec.ts", "**/*.test.ts"],
9
+ "include": ["src/**/*.ts"]
10
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "types": [
5
+ "jest",
6
+ "node"
7
+ ]
8
+ },
9
+ "include": [
10
+ "jest.config.ts",
11
+ "**/*.test.ts",
12
+ "**/*.spec.ts",
13
+ "**/*.test.tsx",
14
+ "**/*.spec.tsx",
15
+ "**/*.test.js",
16
+ "**/*.spec.js",
17
+ "**/*.test.jsx",
18
+ "**/*.spec.jsx",
19
+ "**/*.d.ts"
20
+ ]
21
+ }