@liquid-state/idm-client
Advanced tools
Comparing version
@@ -8,5 +8,10 @@ import { IIDMClient, Options, CreateUser, CreateInvitation } from './types'; | ||
private getURL; | ||
private buildPath; | ||
private apiRequest; | ||
createInvitation: (invitation: CreateInvitation) => Promise<Response>; | ||
createUser: (newUser: CreateUser) => Promise<Response>; | ||
deleteInvitation: (id: string) => Promise<Response>; | ||
updateUserProfile: (id: string, profile: { | ||
[key: string]: any; | ||
}) => Promise<Response>; | ||
users: (page?: number) => Promise<Response>; | ||
@@ -13,0 +18,0 @@ } |
@@ -54,3 +54,5 @@ var __assign = (this && this.__assign) || function () { | ||
var pathMap = { | ||
deleteInvitation: 'invitations/{{id}}', | ||
invitations: 'invitations/', | ||
updateUserProfile: 'users/{{id}}', | ||
users: 'users/', | ||
@@ -62,3 +64,3 @@ }; | ||
this.jwt = jwt; | ||
this.apiRequest = function (pathKey, errorMessage, requestMethod, queryStringParameters, postData) { return __awaiter(_this, void 0, void 0, function () { | ||
this.apiRequest = function (pathKey, errorMessage, requestMethod, queryStringParameters, body, pathParameters) { return __awaiter(_this, void 0, void 0, function () { | ||
var url, resp; | ||
@@ -68,3 +70,3 @@ return __generator(this, function (_a) { | ||
case 0: | ||
url = "" + this.getURL(pathKey) + (queryStringParameters | ||
url = "" + this.buildPath(this.getURL(pathKey), pathParameters) + (queryStringParameters | ||
? Object.keys(queryStringParameters).reduce(function (acc, key) { return "" + acc + key + "=" + queryStringParameters[key] + "&"; }, '?') | ||
@@ -78,3 +80,3 @@ : ''); | ||
}, | ||
body: JSON.stringify(postData), | ||
body: JSON.stringify(body), | ||
})]; | ||
@@ -99,2 +101,8 @@ case 1: | ||
}; | ||
this.deleteInvitation = function (id) { | ||
return _this.apiRequest('deleteInvitation', "Failed to delete IDM user's invitation", 'DELETE', undefined, undefined, { id: id }); | ||
}; | ||
this.updateUserProfile = function (id, profile) { | ||
return _this.apiRequest('updateUserProfile', "Failed to update IDM user's profile", 'PATCH', undefined, profile, { id: id }); | ||
}; | ||
this.users = function (page) { | ||
@@ -121,2 +129,13 @@ if (page === void 0) { page = 1; } | ||
}; | ||
IDMClient.prototype.buildPath = function (pathTemplate, pathParameters) { | ||
if (!pathParameters) | ||
return pathTemplate; | ||
var re = /{{([A-Za-z]+)}}/; | ||
var path = pathTemplate; | ||
var match; | ||
while ((match = re.exec(path)) !== null) { | ||
path = path.replace(match[0], pathParameters[match[1]]); | ||
} | ||
return path[path.length - 1] === '/' ? path : path + "/"; | ||
}; | ||
return IDMClient; | ||
@@ -123,0 +142,0 @@ }()); |
@@ -9,5 +9,9 @@ import { IIDMClient, IIDMService, IDMUser, CreateUser, CreateInvitation } from './types'; | ||
createUser: (newUser: CreateUser) => Promise<any>; | ||
deleteInvitation: (id: string) => Promise<boolean>; | ||
getAllUsers: () => Promise<IDMUser[]>; | ||
updateUserProfile: (id: string, profile: { | ||
[key: string]: any; | ||
}) => Promise<IDMUser>; | ||
} | ||
export default IDMService; | ||
//# sourceMappingURL=service.d.ts.map |
@@ -84,2 +84,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
}); }; | ||
this.deleteInvitation = function (id) { return __awaiter(_this, void 0, void 0, function () { | ||
var response; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.client.deleteInvitation(id)]; | ||
case 1: | ||
response = _a.sent(); | ||
if (response.ok) | ||
return [2 /*return*/, true]; | ||
return [2 /*return*/, false]; | ||
} | ||
}); | ||
}); }; | ||
this.getAllUsers = function () { return __awaiter(_this, void 0, void 0, function () { | ||
@@ -114,2 +127,16 @@ var response, body, users, nextUrl, pageNumber; | ||
}); }; | ||
this.updateUserProfile = function (id, profile) { return __awaiter(_this, void 0, void 0, function () { | ||
var response, body; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.client.updateUserProfile(id, { profile: profile })]; | ||
case 1: | ||
response = _a.sent(); | ||
return [4 /*yield*/, response.json()]; | ||
case 2: | ||
body = _a.sent(); | ||
return [2 /*return*/, body]; | ||
} | ||
}); | ||
}); }; | ||
if (!client) { | ||
@@ -116,0 +143,0 @@ throw createIDMError('You must provide a pathways admin client'); |
@@ -7,2 +7,6 @@ declare type ISOString = string; | ||
createUser(newUser: CreateUser): Promise<Response>; | ||
deleteInvitation(id: string): Promise<Response>; | ||
updateUserProfile(id: string, profile: { | ||
[key: string]: any; | ||
}): Promise<Response>; | ||
users(page?: number): Promise<Response>; | ||
@@ -13,6 +17,10 @@ } | ||
createUser(newUser: CreateUser): Promise<IDMUser>; | ||
deleteInvitation(id: string): Promise<boolean>; | ||
idm: IIDMClient; | ||
getAllUsers(): Promise<IDMUser[]>; | ||
updateUserProfile(id: string, profile: { | ||
[key: string]: any; | ||
}): Promise<IDMUser>; | ||
} | ||
export declare type MethodType = 'DELETE' | 'GET' | 'PATCH' | 'POST'; | ||
export declare type MethodType = 'DELETE' | 'GET' | 'PATCH' | 'POST' | 'PUT'; | ||
export declare type Options = { | ||
@@ -26,2 +34,3 @@ baseUrl?: string; | ||
email: string; | ||
invitations: string[]; | ||
organisation: string; | ||
@@ -28,0 +37,0 @@ profile: { |
{ | ||
"name": "@liquid-state/idm-client", | ||
"version": "0.0.5", | ||
"version": "0.0.6", | ||
"description": "A client for the idm", | ||
@@ -5,0 +5,0 @@ "files": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
29868
19.11%413
18.34%