From 9ef7415615c0feb97a6ec5fbe85e4544273fd352 Mon Sep 17 00:00:00 2001 From: Mike Cook Date: Mon, 19 Mar 2018 09:52:05 +0000 Subject: [PATCH 1/3] Add typings for nodecredstash --- types/nodecredstash/index.d.ts | 45 +++++++++++++++++ types/nodecredstash/nodecredstash-tests.ts | 59 ++++++++++++++++++++++ types/nodecredstash/tsconfig.json | 22 ++++++++ types/nodecredstash/tslint.json | 1 + 4 files changed, 127 insertions(+) create mode 100644 types/nodecredstash/index.d.ts create mode 100644 types/nodecredstash/nodecredstash-tests.ts create mode 100644 types/nodecredstash/tsconfig.json create mode 100644 types/nodecredstash/tslint.json diff --git a/types/nodecredstash/index.d.ts b/types/nodecredstash/index.d.ts new file mode 100644 index 0000000000..d2489178a4 --- /dev/null +++ b/types/nodecredstash/index.d.ts @@ -0,0 +1,45 @@ +// Type definitions for nodecredstash 2.0 +// Project: https://github.com/DavidTanner/nodecredstash#readme +// Definitions by: Mike Cook +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +/// +import * as AWS from 'aws-sdk'; + +interface ICredstashConfig { + table?: string; + awsOpts?: AWS.KMS.ClientConfiguration; + dynamoOpts?: AWS.DynamoDB.ClientConfiguration; + kmsKey?: string; + kmsOpts?: AWS.KMS.ClientConfiguration; +} + +interface ICredstashContext { + [key: string]: string; +} + +interface IPutSecretOptions { + name: string; + secret: string; + context: ICredstashContext; + digest?: string; + version?: number; +} + +interface ICredstash { + getHighestVersion: (options: { name: string }) => Promise; + incrementVersion: (options: { name: string }) => Promise; + putSecret: (options: IPutSecretOptions) => Promise; + decryptStash: (stash: { key: string; }, context?: ICredstashContext) => Promise; + getAllVersions: (options: { name: string, context?: ICredstashContext, limit?: number }) => Promise>; + getSecret: (options: { name: string, context?: ICredstashContext, version?: number }) => Promise; + deleteSecrets: (options: { name: string }) => Promise>; + deleteSecret: (options: { name: string, version: number }) => Promise; + listSecrets: () => Promise; + getAllSecrets: (options: { version?: number, context?: ICredstashContext, startsWith?: string }) => Promise<{ [key: string]: string }>; + createDdbTable: () => Promise; +} + +declare function Credstash(config: ICredstashConfig): ICredstash; + +export = Credstash; diff --git a/types/nodecredstash/nodecredstash-tests.ts b/types/nodecredstash/nodecredstash-tests.ts new file mode 100644 index 0000000000..f3788adc55 --- /dev/null +++ b/types/nodecredstash/nodecredstash-tests.ts @@ -0,0 +1,59 @@ +import Credstash = require('nodecredstash'); + +const credstash = Credstash({ + awsOpts: { region: 'us-east-1' }, + dynamoOpts: { accessKeyId: 'foo' }, + kmsKey: 'bar', + kmsOpts: { accessKeyId: 'baz' }, + table: 'something' +}); + +credstash.decryptStash({ key: 'foo' }).then((result) => { + return { + id: result.KeyId, + text: result.Plaintext + }; +}); + +credstash.deleteSecret({ name: 'foo', version: 1 }).then((result) => { + if (result.Attributes) return result.Attributes['blah']; + if (result.ConsumedCapacity) return result.ConsumedCapacity.TableName; + if (result.ItemCollectionMetrics) return result.ItemCollectionMetrics.ItemCollectionKey; +}); + +credstash.deleteSecrets({ name: 'foo' }).then((results) => { + const result = results[0]; + if (result.Attributes) return result.Attributes['blah'].toUpperCase(); + if (result.ConsumedCapacity) return result.ConsumedCapacity.TableName; + if (result.ItemCollectionMetrics) return result.ItemCollectionMetrics.ItemCollectionKey; +}); + +credstash.getAllSecrets({ version: 1 }).then((result) => { + return result['foo'].toUpperCase(); +}); + +credstash.getAllVersions({ name: 'foo', context: { bar: 'baz' }, limit: 1 }).then((result) => { + return result[0].secret.toUpperCase() + result[0].version.toUpperCase(); +}); + +credstash.getHighestVersion({ name: 'foo' }).then((result) => { + return result['foo'].S; +}); + +credstash.getSecret({ name: 'foo', version: 1, context: { bar: 'baz' } }).then((result) => { + return result.toUpperCase(); +}); + +credstash.incrementVersion({ name: 'foo' }).then((result) => { + return result.toUpperCase(); +}); + +credstash.listSecrets().then((result) => { + return result.map((str) => str.toUpperCase()); +}); + +credstash.putSecret({ name: 'foo', secret: 'bar', context: { baz: 'qux' }, digest: 'quux', version: 1 }).then((result) => { + if (result.Attributes) return result.Attributes['foo']; + if (result.ConsumedCapacity) return result.ConsumedCapacity.TableName; + if (result.ItemCollectionMetrics) return result.ItemCollectionMetrics.ItemCollectionKey; +}); diff --git a/types/nodecredstash/tsconfig.json b/types/nodecredstash/tsconfig.json new file mode 100644 index 0000000000..da430c0182 --- /dev/null +++ b/types/nodecredstash/tsconfig.json @@ -0,0 +1,22 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "nodecredstash-tests.ts" + ] +} diff --git a/types/nodecredstash/tslint.json b/types/nodecredstash/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/nodecredstash/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From a626af102fb70b84e03389a55edb3db026700e4b Mon Sep 17 00:00:00 2001 From: Mike Cook Date: Mon, 19 Mar 2018 10:02:26 +0000 Subject: [PATCH 2/3] Dependencies and linting updates --- types/nodecredstash/index.d.ts | 24 ++++++++++++------------ types/nodecredstash/package.json | 6 ++++++ types/nodecredstash/tsconfig.json | 1 + 3 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 types/nodecredstash/package.json diff --git a/types/nodecredstash/index.d.ts b/types/nodecredstash/index.d.ts index d2489178a4..76375aac21 100644 --- a/types/nodecredstash/index.d.ts +++ b/types/nodecredstash/index.d.ts @@ -6,7 +6,7 @@ /// import * as AWS from 'aws-sdk'; -interface ICredstashConfig { +interface CredstashConfig { table?: string; awsOpts?: AWS.KMS.ClientConfiguration; dynamoOpts?: AWS.DynamoDB.ClientConfiguration; @@ -14,32 +14,32 @@ interface ICredstashConfig { kmsOpts?: AWS.KMS.ClientConfiguration; } -interface ICredstashContext { +interface CredstashContext { [key: string]: string; } -interface IPutSecretOptions { +interface PutSecretOptions { name: string; secret: string; - context: ICredstashContext; + context: CredstashContext; digest?: string; version?: number; } -interface ICredstash { +interface Credstash { getHighestVersion: (options: { name: string }) => Promise; incrementVersion: (options: { name: string }) => Promise; - putSecret: (options: IPutSecretOptions) => Promise; - decryptStash: (stash: { key: string; }, context?: ICredstashContext) => Promise; - getAllVersions: (options: { name: string, context?: ICredstashContext, limit?: number }) => Promise>; - getSecret: (options: { name: string, context?: ICredstashContext, version?: number }) => Promise; - deleteSecrets: (options: { name: string }) => Promise>; + putSecret: (options: PutSecretOptions) => Promise; + decryptStash: (stash: { key: string; }, context?: CredstashContext) => Promise; + getAllVersions: (options: { name: string, context?: CredstashContext, limit?: number }) => Promise>; + getSecret: (options: { name: string, context?: CredstashContext, version?: number }) => Promise; + deleteSecrets: (options: { name: string }) => Promise; deleteSecret: (options: { name: string, version: number }) => Promise; listSecrets: () => Promise; - getAllSecrets: (options: { version?: number, context?: ICredstashContext, startsWith?: string }) => Promise<{ [key: string]: string }>; + getAllSecrets: (options: { version?: number, context?: CredstashContext, startsWith?: string }) => Promise<{ [key: string]: string }>; createDdbTable: () => Promise; } -declare function Credstash(config: ICredstashConfig): ICredstash; +declare function Credstash(config: CredstashConfig): Credstash; export = Credstash; diff --git a/types/nodecredstash/package.json b/types/nodecredstash/package.json new file mode 100644 index 0000000000..0347abc684 --- /dev/null +++ b/types/nodecredstash/package.json @@ -0,0 +1,6 @@ +{ + "dependencies": { + "aws-sdk": "^2.211.0" + }, + "private": true +} diff --git a/types/nodecredstash/tsconfig.json b/types/nodecredstash/tsconfig.json index da430c0182..ec4305243c 100644 --- a/types/nodecredstash/tsconfig.json +++ b/types/nodecredstash/tsconfig.json @@ -7,6 +7,7 @@ "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, + "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ "../" From 59685b6f85c3e0cffe9aafe7692360226683e74f Mon Sep 17 00:00:00 2001 From: Mike Cook Date: Tue, 27 Mar 2018 08:04:13 +0100 Subject: [PATCH 3/3] Remove readme anchor from project link --- types/nodecredstash/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/types/nodecredstash/index.d.ts b/types/nodecredstash/index.d.ts index 76375aac21..9b2fed47c8 100644 --- a/types/nodecredstash/index.d.ts +++ b/types/nodecredstash/index.d.ts @@ -1,5 +1,5 @@ // Type definitions for nodecredstash 2.0 -// Project: https://github.com/DavidTanner/nodecredstash#readme +// Project: https://github.com/DavidTanner/nodecredstash // Definitions by: Mike Cook // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped