Skip to content

Commit 202fda1

Browse files
cleanup src
1 parent 3b8bc36 commit 202fda1

File tree

6 files changed

+19
-17
lines changed

6 files changed

+19
-17
lines changed

src/client-side-encryption/errors.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ export class MongoCryptError extends Error {
2323
* An error indicating that `ClientEncryption.createEncryptedCollection()` failed to create data keys
2424
*/
2525
export class MongoCryptCreateDataKeyError extends MongoCryptError {
26-
// TODO: type encrypted fields
2726
encryptedFields: Document;
28-
constructor({ encryptedFields, cause }) {
27+
constructor({encryptedFields, cause}: { encryptedFields: Document, cause: Error }) {
2928
super(`Unable to complete creating data keys: ${cause.message}`, { cause });
3029
this.encryptedFields = encryptedFields;
3130
}
@@ -40,9 +39,8 @@ export class MongoCryptCreateDataKeyError extends MongoCryptError {
4039
* An error indicating that `ClientEncryption.createEncryptedCollection()` failed to create a collection
4140
*/
4241
export class MongoCryptCreateEncryptedCollectionError extends MongoCryptError {
43-
// TODO: type encrypted fields
4442
encryptedFields: Document;
45-
constructor({ encryptedFields, cause }) {
43+
constructor({encryptedFields, cause}: { encryptedFields: Document, cause: Error }) {
4644
super(`Unable to create collection: ${cause.message}`, { cause });
4745
this.encryptedFields = encryptedFields;
4846
}

src/client-side-encryption/providers/aws.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,5 @@ export async function loadAWSCredentials(kmsProviders: KMSProviders): Promise<KM
1616
// The state machine is the only place calling this so it will
1717
// catch if there is a rejection here.
1818
const aws = await provider();
19-
// TODO - figure out the type mismatch here
2019
return { ...kmsProviders, aws };
2120
}

src/client-side-encryption/providers/azure.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,10 @@ export function prepareRequest(options: AzureKMSRequestOptions): {
117117
const url =
118118
options.url == null
119119
? new URL('http://169.254.169.254/metadata/identity/oauth2/token')
120-
: // TODO - figure out why typings are messed up.
121-
// @ts-expect-error the URL constructor supports a url parameter, but the types say it doesn't
120+
: // The Node URL constructor technically supports "any object that converts to a valid URL string",
121+
// but Node types doesn't support this. See the Node docs for new URL().
122+
// https://nodejs.org/api/url.html#new-urlinput-base
123+
// @ts-ignore
122124
new URL(options.url);
123125

124126
url.searchParams.append('api-version', '2018-02-01');

src/client-side-encryption/providers/gcp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export async function loadGCPCredentials(kmsProviders: KMSProviders): Promise<KM
99
return kmsProviders;
1010
}
1111

12-
const { access_token: accessToken } = await gcpMetadata.instance({
12+
const { access_token: accessToken } = await gcpMetadata.instance<{ access_token: string }>({
1313
property: 'service-accounts/default/token'
1414
});
1515
return { ...kmsProviders, gcp: { accessToken } };

src/cmap/auth/mongodb_aws.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,6 @@ interface AWSTempCredentials {
157157
Expiration?: Date;
158158
}
159159

160-
/* @internal */
161-
export interface AWSCredentials {
162-
accessKeyId?: string;
163-
secretAccessKey?: string;
164-
sessionToken?: string;
165-
expiration?: Date;
166-
}
167-
168160
async function makeTempCredentials(credentials: MongoCredentials): Promise<MongoCredentials> {
169161
function makeMongoCredentialsFromAWSTemp(creds: AWSTempCredentials) {
170162
if (!creds.AccessKeyId || !creds.SecretAccessKey || !creds.Token) {

src/deps.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/* eslint-disable @typescript-eslint/no-var-requires */
22
import type { Document } from './bson';
3-
import type { AWSCredentials } from './cmap/auth/mongodb_aws';
43
import type { ProxyOptions } from './cmap/connection';
54
import { MongoMissingDependencyError } from './error';
65
import type { MongoClient } from './mongo_client';
@@ -76,6 +75,18 @@ export function getZstdLibrary(): typeof ZStandard | { kModuleError: MongoMissin
7675
}
7776
}
7877

78+
/**
79+
* @internal
80+
* Copy of the AwsCredentialIdentityProvider interface from [`@smithy/types`](https://socket.dev/npm/package/@smithy/types/files/1.1.1/dist-types/identity/awsCredentialIdentity.d.ts),
81+
* the return type of the aws-sdk's `fromNodeProviderChain().provider()`.
82+
*/
83+
export interface AWSCredentials {
84+
accessKeyId: string;
85+
secretAccessKey: string;
86+
sessionToken: string;
87+
expiration?: Date;
88+
}
89+
7990
type CredentialProvider = {
8091
fromNodeProviderChain(this: void): () => Promise<AWSCredentials>;
8192
};

0 commit comments

Comments
 (0)