From dc8647855732dcbccee2a1d3dd52f8932cbdcd00 Mon Sep 17 00:00:00 2001 From: mtgto Date: Wed, 4 Jul 2018 02:05:55 +0900 Subject: [PATCH] Add a definition of atlassian-crowd-client (#26782) * Add a definition of atlassian-crowd-client * [atlassian-crowd-client] Fix a wrong definition. * Add `"strictFunctionTypes": true` * [atlassian-crowd-client] Fix a compile error. * [atlassian-crowd-client] Use `export =` instead of `export default`. * Use `export =` instead of `export default` * Use `import = require` --- types/atlassian-crowd-client/api.d.ts | 10 ++ .../atlassian-crowd-client-tests.ts | 44 +++++++ types/atlassian-crowd-client/index.d.ts | 117 ++++++++++++++++++ .../lib/models/attributes.d.ts | 8 ++ .../lib/models/group.d.ts | 18 +++ .../lib/models/session.d.ts | 16 +++ .../lib/models/user.d.ts | 25 ++++ .../lib/models/validation-factors.d.ts | 12 ++ types/atlassian-crowd-client/settings.d.ts | 12 ++ types/atlassian-crowd-client/tsconfig.json | 24 ++++ types/atlassian-crowd-client/tslint.json | 1 + 11 files changed, 287 insertions(+) create mode 100644 types/atlassian-crowd-client/api.d.ts create mode 100644 types/atlassian-crowd-client/atlassian-crowd-client-tests.ts create mode 100644 types/atlassian-crowd-client/index.d.ts create mode 100644 types/atlassian-crowd-client/lib/models/attributes.d.ts create mode 100644 types/atlassian-crowd-client/lib/models/group.d.ts create mode 100644 types/atlassian-crowd-client/lib/models/session.d.ts create mode 100644 types/atlassian-crowd-client/lib/models/user.d.ts create mode 100644 types/atlassian-crowd-client/lib/models/validation-factors.d.ts create mode 100644 types/atlassian-crowd-client/settings.d.ts create mode 100644 types/atlassian-crowd-client/tsconfig.json create mode 100644 types/atlassian-crowd-client/tslint.json diff --git a/types/atlassian-crowd-client/api.d.ts b/types/atlassian-crowd-client/api.d.ts new file mode 100644 index 0000000000..0064382605 --- /dev/null +++ b/types/atlassian-crowd-client/api.d.ts @@ -0,0 +1,10 @@ +import { Settings } from "./settings"; + +declare class CrowdApi { + settings: Settings; + constructor(settings: Settings); + request(method: string, path: string, data?: any): Promise; + log(...args: any[]): void; +} + +export = CrowdApi; diff --git a/types/atlassian-crowd-client/atlassian-crowd-client-tests.ts b/types/atlassian-crowd-client/atlassian-crowd-client-tests.ts new file mode 100644 index 0000000000..c43c272343 --- /dev/null +++ b/types/atlassian-crowd-client/atlassian-crowd-client-tests.ts @@ -0,0 +1,44 @@ +import CrowdClient = require("atlassian-crowd-client"); +import Attributes = require("atlassian-crowd-client/lib/models/attributes"); +import Group = require("atlassian-crowd-client/lib/models/group"); +import Session = require("atlassian-crowd-client/lib/models/session"); +import User = require("atlassian-crowd-client/lib/models/user"); + +// Initialize the Crowd client: +const crowd = new CrowdClient({ + baseUrl: "https://crowd.example.com/", + application: { + name: "demo", + password: "example" + } +}); + +// Create a new user: +crowd.user.create(new User("John", "Doe", "John Doe", "johndoe@example.com", "johndoe", "secret")); +// Remove +crowd.user.remove("johndoe"); + +// Authenticate to Crowd: +crowd.session.create("someusername", "somepassword").then((session: Session) => { + // Fetch the user profile: + crowd.session.getUser(session.token).then((user: User) => { + console.log("Hello, " + user.displayname); + }); +}); + +// Find all active groups (using Crowd Query Language): +crowd.search.group("active=true").then((groups: string[] | Group[]) => { + console.log("Found groups: " + groups.length); +}); + +const group = new Group("testgroup1", "Test group"); + +const attributes = new Attributes({ + foo: "Foo", + bar: ["Bar", "Baz"], + obj: { a: "A" } +}); + +crowd.group.attributes.set(group.groupname, attributes).then(() => { + console.log("Group attribute is set."); +}); diff --git a/types/atlassian-crowd-client/index.d.ts b/types/atlassian-crowd-client/index.d.ts new file mode 100644 index 0000000000..a2e5d8e88f --- /dev/null +++ b/types/atlassian-crowd-client/index.d.ts @@ -0,0 +1,117 @@ +// Type definitions for atlassian-crowd-client 2.0 +// Project: https://github.com/ghengeveld/atlassian-crowd-client +// Definitions by: mtgto +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +import CrowdApi = require("./api"); +import { Settings } from "./settings"; +import Attributes = require("./lib/models/attributes"); +import Group = require("./lib/models/group"); +import User = require("./lib/models/user"); +import Session = require("./lib/models/session"); +import ValidationFactors = require("./lib/models/validation-factors"); + +export = CrowdClient; +declare class CrowdClient extends CrowdApi { + settings: Settings; + + constructor(settings: Settings); + + user: { + get: (username: string, withAttributes?: boolean) => Promise; + create: (user: User) => Promise; + update: (username: string, user: User) => Promise; + rename: (oldname: string, newname: string) => Promise; + remove: (username: string) => Promise; + attributes: { + list: (username: string) => Promise; + set: (username: string, attributes: Attributes) => Promise; + remove: (username: string, attributename: string) => Promise; + password: { + set: (username: string, password: string) => Promise; + reset: (username: string) => Promise; + }; + username: { + request: (email: string) => Promise; + }; + }; + groups: { + get: (username: string, groupname: string, nested?: boolean) => Promise; + list: (username: string, nested?: boolean, startIndex?: number, maxResults?: number) => Promise; + add: (username: string, groupname: string) => Promise; + remove: (username: string, groupname: string) => Promise; + }; + }; + group: { + get: (groupname: string, withAttributes?: boolean) => Promise; + create: (group: Group) => Promise; + update: (groupname: string, group: Group) => Promise; + remove: (groupname: string) => Promise; + attributes: { + list: (groupname: string) => Promise; + set: (groupname: string, attributes: Attributes) => Promise; + remove: (groupname: string, attributename: string) => Promise; + }; + users: { + get: (groupname: string, username: string, nested?: boolean) => Promise; + list: ( + groupname: string, + nested?: boolean, + startIndex?: number, + maxResults?: number, + expand?: boolean, + ) => Promise; + add: (groupname: string, username: string) => Promise; + remove: (groupname: string, username: string) => Promise; + }; + parents: { + get: (groupname: string, parentname: string, nested?: boolean) => Promise; + list: (groupname: string, nested?: boolean, startIndex?: number, maxResults?: number) => Promise; + add: (groupname: string, parentname: string) => Promise; + }; + children: { + get: (groupname: string, childname: string, nested?: boolean) => Promise; + list: (groupname: string, nested?: boolean, startIndex?: number, maxResults?: number) => Promise; + add: (groupname: string, childname: string) => Promise; + remove: (groupname: string, childname: string) => Promise; + }; + membership: () => Promise; + }; + authentication: { + authenticate: (username: string, password: string) => Promise; + }; + search: { + user: ( + restriction: string, + expand?: boolean, + startIndex?: number, + maxResults?: number, + ) => Promise; + group: ( + restriction: string, + expand?: boolean, + startIndex?: number, + maxResults?: number, + ) => Promise; + }; + session: { + getUser: (token: string) => Promise; + validate: (token: string, validationFactors?: ValidationFactors) => Promise; + create: ( + username: string, + password: string, + validationFactors?: ValidationFactors, + duration?: number, + ) => Promise; + createUnvalidated: ( + username: string, + validationFactors?: ValidationFactors, + duration?: number, + ) => Promise; + remove: (token: string) => Promise; + removeAll: (username: string, exclude?: string) => Promise; + }; + config: { + cookie: () => Promise; + }; +} diff --git a/types/atlassian-crowd-client/lib/models/attributes.d.ts b/types/atlassian-crowd-client/lib/models/attributes.d.ts new file mode 100644 index 0000000000..3385311546 --- /dev/null +++ b/types/atlassian-crowd-client/lib/models/attributes.d.ts @@ -0,0 +1,8 @@ +export = Attributes; +declare class Attributes { + readonly attributes: {[name: string]: any}; + + constructor(attributePairs: {[name: string]: any}); + toCrowd(stringify?: (attr: any) => string): any; + static fromCrowd(attributesArr: ReadonlyArray<{name: string}>, parse?: (json: string) => any): Attributes; +} diff --git a/types/atlassian-crowd-client/lib/models/group.d.ts b/types/atlassian-crowd-client/lib/models/group.d.ts new file mode 100644 index 0000000000..e7dc70b6df --- /dev/null +++ b/types/atlassian-crowd-client/lib/models/group.d.ts @@ -0,0 +1,18 @@ +export = Group; +declare class Group { + readonly groupname: string; + readonly description: string; + readonly active: boolean; + readonly attributes?: any; + + constructor(groupname: string, description?: string, active?: boolean, attributes?: any); + toCrowd(): GroupObj; + static fromCrowd(obj: {name: string, description?: string, active?: boolean, attributes: any}): Group; +} + +interface GroupObj { + readonly type: "GROUP"; + readonly name: string; + readonly description: string; + readonly active: boolean; +} diff --git a/types/atlassian-crowd-client/lib/models/session.d.ts b/types/atlassian-crowd-client/lib/models/session.d.ts new file mode 100644 index 0000000000..2ef16a0814 --- /dev/null +++ b/types/atlassian-crowd-client/lib/models/session.d.ts @@ -0,0 +1,16 @@ +export = Session; +declare class Session { + readonly token: string; + readonly createdAt: Date; + readonly expiresAt: Date; + + constructor(token: string, createdAt: Date, expiresAt: Date); + toCrowd(): SessionObj; + static fromCrowd(obj: SessionObj): Session; +} + +interface SessionObj { + readonly token: string; + readonly "created-date": number; + readonly "expiry-date": number; +} diff --git a/types/atlassian-crowd-client/lib/models/user.d.ts b/types/atlassian-crowd-client/lib/models/user.d.ts new file mode 100644 index 0000000000..cf5fdeb115 --- /dev/null +++ b/types/atlassian-crowd-client/lib/models/user.d.ts @@ -0,0 +1,25 @@ +export = User; +declare class User { + readonly firstname: string; + readonly lastname: string; + readonly displayname: string; + readonly email: string; + readonly username: string; + readonly password?: string; + readonly active: boolean; + readonly attributes: {[key: string]: any}; + + constructor(firstname: string, lastname: string, displayname: string, email: string, username: string, password?: string, active?: boolean, attributes?: any); + toCrowd(): UserObj; + static fromCrowd(userObj: UserObj): User; +} + +interface UserObj { + readonly "name": string; + readonly "first-name": string; + readonly "last-name": string; + readonly "display-name": string; + readonly "email": string; + readonly "active": boolean; + readonly "password"?: { value: string }; +} diff --git a/types/atlassian-crowd-client/lib/models/validation-factors.d.ts b/types/atlassian-crowd-client/lib/models/validation-factors.d.ts new file mode 100644 index 0000000000..60e418f80d --- /dev/null +++ b/types/atlassian-crowd-client/lib/models/validation-factors.d.ts @@ -0,0 +1,12 @@ +export = ValidationFactors; +declare class ValidationFactors { + readonly validationFactors: any; + + constructor(validationFactorPairs: any); + toCrowd(): ValidationFactorsObj; + static fromCrowd(validationFactorsObj: ValidationFactorsObj): ValidationFactors; +} + +interface ValidationFactorsObj { + validationFactors: any[]; +} diff --git a/types/atlassian-crowd-client/settings.d.ts b/types/atlassian-crowd-client/settings.d.ts new file mode 100644 index 0000000000..755c26038a --- /dev/null +++ b/types/atlassian-crowd-client/settings.d.ts @@ -0,0 +1,12 @@ +export interface Settings { + readonly baseUrl: string; + readonly application: { + readonly name: string; + readonly password: string; + } + readonly nesting?: boolean; + readonly sessionTimeout?: number; + readonly debug?: boolean; + readonly attributesParser?: (json: string) => any; + readonly attributesEncoder?: (obj: any) => string; +} diff --git a/types/atlassian-crowd-client/tsconfig.json b/types/atlassian-crowd-client/tsconfig.json new file mode 100644 index 0000000000..51cfc0966c --- /dev/null +++ b/types/atlassian-crowd-client/tsconfig.json @@ -0,0 +1,24 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6", + "dom" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "atlassian-crowd-client-tests.ts" + ] +} diff --git a/types/atlassian-crowd-client/tslint.json b/types/atlassian-crowd-client/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/atlassian-crowd-client/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }