From b1e3ed6ea9331001663434a9d1214299cf1e8015 Mon Sep 17 00:00:00 2001 From: Arnav Gupta Date: Sat, 12 May 2018 15:22:49 +0530 Subject: [PATCH 1/4] add types for discourse-sso Signed-off-by: Arnav Gupta --- types/discourse-sso/discourse-sso-tests.ts | 16 ++++++++++++ types/discourse-sso/index.d.ts | 30 ++++++++++++++++++++++ types/discourse-sso/tsconfig.json | 22 ++++++++++++++++ types/discourse-sso/tslint.json | 1 + 4 files changed, 69 insertions(+) create mode 100644 types/discourse-sso/discourse-sso-tests.ts create mode 100644 types/discourse-sso/index.d.ts create mode 100644 types/discourse-sso/tsconfig.json create mode 100644 types/discourse-sso/tslint.json diff --git a/types/discourse-sso/discourse-sso-tests.ts b/types/discourse-sso/discourse-sso-tests.ts new file mode 100644 index 0000000000..fe61efe08a --- /dev/null +++ b/types/discourse-sso/discourse-sso-tests.ts @@ -0,0 +1,16 @@ +import * as discourseSSO from 'discourse-sso' +const sso = new discourseSSO('sso secret string') + +if (sso.validate('payload', 'sig')) { + const nonce = sso.getNonce('payload') + + const userParams: discourseSSO.UserParams = { + nonce, + external_id: '1', + email: 'omg@mail.com', + username: 'myuser', + name: 'This Guy' + } + + const loginString: string = sso.buildLoginString(userParams) +} \ No newline at end of file diff --git a/types/discourse-sso/index.d.ts b/types/discourse-sso/index.d.ts new file mode 100644 index 0000000000..90c652948d --- /dev/null +++ b/types/discourse-sso/index.d.ts @@ -0,0 +1,30 @@ +// Type definitions for discourse-sso 1.0 +// Project: https://github.com/ArmedGuy/discourse_sso_node +// Definitions by: Arnav Gupta +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + + + + +declare class DiscourseSSO { + constructor(ssoSecret: string) + validate(payload: string, sig: string): boolean + getNonce(payload: string): string + buildLoginString(params: DiscourseSSO.UserParams): string +} +declare namespace DiscourseSSO { + + export interface UserParams { + nonce: string, + external_id: string, + email: string, + admin?: boolean, + moderator?: boolean, + username?: string, + name?: string, + avatar_url?: string, + add_groups?: string[], + remove_groups?: string[] + } +} +export = DiscourseSSO \ No newline at end of file diff --git a/types/discourse-sso/tsconfig.json b/types/discourse-sso/tsconfig.json new file mode 100644 index 0000000000..c80e56868b --- /dev/null +++ b/types/discourse-sso/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", + "discourse-sso-tests.ts" + ] +} diff --git a/types/discourse-sso/tslint.json b/types/discourse-sso/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/discourse-sso/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" } From bd9997047cccf10d7d275321e8847d462599af4d Mon Sep 17 00:00:00 2001 From: Arnav Gupta Date: Sat, 12 May 2018 15:53:39 +0530 Subject: [PATCH 2/4] Add strictFunctionTypes Signed-off-by: Arnav Gupta --- types/discourse-sso/tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/types/discourse-sso/tsconfig.json b/types/discourse-sso/tsconfig.json index c80e56868b..a0f1edbad5 100644 --- a/types/discourse-sso/tsconfig.json +++ b/types/discourse-sso/tsconfig.json @@ -7,6 +7,7 @@ "noImplicitAny": true, "noImplicitThis": true, "strictNullChecks": true, + "strictFunctionTypes": true, "baseUrl": "../", "typeRoots": [ "../" From 2be4ed83e95c648aa9dc0593e3e465074eef899a Mon Sep 17 00:00:00 2001 From: Arnav Gupta Date: Sat, 12 May 2018 16:03:57 +0530 Subject: [PATCH 3/4] tslint fixes Signed-off-by: Arnav Gupta --- types/discourse-sso/discourse-sso-tests.ts | 10 +++---- types/discourse-sso/index.d.ts | 35 ++++++++++------------ 2 files changed, 21 insertions(+), 24 deletions(-) diff --git a/types/discourse-sso/discourse-sso-tests.ts b/types/discourse-sso/discourse-sso-tests.ts index fe61efe08a..6ec2d967fc 100644 --- a/types/discourse-sso/discourse-sso-tests.ts +++ b/types/discourse-sso/discourse-sso-tests.ts @@ -1,8 +1,8 @@ -import * as discourseSSO from 'discourse-sso' -const sso = new discourseSSO('sso secret string') +import * as discourseSSO from 'discourse-sso'; +const sso = new discourseSSO('sso secret string'); if (sso.validate('payload', 'sig')) { - const nonce = sso.getNonce('payload') + const nonce = sso.getNonce('payload'); const userParams: discourseSSO.UserParams = { nonce, @@ -12,5 +12,5 @@ if (sso.validate('payload', 'sig')) { name: 'This Guy' } - const loginString: string = sso.buildLoginString(userParams) -} \ No newline at end of file + const loginString: string = sso.buildLoginString(userParams); +} diff --git a/types/discourse-sso/index.d.ts b/types/discourse-sso/index.d.ts index 90c652948d..322d2d609f 100644 --- a/types/discourse-sso/index.d.ts +++ b/types/discourse-sso/index.d.ts @@ -3,28 +3,25 @@ // Definitions by: Arnav Gupta // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped - - - declare class DiscourseSSO { - constructor(ssoSecret: string) - validate(payload: string, sig: string): boolean - getNonce(payload: string): string - buildLoginString(params: DiscourseSSO.UserParams): string + constructor(ssoSecret: string); + validate(payload: string, sig: string): boolean; + getNonce(payload: string): string; + buildLoginString(params: DiscourseSSO.UserParams): string; } + declare namespace DiscourseSSO { - export interface UserParams { - nonce: string, - external_id: string, - email: string, - admin?: boolean, - moderator?: boolean, - username?: string, - name?: string, - avatar_url?: string, - add_groups?: string[], - remove_groups?: string[] + nonce: string; + external_id: string; + email: string; + admin?: boolean; + moderator?: boolean; + username?: string; + name?: string; + avatar_url?: string; + add_groups?: string[]; + remove_groups?: string[]; } } -export = DiscourseSSO \ No newline at end of file +export = DiscourseSSO; \ No newline at end of file From bce8cdb6d36d24983dac1b482bdebba9be390d34 Mon Sep 17 00:00:00 2001 From: Arnav Gupta Date: Sat, 12 May 2018 16:16:43 +0530 Subject: [PATCH 4/4] more lint fixes Signed-off-by: Arnav Gupta --- types/discourse-sso/discourse-sso-tests.ts | 2 +- types/discourse-sso/index.d.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/types/discourse-sso/discourse-sso-tests.ts b/types/discourse-sso/discourse-sso-tests.ts index 6ec2d967fc..efe7eba95b 100644 --- a/types/discourse-sso/discourse-sso-tests.ts +++ b/types/discourse-sso/discourse-sso-tests.ts @@ -10,7 +10,7 @@ if (sso.validate('payload', 'sig')) { email: 'omg@mail.com', username: 'myuser', name: 'This Guy' - } + }; const loginString: string = sso.buildLoginString(userParams); } diff --git a/types/discourse-sso/index.d.ts b/types/discourse-sso/index.d.ts index 322d2d609f..b8030e0735 100644 --- a/types/discourse-sso/index.d.ts +++ b/types/discourse-sso/index.d.ts @@ -11,7 +11,7 @@ declare class DiscourseSSO { } declare namespace DiscourseSSO { - export interface UserParams { + interface UserParams { nonce: string; external_id: string; email: string; @@ -24,4 +24,4 @@ declare namespace DiscourseSSO { remove_groups?: string[]; } } -export = DiscourseSSO; \ No newline at end of file +export = DiscourseSSO;