From 60f9cc8b2c255fa2b1ba0872d52b9761887a1c8c Mon Sep 17 00:00:00 2001 From: Hugo Renard Date: Tue, 15 Feb 2022 14:09:03 +0100 Subject: [PATCH] change folder structure --- RcHttp.ts | 76 ---------- ScimApp.ts | 8 +- rc-sdk/RcSdkTeam.ts | 70 ---------- rc-sdk/RcSdkUser.ts | 35 ----- rest.ts | 62 -------- Context.ts => src/endpoints/Context.ts | 4 +- .../endpoints/GroupEndpoint.ts | 5 +- .../endpoints/GroupsEndpoint.ts | 23 +-- .../endpoints/ScimEndpoint.ts | 10 +- .../endpoints/UserEndpoint.ts | 36 +++-- .../endpoints/UsersEndpoint.ts | 37 +++-- {errors => src/errors}/BaseError.ts | 0 {errors => src/errors}/ConflictError.ts | 0 {errors => src/errors}/EmptyRequestError.ts | 0 {errors => src/errors}/EmptyResponseError.ts | 0 {errors => src/errors}/JsonParseError.ts | 0 {rc-sdk => src/rc-sdk}/RcSdk.ts | 0 src/rc-sdk/RcSdkTeam.ts | 132 ++++++++++++++++++ src/rc-sdk/RcSdkUser.ts | 101 ++++++++++++++ {scim => src/scim}/Error.ts | 0 {scim => src/scim}/Group.ts | 1 + {scim => src/scim}/Interfaces.ts | 0 {scim => src/scim}/ListResponse.ts | 0 {scim => src/scim}/Meta.ts | 0 {scim => src/scim}/User.ts | 1 + 25 files changed, 285 insertions(+), 316 deletions(-) delete mode 100644 RcHttp.ts delete mode 100644 rc-sdk/RcSdkTeam.ts delete mode 100644 rc-sdk/RcSdkUser.ts delete mode 100644 rest.ts rename Context.ts => src/endpoints/Context.ts (92%) rename GroupEndpoint.ts => src/endpoints/GroupEndpoint.ts (94%) rename GroupsEndpoint.ts => src/endpoints/GroupsEndpoint.ts (70%) rename ScimEndpoint.ts => src/endpoints/ScimEndpoint.ts (92%) rename UserEndpoint.ts => src/endpoints/UserEndpoint.ts (69%) rename UsersEndpoint.ts => src/endpoints/UsersEndpoint.ts (66%) rename {errors => src/errors}/BaseError.ts (100%) rename {errors => src/errors}/ConflictError.ts (100%) rename {errors => src/errors}/EmptyRequestError.ts (100%) rename {errors => src/errors}/EmptyResponseError.ts (100%) rename {errors => src/errors}/JsonParseError.ts (100%) rename {rc-sdk => src/rc-sdk}/RcSdk.ts (100%) create mode 100644 src/rc-sdk/RcSdkTeam.ts create mode 100644 src/rc-sdk/RcSdkUser.ts rename {scim => src/scim}/Error.ts (100%) rename {scim => src/scim}/Group.ts (95%) rename {scim => src/scim}/Interfaces.ts (100%) rename {scim => src/scim}/ListResponse.ts (100%) rename {scim => src/scim}/Meta.ts (100%) rename {scim => src/scim}/User.ts (97%) diff --git a/RcHttp.ts b/RcHttp.ts deleted file mode 100644 index 27df6e4..0000000 --- a/RcHttp.ts +++ /dev/null @@ -1,76 +0,0 @@ -import { - IHttp, - IHttpRequest, - IHttpResponse, - IRead, -} from "@rocket.chat/apps-engine/definition/accessors"; - -export class RcHttp implements IHttp { - private readonly baseUrl = "http://localhost:3000/api/v1"; - private readonly http: IHttp; - private readonly read: IRead; - - constructor(http: IHttp, read: IRead) { - this.http = http; - this.read = read; - } - - public async get(url: string, content?: any): Promise { - return this.http.get( - this.buildUrl(url), - await this.buildOptions(content), - ); - } - - public async post(url: string, content?: any): Promise { - return this.http.post( - this.buildUrl(url), - await this.buildOptions(content), - ); - } - - public async put(url: string, content?: any): Promise { - return this.http.put( - this.buildUrl(url), - await this.buildOptions(content), - ); - } - - public async del(url: string, content?: any): Promise { - return this.http.del( - this.buildUrl(url), - await this.buildOptions(content), - ); - } - - public async patch(url: string, content?: any): Promise { - return this.http.patch( - this.buildUrl(url), - await this.buildOptions(content), - ); - } - - private buildUrl(url: string): string { - return `${this.baseUrl}/${url}`; - } - - private async buildOptions(content?: any): Promise { - const options: IHttpRequest = { - headers: { - "X-User-Id": await this.read - .getEnvironmentReader() - .getSettings() - .getValueById("rc-user-id"), - "X-Auth-Token": await this.read - .getEnvironmentReader() - .getSettings() - .getValueById("rc-token"), - "Content-Type": "application/json", - }, - }; - if (content !== undefined) { - options.content = JSON.stringify(content); - } - return options; - } -} diff --git a/ScimApp.ts b/ScimApp.ts index b863074..7e784dc 100644 --- a/ScimApp.ts +++ b/ScimApp.ts @@ -10,11 +10,11 @@ import { import { App } from "@rocket.chat/apps-engine/definition/App"; import { IAppInfo } from "@rocket.chat/apps-engine/definition/metadata"; import { SettingType } from "@rocket.chat/apps-engine/definition/settings"; -import { GroupEndpoint } from "./GroupEndpoint"; -import { GroupsEndpoint } from "./GroupsEndpoint"; +import { GroupEndpoint } from "./src/endpoints/GroupEndpoint"; +import { GroupsEndpoint } from "./src/endpoints/GroupsEndpoint"; -import { UserEndpoint } from "./UserEndpoint"; -import { UsersEndpoint } from "./UsersEndpoint"; +import { UserEndpoint } from "./src/endpoints/UserEndpoint"; +import { UsersEndpoint } from "./src/endpoints/UsersEndpoint"; export class ScimApp extends App { constructor(info: IAppInfo, logger: ILogger, accessors: IAppAccessors) { diff --git a/rc-sdk/RcSdkTeam.ts b/rc-sdk/RcSdkTeam.ts deleted file mode 100644 index 08afe4e..0000000 --- a/rc-sdk/RcSdkTeam.ts +++ /dev/null @@ -1,70 +0,0 @@ -import { RcSdk } from "./RcSdk"; - -interface ITeamRemoveMemberBody { - teamId: string; - userId: string; -} - -interface ITeamAddMemberBody { - teamId: string; - members: Array<{ - userId: string; - roles: Array; - }>; -} - -interface ITeamDeleteBody { - teamId: string; - roomsToRemove?: Array; -} - -interface ITeamCreateBody { - name: string; - type: 0 | 1; - members?: Array; - room?: { - readOnly: boolean; - }; -} - -export class RcSdkTeam { - private sdk: RcSdk; - constructor(sdk: RcSdk) { - this.sdk = sdk; - } - - public async listAll(): Promise { - const response = await this.sdk.get(`teams.listAll`); - return this.sdk.parseResponse(response); - } - - public async members(teamId: string): Promise { - const response = await this.sdk.get(`teams.members?teamId=${teamId}`); - return this.sdk.parseResponse(response); - } - - public async info(teamId: string): Promise { - const response = await this.sdk.get(`teams.info?teamId=${teamId}`); - return this.sdk.parseResponse(response); - } - - public async delete(body: ITeamDeleteBody): Promise { - const response = await this.sdk.post(`teams.delete`, body); - return this.sdk.parseResponse(response); - } - - public async create(body: ITeamCreateBody): Promise { - const response = await this.sdk.post(`teams.create`, body); - return this.sdk.parseResponse(response); - } - - public async removeMember(body: ITeamRemoveMemberBody): Promise { - const response = await this.sdk.post(`teams.removeMember`, body); - return this.sdk.parseResponse(response); - } - - public async addMembers(body: ITeamAddMemberBody): Promise { - const response = await this.sdk.post(`teams.addMembers`, body); - return this.sdk.parseResponse(response); - } -} diff --git a/rc-sdk/RcSdkUser.ts b/rc-sdk/RcSdkUser.ts deleted file mode 100644 index 5bf3f73..0000000 --- a/rc-sdk/RcSdkUser.ts +++ /dev/null @@ -1,35 +0,0 @@ -import { RcSdk } from "./RcSdk"; - -export class RcSdkUser { - private sdk: RcSdk; - constructor(sdk: RcSdk) { - this.sdk = sdk; - } - - public async list(): Promise { - const response = await this.sdk.get( - `users.list?query={"type":{"$eq":"user"}}&fields={"createdAt":1}`, - ); - return this.sdk.parseResponse(response); - } - - public async info(userId: string): Promise { - const response = await this.sdk.get(`users.info?userId=${userId}`); - return this.sdk.parseResponse(response); - } - - public async update(body: IUserUpdate): Promise { - const response = await this.sdk.post(`users.update`, body); - return this.sdk.parseResponse(response); - } - - public async delete(body: IUserDelete): Promise { - const response = await this.sdk.post(`users.delete`); - return this.sdk.parseResponse(response); - } - - public async create(body: IUserCreate): Promise { - const response = await this.sdk.post(`users.create`, body); - return this.sdk.parseResponse(response); - } -} diff --git a/rest.ts b/rest.ts deleted file mode 100644 index 7308cb5..0000000 --- a/rest.ts +++ /dev/null @@ -1,62 +0,0 @@ -interface IUserCreate { - email: string; - name: string; - password: string; - username: string; - active?: boolean; - roles?: Array; - joinDefaultChannels?: boolean; - requirePasswordChange?: boolean; - sendWelcomeEmail?: boolean; - verified?: boolean; - customFields?: any; -} - -interface IUserUpdate { - userId: string; - data: { - email?: string; - name?: string; - password?: string; - username?: string; - active?: boolean; - roles?: Array; - joinDefaultChannels?: boolean; - requirePasswordChange?: boolean; - sendWelcomeEmail?: boolean; - verified?: boolean; - customFields?: any; - }; -} - -interface IUserDelete { - userId: string; - confirmRelinquish?: boolean; -} - -interface IUser { - _id: string; - emails: Array<{ address: string; verified: boolean }>; - name: string; - username: string; - active?: boolean; - createdAt: string; - _updatedAt?: string; -} - -interface ITeam { - _id: string; - name: string; - active?: boolean; - createdAt: string; - _updatedAt?: string; -} - -interface ITeamMember { - user: { - _id: string; - name: string; - username: string; - }; - createdAt: string; -} diff --git a/Context.ts b/src/endpoints/Context.ts similarity index 92% rename from Context.ts rename to src/endpoints/Context.ts index 72a1c7b..9a66424 100644 --- a/Context.ts +++ b/src/endpoints/Context.ts @@ -8,8 +8,8 @@ import { IApiEndpointInfo, IApiRequest, } from "@rocket.chat/apps-engine/definition/api"; -import { EmptyRequestError } from "./errors/EmptyRequestError"; -import { RcSdk } from "./rc-sdk/RcSdk"; +import { EmptyRequestError } from "../errors/EmptyRequestError"; +import { RcSdk } from "../rc-sdk/RcSdk"; export class Context { public readonly rc: RcSdk; diff --git a/GroupEndpoint.ts b/src/endpoints/GroupEndpoint.ts similarity index 94% rename from GroupEndpoint.ts rename to src/endpoints/GroupEndpoint.ts index 42fe86c..9536b14 100644 --- a/GroupEndpoint.ts +++ b/src/endpoints/GroupEndpoint.ts @@ -1,8 +1,7 @@ import { HttpStatusCode } from "@rocket.chat/apps-engine/definition/accessors"; import { IApiResponse } from "@rocket.chat/apps-engine/definition/api"; +import { SCIMGroup } from "../scim/Group"; import { Context } from "./Context"; -import { SCIMGroup } from "./scim/Group"; -import { SCIMUser } from "./scim/User"; import { IScimEndpoint, ScimEndpoint } from "./ScimEndpoint"; export class GroupEndpoint extends ScimEndpoint implements IScimEndpoint { @@ -33,7 +32,7 @@ export class GroupEndpoint extends ScimEndpoint implements IScimEndpoint { SCIMGroup.fromPlain(ctx.content()).members.map((x) => x.value), ); const currentIds = new Set( - membersRaw.members.map((x: ITeamMember) => x.user._id), + membersRaw.members.map((x) => x.user._id), ); const removeMember = async (userId: string) => { const removeMembersRaw = await ctx.rc.team.removeMember({ diff --git a/GroupsEndpoint.ts b/src/endpoints/GroupsEndpoint.ts similarity index 70% rename from GroupsEndpoint.ts rename to src/endpoints/GroupsEndpoint.ts index e226057..ab44d31 100644 --- a/GroupsEndpoint.ts +++ b/src/endpoints/GroupsEndpoint.ts @@ -1,21 +1,8 @@ -import { - HttpStatusCode, - IHttp, - IModify, - IPersistence, - IRead, -} from "@rocket.chat/apps-engine/definition/accessors"; -import { - IApiEndpointInfo, - IApiRequest, - IApiResponse, -} from "@rocket.chat/apps-engine/definition/api"; -import crypto = require("crypto"); +import { HttpStatusCode } from "@rocket.chat/apps-engine/definition/accessors"; +import { IApiResponse } from "@rocket.chat/apps-engine/definition/api"; +import { SCIMGroup } from "../scim/Group"; +import { SCIMListResponse } from "../scim/ListResponse"; import { Context } from "./Context"; -import { RcHttp } from "./RcHttp"; -import { SCIMGroup } from "./scim/Group"; -import { SCIMListResponse } from "./scim/ListResponse"; -import { SCIMUser } from "./scim/User"; import { IScimEndpoint, ScimEndpoint } from "./ScimEndpoint"; export class GroupsEndpoint extends ScimEndpoint implements IScimEndpoint { @@ -24,7 +11,7 @@ export class GroupsEndpoint extends ScimEndpoint implements IScimEndpoint { public async _get(ctx: Context): Promise { const teamsRaw = await ctx.rc.team.listAll(); this.handleError(teamsRaw); - const groups = teamsRaw.teams.map(async (team: ITeam) => { + const groups = teamsRaw.teams.map(async (team) => { const membersRaw = await ctx.rc.team.members(team._id); this.handleError(membersRaw); return SCIMGroup.fromRC(team, membersRaw.members); diff --git a/ScimEndpoint.ts b/src/endpoints/ScimEndpoint.ts similarity index 92% rename from ScimEndpoint.ts rename to src/endpoints/ScimEndpoint.ts index 5e72d59..bdfd269 100644 --- a/ScimEndpoint.ts +++ b/src/endpoints/ScimEndpoint.ts @@ -13,12 +13,12 @@ import { IApiResponse, } from "@rocket.chat/apps-engine/definition/api"; import { IApp } from "@rocket.chat/apps-engine/definition/IApp"; +import { ConflictError } from "../errors/ConflictError"; +import { EmptyRequestError } from "../errors/EmptyRequestError"; +import { EmptyResponseError } from "../errors/EmptyResponseError"; +import { JsonParseError } from "../errors/JsonParseError"; +import { SCIMError, SCIMErrorType } from "../scim/Error"; import { Context } from "./Context"; -import { ConflictError } from "./errors/ConflictError"; -import { EmptyRequestError } from "./errors/EmptyRequestError"; -import { EmptyResponseError } from "./errors/EmptyResponseError"; -import { JsonParseError } from "./errors/JsonParseError"; -import { SCIMError, SCIMErrorType } from "./scim/Error"; type ApiEndpointMethod = ( request: IApiRequest, diff --git a/UserEndpoint.ts b/src/endpoints/UserEndpoint.ts similarity index 69% rename from UserEndpoint.ts rename to src/endpoints/UserEndpoint.ts index 18fab64..d61b3fe 100644 --- a/UserEndpoint.ts +++ b/src/endpoints/UserEndpoint.ts @@ -1,7 +1,7 @@ import { HttpStatusCode } from "@rocket.chat/apps-engine/definition/accessors"; import { IApiResponse } from "@rocket.chat/apps-engine/definition/api"; +import { SCIMUser } from "../scim/User"; import { Context } from "./Context"; -import { SCIMUser } from "./scim/User"; import { IScimEndpoint, ScimEndpoint } from "./ScimEndpoint"; export class UserEndpoint extends ScimEndpoint implements IScimEndpoint { @@ -15,9 +15,21 @@ export class UserEndpoint extends ScimEndpoint implements IScimEndpoint { } public async _put(ctx: Context): Promise { - const o = await ctx.rc.user.update( - this.scimToUserUpdate(ctx.id(), SCIMUser.fromPlain(ctx.content())), - ); + const u = SCIMUser.fromPlain(ctx.content()); + const o = await ctx.rc.user.update({ + userId: ctx.id(), + data: { + email: u.getEmail(), + name: u.displayName, + username: u.userName, + active: u.active, + verified: true, + customFields: { + scimExternalId: u.externalId, + }, + }, + }); + this.handleError(o); const user = SCIMUser.fromRC(o.user); return this.success(user); @@ -33,20 +45,4 @@ export class UserEndpoint extends ScimEndpoint implements IScimEndpoint { status: HttpStatusCode.NO_CONTENT, }); } - - private scimToUserUpdate(userId: string, user: SCIMUser): IUserUpdate { - return { - userId, - data: { - email: user.getEmail(), - name: user.displayName, - username: user.userName, - active: user.active, - verified: true, - customFields: { - scimExternalId: user.externalId, - }, - }, - }; - } } diff --git a/UsersEndpoint.ts b/src/endpoints/UsersEndpoint.ts similarity index 66% rename from UsersEndpoint.ts rename to src/endpoints/UsersEndpoint.ts index 5e21a27..0d69850 100644 --- a/UsersEndpoint.ts +++ b/src/endpoints/UsersEndpoint.ts @@ -1,9 +1,9 @@ import { HttpStatusCode } from "@rocket.chat/apps-engine/definition/accessors"; import { IApiResponse } from "@rocket.chat/apps-engine/definition/api"; import crypto = require("crypto"); +import { SCIMListResponse } from "../scim/ListResponse"; +import { SCIMUser } from "../scim/User"; import { Context } from "./Context"; -import { SCIMListResponse } from "./scim/ListResponse"; -import { SCIMUser } from "./scim/User"; import { IScimEndpoint, ScimEndpoint } from "./ScimEndpoint"; export class UsersEndpoint extends ScimEndpoint implements IScimEndpoint { @@ -19,9 +19,20 @@ export class UsersEndpoint extends ScimEndpoint implements IScimEndpoint { } public async _post(ctx: Context): Promise { - const o = await ctx.rc.user.create( - this.scimToUserCreate(SCIMUser.fromPlain(ctx.content())), - ); + const u = SCIMUser.fromPlain(ctx.content()); + const o = await ctx.rc.user.create({ + email: u.getEmail(), + name: + u.displayName || + `${u.name.givenName} ${u.name.familyName}` || + u.userName, + username: u.userName, + password: crypto.randomBytes(64).toString("base64").slice(0, 64), + verified: true, + customFields: { + scimExternalId: u.externalId, + }, + }); this.handleError(o); const user = SCIMUser.fromRC(o.user); return this.response({ @@ -29,20 +40,4 @@ export class UsersEndpoint extends ScimEndpoint implements IScimEndpoint { content: user, }); } - - private scimToUserCreate(user: SCIMUser): IUserCreate { - return { - email: user.getEmail(), - name: - user.displayName || - `${user.name.givenName} ${user.name.familyName}` || - user.userName, - username: user.userName, - password: crypto.randomBytes(64).toString("base64").slice(0, 64), - verified: true, - customFields: { - scimExternalId: user.externalId, - }, - }; - } } diff --git a/errors/BaseError.ts b/src/errors/BaseError.ts similarity index 100% rename from errors/BaseError.ts rename to src/errors/BaseError.ts diff --git a/errors/ConflictError.ts b/src/errors/ConflictError.ts similarity index 100% rename from errors/ConflictError.ts rename to src/errors/ConflictError.ts diff --git a/errors/EmptyRequestError.ts b/src/errors/EmptyRequestError.ts similarity index 100% rename from errors/EmptyRequestError.ts rename to src/errors/EmptyRequestError.ts diff --git a/errors/EmptyResponseError.ts b/src/errors/EmptyResponseError.ts similarity index 100% rename from errors/EmptyResponseError.ts rename to src/errors/EmptyResponseError.ts diff --git a/errors/JsonParseError.ts b/src/errors/JsonParseError.ts similarity index 100% rename from errors/JsonParseError.ts rename to src/errors/JsonParseError.ts diff --git a/rc-sdk/RcSdk.ts b/src/rc-sdk/RcSdk.ts similarity index 100% rename from rc-sdk/RcSdk.ts rename to src/rc-sdk/RcSdk.ts diff --git a/src/rc-sdk/RcSdkTeam.ts b/src/rc-sdk/RcSdkTeam.ts new file mode 100644 index 0000000..0a9db37 --- /dev/null +++ b/src/rc-sdk/RcSdkTeam.ts @@ -0,0 +1,132 @@ +import { RcSdk } from "./RcSdk"; + +interface ITeamRemoveMemberBody { + teamId: string; + userId: string; +} + +interface ITeamAddMemberBody { + teamId: string; + members: Array<{ + userId: string; + roles: Array; + }>; +} + +interface ITeamDeleteBody { + teamId: string; + roomsToRemove?: Array; +} + +interface ITeamCreateBody { + name: string; + type: 0 | 1; + members?: Array; + room?: { + readOnly: boolean; + }; +} + +export interface ITeam { + _id: string; + name: string; + active?: boolean; + createdAt: string; + _updatedAt?: string; +} + +export interface ITeamMember { + user: { + _id: string; + name: string; + username: string; + }; + createdAt: string; +} + +interface ITeamListAllResponse { + teams: Array; + count: number; + offset: number; + total: number; + success: boolean; + error?: string; +} + +interface ITeamMembersResponse { + members: Array; + count: number; + offset: number; + total: number; + success: boolean; + error?: string; +} + +interface ITeamInfoResponse { + teamInfo: ITeam; + success: boolean; + error?: string; +} + +interface ITeamDeleteResponse { + teamInfo: ITeam; + success: boolean; + error?: string; +} + +interface ITeamCreateResponse { + team: ITeam; + success: boolean; + error?: string; +} + +interface ITeamMemberResponse { + success: boolean; + error?: string; +} + +export class RcSdkTeam { + private sdk: RcSdk; + constructor(sdk: RcSdk) { + this.sdk = sdk; + } + + public async listAll(): Promise { + const response = await this.sdk.get(`teams.listAll`); + return this.sdk.parseResponse(response); + } + + public async members(teamId: string): Promise { + const response = await this.sdk.get(`teams.members?teamId=${teamId}`); + return this.sdk.parseResponse(response); + } + + public async info(teamId: string): Promise { + const response = await this.sdk.get(`teams.info?teamId=${teamId}`); + return this.sdk.parseResponse(response); + } + + public async delete(body: ITeamDeleteBody): Promise { + const response = await this.sdk.post(`teams.delete`, body); + return this.sdk.parseResponse(response); + } + + public async create(body: ITeamCreateBody): Promise { + const response = await this.sdk.post(`teams.create`, body); + return this.sdk.parseResponse(response); + } + + public async removeMember( + body: ITeamRemoveMemberBody, + ): Promise { + const response = await this.sdk.post(`teams.removeMember`, body); + return this.sdk.parseResponse(response); + } + + public async addMembers( + body: ITeamAddMemberBody, + ): Promise { + const response = await this.sdk.post(`teams.addMembers`, body); + return this.sdk.parseResponse(response); + } +} diff --git a/src/rc-sdk/RcSdkUser.ts b/src/rc-sdk/RcSdkUser.ts new file mode 100644 index 0000000..0d85330 --- /dev/null +++ b/src/rc-sdk/RcSdkUser.ts @@ -0,0 +1,101 @@ +import { RcSdk } from "./RcSdk"; + +interface IUserCreate { + email: string; + name: string; + password: string; + username: string; + active?: boolean; + roles?: Array; + joinDefaultChannels?: boolean; + requirePasswordChange?: boolean; + sendWelcomeEmail?: boolean; + verified?: boolean; + customFields?: any; +} + +interface IUserUpdate { + userId: string; + data: { + email?: string; + name?: string; + password?: string; + username?: string; + active?: boolean; + roles?: Array; + joinDefaultChannels?: boolean; + requirePasswordChange?: boolean; + sendWelcomeEmail?: boolean; + verified?: boolean; + customFields?: any; + }; +} + +interface IUserDelete { + userId: string; + confirmRelinquish?: boolean; +} + +export interface IUser { + _id: string; + emails: Array<{ address: string; verified: boolean }>; + name: string; + username: string; + active?: boolean; + createdAt: string; + _updatedAt?: string; +} + +interface IUserListResponse { + users: Array; + count: number; + offset: number; + total: number; + success: boolean; + error?: string; +} + +interface IUserResponse { + user: IUser; + success: boolean; + error?: string; +} + +interface IUserDeleteResponse { + success: boolean; + error?: string; +} + +export class RcSdkUser { + private sdk: RcSdk; + constructor(sdk: RcSdk) { + this.sdk = sdk; + } + + public async list(): Promise { + const response = await this.sdk.get( + `users.list?query={"type":{"$eq":"user"}}&fields={"createdAt":1}`, + ); + return this.sdk.parseResponse(response); + } + + public async info(userId: string): Promise { + const response = await this.sdk.get(`users.info?userId=${userId}`); + return this.sdk.parseResponse(response); + } + + public async update(body: IUserUpdate): Promise { + const response = await this.sdk.post(`users.update`, body); + return this.sdk.parseResponse(response); + } + + public async delete(body: IUserDelete): Promise { + const response = await this.sdk.post(`users.delete`); + return this.sdk.parseResponse(response); + } + + public async create(body: IUserCreate): Promise { + const response = await this.sdk.post(`users.create`, body); + return this.sdk.parseResponse(response); + } +} diff --git a/scim/Error.ts b/src/scim/Error.ts similarity index 100% rename from scim/Error.ts rename to src/scim/Error.ts diff --git a/scim/Group.ts b/src/scim/Group.ts similarity index 95% rename from scim/Group.ts rename to src/scim/Group.ts index f4cb90f..e4dd2db 100644 --- a/scim/Group.ts +++ b/src/scim/Group.ts @@ -1,3 +1,4 @@ +import { ITeam, ITeamMember } from "../rc-sdk/RcSdkTeam"; import { ISCIMGroupMember, ISCIMResource } from "./Interfaces"; import { SCIMMeta } from "./Meta"; diff --git a/scim/Interfaces.ts b/src/scim/Interfaces.ts similarity index 100% rename from scim/Interfaces.ts rename to src/scim/Interfaces.ts diff --git a/scim/ListResponse.ts b/src/scim/ListResponse.ts similarity index 100% rename from scim/ListResponse.ts rename to src/scim/ListResponse.ts diff --git a/scim/Meta.ts b/src/scim/Meta.ts similarity index 100% rename from scim/Meta.ts rename to src/scim/Meta.ts diff --git a/scim/User.ts b/src/scim/User.ts similarity index 97% rename from scim/User.ts rename to src/scim/User.ts index 057cf25..0f2e5e8 100644 --- a/scim/User.ts +++ b/src/scim/User.ts @@ -1,3 +1,4 @@ +import { IUser } from "../rc-sdk/RcSdkUser"; import { ISCIMResource, ISCIMUserEmail, ISCIMUserName } from "./Interfaces"; import { SCIMMeta } from "./Meta";