@onivoro/server-aws-credential-providers 24.33.16 → 24.33.17
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 +70 -1
- package/package.json +1 -1
- package/src/index.d.ts +1 -0
- package/src/index.js +1 -0
- package/src/index.js.map +1 -1
- package/src/lib/aws-client-provider.function.d.ts +9 -0
- package/src/lib/aws-client-provider.function.js +16 -0
- package/src/lib/aws-client-provider.function.js.map +1 -0
package/README.md
CHANGED
|
@@ -132,9 +132,78 @@ aws_access_key_id = AKIAIOSFODNN7EXAMPLE2
|
|
|
132
132
|
aws_secret_access_key = wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY2
|
|
133
133
|
```
|
|
134
134
|
|
|
135
|
+
## AWS Client Provider Helper
|
|
136
|
+
|
|
137
|
+
The `awsClientProvider` function eliminates boilerplate when registering AWS SDK v3 clients as NestJS providers. It creates a provider that injects `AwsCredentials` and instantiates the client with the correct region and credentials.
|
|
138
|
+
|
|
139
|
+
```typescript
|
|
140
|
+
import { awsClientProvider } from '@onivoro/server-aws-credential-providers';
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### Basic usage
|
|
144
|
+
|
|
145
|
+
```typescript
|
|
146
|
+
import { Module } from '@nestjs/common';
|
|
147
|
+
import { S3Client } from '@aws-sdk/client-s3';
|
|
148
|
+
import { awsClientProvider, ServerAwsCredentialProvidersModule } from '@onivoro/server-aws-credential-providers';
|
|
149
|
+
|
|
150
|
+
@Module({})
|
|
151
|
+
export class ServerAwsS3Module {
|
|
152
|
+
static configure(config: ServerAwsS3Config) {
|
|
153
|
+
return {
|
|
154
|
+
module: ServerAwsS3Module,
|
|
155
|
+
imports: [ServerAwsCredentialProvidersModule.configure(config)],
|
|
156
|
+
providers: [
|
|
157
|
+
awsClientProvider(S3Client, config),
|
|
158
|
+
S3Service,
|
|
159
|
+
],
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Multiple clients in one module
|
|
166
|
+
|
|
167
|
+
```typescript
|
|
168
|
+
import { CloudWatchClient } from '@aws-sdk/client-cloudwatch';
|
|
169
|
+
import { CloudWatchLogsClient } from '@aws-sdk/client-cloudwatch-logs';
|
|
170
|
+
|
|
171
|
+
// ...
|
|
172
|
+
providers: [
|
|
173
|
+
awsClientProvider(CloudWatchClient, config),
|
|
174
|
+
awsClientProvider(CloudWatchLogsClient, config),
|
|
175
|
+
],
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
### Passing extra client options
|
|
179
|
+
|
|
180
|
+
Use the optional third argument to pass additional properties to the client constructor:
|
|
181
|
+
|
|
182
|
+
```typescript
|
|
183
|
+
import { CognitoIdentityProviderClient } from '@aws-sdk/client-cognito-identity-provider';
|
|
184
|
+
|
|
185
|
+
// ...
|
|
186
|
+
providers: [
|
|
187
|
+
awsClientProvider(CognitoIdentityProviderClient, config, {
|
|
188
|
+
apiVersion: config.COGNITO_API_VERSION,
|
|
189
|
+
}),
|
|
190
|
+
],
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Config requirements
|
|
194
|
+
|
|
195
|
+
The `config` object must have an `AWS_REGION` property (and `AWS_PROFILE` if using profile-based credentials):
|
|
196
|
+
|
|
197
|
+
```typescript
|
|
198
|
+
export class ServerAwsS3Config {
|
|
199
|
+
AWS_REGION: string;
|
|
200
|
+
AWS_PROFILE?: string;
|
|
201
|
+
}
|
|
202
|
+
```
|
|
203
|
+
|
|
135
204
|
## Integration with AWS SDK
|
|
136
205
|
|
|
137
|
-
Use the resolved credentials with AWS SDK v3:
|
|
206
|
+
Use the resolved credentials directly with AWS SDK v3:
|
|
138
207
|
|
|
139
208
|
```typescript
|
|
140
209
|
import { S3Client } from '@aws-sdk/client-s3';
|
package/package.json
CHANGED
package/src/index.d.ts
CHANGED
package/src/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
+
tslib_1.__exportStar(require("./lib/aws-client-provider.function"), exports);
|
|
4
5
|
tslib_1.__exportStar(require("./lib/aws-credentials.class"), exports);
|
|
5
6
|
tslib_1.__exportStar(require("./lib/resolve-aws-credential-providers-by-profile.function"), exports);
|
|
6
7
|
tslib_1.__exportStar(require("./lib/server-aws-credential-providers-config.class"), exports);
|
package/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/server/aws-credential-providers/src/index.ts"],"names":[],"mappings":";;;AAAA,sEAA4C;AAC5C,qGAA2E;AAC3E,6FAAmE;AACnE,uFAA6D"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../libs/server/aws-credential-providers/src/index.ts"],"names":[],"mappings":";;;AAAA,6EAAmD;AACnD,sEAA4C;AAC5C,qGAA2E;AAC3E,6FAAmE;AACnE,uFAA6D"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { AwsCredentials } from './aws-credentials.class';
|
|
2
|
+
export declare function awsClientProvider<T>(ClientClass: new (config: any) => T, config: {
|
|
3
|
+
AWS_REGION: string;
|
|
4
|
+
}, extras?: Record<string, any>): {
|
|
5
|
+
provide: new (config: any) => T;
|
|
6
|
+
useFactory: (credentials: AwsCredentials) => T;
|
|
7
|
+
inject: (typeof AwsCredentials)[];
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=aws-client-provider.function.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.awsClientProvider = awsClientProvider;
|
|
4
|
+
const aws_credentials_class_1 = require("./aws-credentials.class");
|
|
5
|
+
function awsClientProvider(ClientClass, config, extras) {
|
|
6
|
+
return {
|
|
7
|
+
provide: ClientClass,
|
|
8
|
+
useFactory: (credentials) => new ClientClass({
|
|
9
|
+
region: config.AWS_REGION,
|
|
10
|
+
credentials: credentials || undefined,
|
|
11
|
+
...extras,
|
|
12
|
+
}),
|
|
13
|
+
inject: [aws_credentials_class_1.AwsCredentials],
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=aws-client-provider.function.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"aws-client-provider.function.js","sourceRoot":"","sources":["../../../../../../libs/server/aws-credential-providers/src/lib/aws-client-provider.function.ts"],"names":[],"mappings":";;AAEA,8CAeC;AAjBD,mEAAyD;AAEzD,SAAgB,iBAAiB,CAC/B,WAAmC,EACnC,MAA8B,EAC9B,MAA4B;IAE5B,OAAO;QACL,OAAO,EAAE,WAAW;QACpB,UAAU,EAAE,CAAC,WAA2B,EAAE,EAAE,CAC1C,IAAI,WAAW,CAAC;YACd,MAAM,EAAE,MAAM,CAAC,UAAU;YACzB,WAAW,EAAE,WAAW,IAAI,SAAS;YACrC,GAAG,MAAM;SACV,CAAC;QACJ,MAAM,EAAE,CAAC,sCAAc,CAAC;KACzB,CAAC;AACJ,CAAC"}
|