Comparing version 0.2.7-alpha to 0.3.0-alpha
@@ -5,9 +5,7 @@ import User from "./User"; | ||
import Client from "../client/Client"; | ||
export interface AttachmentData { | ||
id: string; | ||
type: string; | ||
fileUrl: string; | ||
fileName: string; | ||
createdAt: string; | ||
} | ||
import { APIResourceAttachmentData } from "../@types"; | ||
/** | ||
* Represents an attachment | ||
* WARNING: You can't upload a real file yet | ||
*/ | ||
export default class Attachment extends Base { | ||
@@ -18,5 +16,7 @@ fileUrl: string; | ||
createdAt: Date; | ||
/** User who have create this attachment */ | ||
user: User | null; | ||
/** Resource of this attachment */ | ||
resource: Resource; | ||
constructor(client: Client, resource: Resource, user: User | null, data: AttachmentData); | ||
constructor(client: Client, resource: Resource, user: User | null, data: APIResourceAttachmentData); | ||
/** Return data for api request */ | ||
@@ -23,0 +23,0 @@ toJSON(): { |
import { __extends } from "tslib"; | ||
import Base from "./Base"; | ||
/** | ||
* Represents an attachment | ||
* WARNING: You can't upload a real file yet | ||
*/ | ||
var Attachment = /** @class */ (function (_super) { | ||
@@ -4,0 +8,0 @@ __extends(Attachment, _super); |
@@ -5,3 +5,3 @@ import Client from "../client/Client"; | ||
client: Client; | ||
private path; | ||
path: string; | ||
constructor(client: Client, id: string, path: string); | ||
@@ -8,0 +8,0 @@ /** Return the iri of element */ |
@@ -1,22 +0,21 @@ | ||
import { Collection } from "@discordjs/collection"; | ||
import User from "./User"; | ||
import Base from "./Base"; | ||
import Resource from "./Resource"; | ||
import Client from "../client/Client"; | ||
import User, { UserData } from "./User"; | ||
export interface CategoryData { | ||
id: string; | ||
name: string; | ||
isVisible: boolean; | ||
createdAt: string; | ||
updatedAt: string | null; | ||
creator: Partial<UserData> | null; | ||
} | ||
import { APICategoryData } from "../@types"; | ||
import CategoryResourceManager from "../managers/CategoryResourceManager"; | ||
/** Represents an category */ | ||
export default class Category extends Base { | ||
/** Name of this category */ | ||
name: string; | ||
/** Visiblity of this category */ | ||
isVisible: boolean; | ||
/** Creation date */ | ||
createdAt: Date; | ||
/** Updated date */ | ||
updatedAt: Date | null; | ||
/** User have created this category */ | ||
creator: User | null; | ||
resources: Collection<string, Resource>; | ||
constructor(client: Client, data: CategoryData); | ||
/** Linked resource */ | ||
resources: CategoryResourceManager; | ||
constructor(client: Client, data: APICategoryData); | ||
private getCreator; | ||
@@ -23,0 +22,0 @@ /** Return data for api request */ |
import { __extends } from "tslib"; | ||
import Base from "./Base"; | ||
import CategoryResourceManager from "../managers/CategoryResourceManager"; | ||
/** Represents an category */ | ||
var Category = /** @class */ (function (_super) { | ||
@@ -14,3 +16,3 @@ __extends(Category, _super); | ||
_this.creator = _this.getCreator((_a = data === null || data === void 0 ? void 0 : data.creator) === null || _a === void 0 ? void 0 : _a.id); | ||
_this.resources = _this.client.resources.cache.filter(function (r) { return r.categories.has(_this.id); }); | ||
_this.resources = new CategoryResourceManager(_this); | ||
return _this; | ||
@@ -17,0 +19,0 @@ } |
@@ -5,15 +5,14 @@ import Base from "./Base"; | ||
import Client from "../client/Client"; | ||
export interface CommentData { | ||
id: string; | ||
comment: string; | ||
createdAt: string; | ||
updatedAt: string | null; | ||
} | ||
import { APIResourceCommentData } from "../@types"; | ||
/** Represents an resource comment */ | ||
export default class Comment extends Base { | ||
/** Message of the user */ | ||
comment: string; | ||
/** Creation date */ | ||
createdAt: Date; | ||
updatedAt: Date | null; | ||
/** Linked resource */ | ||
resource: Resource; | ||
/** Creator of this comment */ | ||
user: User | null; | ||
constructor(client: Client, resource: Resource, user: User | null, data: CommentData); | ||
constructor(client: Client, resource: Resource, data: APIResourceCommentData); | ||
/** Return data for api request */ | ||
@@ -20,0 +19,0 @@ toJSON(): { |
import { __extends } from "tslib"; | ||
import Base from "./Base"; | ||
/** Represents an resource comment */ | ||
var Comment = /** @class */ (function (_super) { | ||
__extends(Comment, _super); | ||
function Comment(client, resource, user, data) { | ||
var _this = _super.call(this, client, data.id, "/comments") || this; | ||
function Comment(client, resource, data) { | ||
var _this = this; | ||
var _a, _b; | ||
_this = _super.call(this, client, data.id, "/comments") || this; | ||
_this.resource = resource; | ||
_this.user = user; | ||
_this.comment = data.comment, | ||
_this.createdAt = new Date(data.createdAt), | ||
_this.updatedAt = data.updatedAt ? new Date(data.updatedAt) : null; | ||
_this.user = data.user ? (_b = _this.client.users.cache.get((_a = data.user) === null || _a === void 0 ? void 0 : _a.id)) !== null && _b !== void 0 ? _b : null : null; | ||
_this.comment = data.comment; | ||
_this.createdAt = new Date(data.createdAt); | ||
return _this; | ||
@@ -13,0 +15,0 @@ } |
@@ -1,47 +0,40 @@ | ||
import { Collection } from "@discordjs/collection"; | ||
import CommentBuilder from "../builders/CommentBuilder"; | ||
import AttachmentBuilder from "../builders/AttachmentBuilder"; | ||
import { APIResourceData } from "../@types"; | ||
import Base from "./Base"; | ||
import User from "./User"; | ||
import Client from "../client/Client"; | ||
import User, { UserData } from "./User"; | ||
import Comment, { CommentData } from "./Comment"; | ||
import Category, { CategoryData } from "./Category"; | ||
import Attachment, { AttachmentData } from "./Attachment"; | ||
export interface ResourceData { | ||
id: string; | ||
title: string; | ||
description: string; | ||
createdAt: string; | ||
updatedAt: string | null; | ||
isPublic: boolean; | ||
user: Partial<UserData> | null; | ||
attachments: AttachmentData[]; | ||
categories: CategoryData[]; | ||
comments: CommentData[]; | ||
} | ||
import ResourceAttachmentManager from "../managers/ResourceAttachmentManager"; | ||
import ResourceCategoryManager from "../managers/ResourceCategoryManager"; | ||
import ResourceCommentManager from "../managers/ResourceCommentManager"; | ||
import ResourceLikeManager from "../managers/ResourceLikeManager"; | ||
import ResourceValidationStateManager from "../managers/ResourceValidationStateManager"; | ||
/** Represents an resource */ | ||
export default class Resource extends Base { | ||
/** The resource's title */ | ||
title: string; | ||
/** The resource's description */ | ||
description: string | null; | ||
/** Creation date */ | ||
createdAt: Date; | ||
/** Last updated date */ | ||
updatedAt: Date | null; | ||
/** Privacy of this resource */ | ||
isPublic: boolean; | ||
/**Resource's creator */ | ||
user: User | null; | ||
attachments: Collection<string, Attachment>; | ||
categories: Collection<string, Category>; | ||
comments: Collection<string, Comment>; | ||
constructor(client: Client, data: ResourceData); | ||
/** Resource's attachments manager */ | ||
attachments: ResourceAttachmentManager; | ||
/** Resource's categories manager */ | ||
categories: ResourceCategoryManager; | ||
/** Resource's comments manager */ | ||
comments: ResourceCommentManager; | ||
/** Resource's likes manager */ | ||
likes: ResourceLikeManager; | ||
/** Resource's validation state manager */ | ||
validations: ResourceValidationStateManager; | ||
constructor(client: Client, data: APIResourceData); | ||
private getCreator; | ||
private buildAttachCollection; | ||
private buildCategoriesCollection; | ||
private buildCommentCollection; | ||
/** Upload a new attachment for this resource */ | ||
addNewAttachement(data: AttachmentBuilder): Promise<this>; | ||
/** Delete a attachment for this resource */ | ||
deleteAttachement(attachment: Attachment): Promise<this>; | ||
/** Upload a new comment for this resource */ | ||
addComment(data: CommentBuilder): Promise<this>; | ||
/** Delete a comment for this resource */ | ||
deleteComment(comment: Comment): Promise<this>; | ||
/** Update the categories for this resource */ | ||
setCategories(categories: Collection<string, Category>): Promise<this>; | ||
private getYourLike; | ||
hasLike(): boolean; | ||
like(): void; | ||
unlike(): void; | ||
/** Return data for api request */ | ||
@@ -48,0 +41,0 @@ toJSON(): { |
@@ -1,7 +0,10 @@ | ||
import { __awaiter, __extends, __generator } from "tslib"; | ||
import { Collection } from "@discordjs/collection"; | ||
import { __extends } from "tslib"; | ||
import Base from "./Base"; | ||
import Comment from "./Comment"; | ||
import Category from "./Category"; | ||
import Attachment from "./Attachment"; | ||
import UserLikeBuilder from "../builders/UserLikeBuilder"; | ||
import ResourceAttachmentManager from "../managers/ResourceAttachmentManager"; | ||
import ResourceCategoryManager from "../managers/ResourceCategoryManager"; | ||
import ResourceCommentManager from "../managers/ResourceCommentManager"; | ||
import ResourceLikeManager from "../managers/ResourceLikeManager"; | ||
import ResourceValidationStateManager from "../managers/ResourceValidationStateManager"; | ||
/** Represents an resource */ | ||
var Resource = /** @class */ (function (_super) { | ||
@@ -19,5 +22,7 @@ __extends(Resource, _super); | ||
_this.user = _this.getCreator((_a = data.user) === null || _a === void 0 ? void 0 : _a.id); | ||
_this.attachments = _this.buildAttachCollection(data.attachments); | ||
_this.categories = _this.buildCategoriesCollection(data.categories); | ||
_this.comments = _this.buildCommentCollection(data.comments); | ||
_this.attachments = new ResourceAttachmentManager(_this, data.attachments); | ||
_this.categories = new ResourceCategoryManager(_this); | ||
_this.comments = new ResourceCommentManager(_this, data.comments); | ||
_this.likes = new ResourceLikeManager(_this, data.userLikes); | ||
_this.validations = new ResourceValidationStateManager(_this); | ||
return _this; | ||
@@ -29,107 +34,30 @@ } | ||
}; | ||
Resource.prototype.buildAttachCollection = function (attachments) { | ||
var collection = new Collection(); | ||
for (var _i = 0, attachments_1 = attachments; _i < attachments_1.length; _i++) { | ||
var a = attachments_1[_i]; | ||
collection.set(a.id, new Attachment(this.client, this, this.user, a)); | ||
Resource.prototype.getYourLike = function () { | ||
var _this = this; | ||
if (this.client.auth.me) { | ||
var me = this.likes.cache.find(function (l) { var _a, _b; return ((_a = l.user) === null || _a === void 0 ? void 0 : _a.id) === ((_b = _this.client.auth.me) === null || _b === void 0 ? void 0 : _b.id); }); | ||
if (me) { | ||
return me; | ||
} | ||
} | ||
return collection; | ||
return null; | ||
}; | ||
Resource.prototype.buildCategoriesCollection = function (categories) { | ||
var collection = new Collection(); | ||
for (var _i = 0, categories_1 = categories; _i < categories_1.length; _i++) { | ||
var a = categories_1[_i]; | ||
collection.set(a.id, new Category(this.client, a)); | ||
/* Check if the current user like this resource */ | ||
Resource.prototype.hasLike = function () { | ||
return this.getYourLike() ? true : false; | ||
}; | ||
/* Current user like this resource */ | ||
Resource.prototype.like = function () { | ||
var me = this.client.auth.me; | ||
if (me) { | ||
this.likes.add(new UserLikeBuilder().setUser(me)); | ||
} | ||
return collection; | ||
}; | ||
Resource.prototype.buildCommentCollection = function (comments) { | ||
var collection = new Collection(); | ||
for (var _i = 0, comments_1 = comments; _i < comments_1.length; _i++) { | ||
var c = comments_1[_i]; | ||
collection.set(c.id, new Comment(this.client, this, this.user, c)); | ||
/* Current user unlike this resource */ | ||
Resource.prototype.unlike = function () { | ||
var l = this.getYourLike(); | ||
if (l) { | ||
this.likes.remove(l); | ||
} | ||
return collection; | ||
}; | ||
/** Upload a new attachment for this resource */ | ||
Resource.prototype.addNewAttachement = function (data) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var json, attachData, attachment; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
json = data.setRessource(this).toJSON(); | ||
return [4 /*yield*/, this.client.rest.postRequest("/attachments/resource", json)]; | ||
case 1: | ||
attachData = _a.sent(); | ||
attachment = new Attachment(this.client, this, this.client.auth.me, attachData); | ||
this.attachments.set(attachment.id, attachment); | ||
return [2 /*return*/, this]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** Delete a attachment for this resource */ | ||
Resource.prototype.deleteAttachement = function (attachment) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.client.rest.deleteRequest("/attachments/".concat(attachment.id))]; | ||
case 1: | ||
_a.sent(); | ||
this.attachments.delete(attachment.id); | ||
return [2 /*return*/, this]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** Upload a new comment for this resource */ | ||
Resource.prototype.addComment = function (data) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var json, commentData, comment; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
json = data.setRessource(this).toJSON(); | ||
return [4 /*yield*/, this.client.rest.postRequest("/comments", json)]; | ||
case 1: | ||
commentData = _a.sent(); | ||
comment = new Comment(this.client, this, this.client.auth.me, commentData); | ||
this.comments.set(comment.id, comment); | ||
return [2 /*return*/, this]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** Delete a comment for this resource */ | ||
Resource.prototype.deleteComment = function (comment) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.client.rest.deleteRequest("/comments/".concat(comment.id))]; | ||
case 1: | ||
_a.sent(); | ||
this.comments.delete(comment.id); | ||
return [2 /*return*/, this]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** Update the categories for this resource */ | ||
Resource.prototype.setCategories = function (categories) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var json; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
this.categories = categories; | ||
json = this.toJSON(); | ||
return [4 /*yield*/, this.client.rest.putRequest("/ressources/".concat(this.id), json)]; | ||
case 1: | ||
_a.sent(); | ||
return [2 /*return*/, this]; | ||
} | ||
}); | ||
}); | ||
}; | ||
/** Return data for api request */ | ||
@@ -142,3 +70,3 @@ Resource.prototype.toJSON = function () { | ||
isPublic: this.isPublic, | ||
categories: Array.from(this.categories.keys()), | ||
categories: Array.from(this.categories.cache.keys()), | ||
}; | ||
@@ -145,0 +73,0 @@ }; |
@@ -1,23 +0,22 @@ | ||
import { Collection } from "@discordjs/collection"; | ||
import Base from "./Base"; | ||
import Resource from "./Resource"; | ||
import Client from "../client/Client"; | ||
export interface UserData { | ||
id: string; | ||
email: string; | ||
roles: string[]; | ||
name: string; | ||
firstname: string; | ||
createdAt: string; | ||
updatedAt: string | null; | ||
} | ||
import UserResourceManager from "../managers/UserResourceManager"; | ||
import { APIUserData, APIUserRole } from "../@types"; | ||
/** Represents an user */ | ||
export default class User extends Base { | ||
/** User's email */ | ||
email: string; | ||
roles: string[]; | ||
/** User's roles */ | ||
roles: APIUserRole[]; | ||
/** User's name */ | ||
name: string; | ||
/** User's firstname */ | ||
firstname: string; | ||
/** Creation date of the account */ | ||
createdAt: Date; | ||
/** Last updated datel */ | ||
updatedAt: Date | null; | ||
resources: Collection<string, Resource>; | ||
constructor(client: Client, data: UserData); | ||
/** Resources manager for this user */ | ||
resources: UserResourceManager; | ||
constructor(client: Client, data: APIUserData); | ||
/** Return data for api request */ | ||
@@ -24,0 +23,0 @@ toJSON(): { |
import { __extends } from "tslib"; | ||
import Base from "./Base"; | ||
import UserResourceManager from "../managers/UserResourceManager"; | ||
/** Represents an user */ | ||
var User = /** @class */ (function (_super) { | ||
@@ -13,3 +15,3 @@ __extends(User, _super); | ||
_this.updatedAt = data.updatedAt ? new Date(data.updatedAt) : new Date(); | ||
_this.resources = _this.client.resources.cache.filter(function (r) { var _a; return ((_a = r.user) === null || _a === void 0 ? void 0 : _a.id) === _this.id; }); | ||
_this.resources = new UserResourceManager(_this); | ||
return _this; | ||
@@ -16,0 +18,0 @@ } |
@@ -1,17 +0,17 @@ | ||
import User, { UserData } from "./User"; | ||
import { State } from "../builders/ValidStateBuilder"; | ||
import User from "./User"; | ||
import Base from "./Base"; | ||
import Client from "../client/Client"; | ||
export interface ValidationStateData { | ||
id: string; | ||
state: State; | ||
updatedAt: string | null; | ||
moderator: Partial<UserData> | null; | ||
} | ||
import { APIValidationState, APIValidationStateData } from "../@types"; | ||
import Resource from "./Resource"; | ||
/** Represents an validation state for a resource */ | ||
export default class ValidationState extends Base { | ||
id: string; | ||
state: State; | ||
/** Value of the state */ | ||
state: APIValidationState; | ||
/** Las update */ | ||
updatedAt: Date | null; | ||
/** User who intervened */ | ||
moderator: User | null; | ||
constructor(client: Client, data: ValidationStateData); | ||
/** The linked resource */ | ||
resource: Resource | null; | ||
constructor(client: Client, data: APIValidationStateData); | ||
private getModerator; | ||
@@ -21,4 +21,4 @@ /** Return data for api request */ | ||
id: string; | ||
state: State; | ||
state: APIValidationState; | ||
}; | ||
} |
import { __extends } from "tslib"; | ||
import Base from "./Base"; | ||
/** Represents an validation state for a resource */ | ||
var ValidationState = /** @class */ (function (_super) { | ||
@@ -7,8 +8,8 @@ __extends(ValidationState, _super); | ||
var _this = this; | ||
var _a; | ||
var _a, _b, _c; | ||
_this = _super.call(this, client, data.id, "/validation_states") || this; | ||
_this.id = data.id; | ||
_this.state = data.state; | ||
_this.updatedAt = data.updatedAt ? new Date(data.updatedAt) : null; | ||
_this.moderator = _this.getModerator((_a = data.moderator) === null || _a === void 0 ? void 0 : _a.id); | ||
_this.resource = ((_b = data.resource) === null || _b === void 0 ? void 0 : _b.id) ? (_c = _this.client.resources.cache.get(data.resource.id)) !== null && _c !== void 0 ? _c : null : null; | ||
return _this; | ||
@@ -15,0 +16,0 @@ } |
@@ -22,4 +22,7 @@ import User from "../class/User"; | ||
refresh_token: string | null; | ||
private refreshInterval; | ||
constructor(client: Client); | ||
private getCurrentUser; | ||
private startRefreshInterval; | ||
private clearRefreshInterval; | ||
/** Throw error if user is not connected (for protected routes) */ | ||
@@ -29,2 +32,4 @@ checkAuth(): void; | ||
login(username: string, password: string): Promise<LoginResponse>; | ||
/** Logout the user from the client */ | ||
logout(): void; | ||
/** | ||
@@ -31,0 +36,0 @@ * Refresh auth and get new tokens |
@@ -13,2 +13,3 @@ import { __awaiter, __generator } from "tslib"; | ||
this.refresh_token = null; | ||
this.refreshInterval = null; | ||
} | ||
@@ -28,2 +29,12 @@ Auth.prototype.getCurrentUser = function () { | ||
}; | ||
Auth.prototype.startRefreshInterval = function () { | ||
var _this = this; | ||
this.refreshInterval = setInterval(function () { return _this.refresh(); }, 36e5); | ||
}; | ||
Auth.prototype.clearRefreshInterval = function () { | ||
if (this.refreshInterval) { | ||
clearInterval(this.refreshInterval); | ||
} | ||
this.refreshInterval = null; | ||
}; | ||
/** Throw error if user is not connected (for protected routes) */ | ||
@@ -45,5 +56,7 @@ Auth.prototype.checkAuth = function () { | ||
token = data.token, refresh_token = data.refresh_token; | ||
this.clearRefreshInterval(); | ||
this.token = token; | ||
this.refresh_token = refresh_token; | ||
this.client.rest.setToken(this.token); | ||
this.startRefreshInterval(); | ||
_a = this; | ||
@@ -59,2 +72,10 @@ return [4 /*yield*/, this.getCurrentUser()]; | ||
}; | ||
/** Logout the user from the client */ | ||
Auth.prototype.logout = function () { | ||
this.me = null; | ||
this.token = null; | ||
this.refresh_token = null; | ||
this.client.rest.removeToken(); | ||
this.clearRefreshInterval(); | ||
}; | ||
/** | ||
@@ -75,5 +96,7 @@ * Refresh auth and get new tokens | ||
token = data.token, refresh_token = data.refresh_token; | ||
this.clearRefreshInterval(); | ||
this.token = token; | ||
this.refresh_token = refresh_token; | ||
this.client.rest.setToken(this.token); | ||
this.startRefreshInterval(); | ||
_a = this; | ||
@@ -80,0 +103,0 @@ return [4 /*yield*/, this.getCurrentUser()]; |
@@ -7,2 +7,3 @@ import { CreateAxiosDefaults } from "axios"; | ||
import ResourceManager from "../managers/ResourceManager"; | ||
import ValidationStateManager from "../managers/ValidationStateManager"; | ||
/** Client configuration object */ | ||
@@ -26,2 +27,4 @@ export interface ClientConfig extends CreateAxiosDefaults { | ||
resources: ResourceManager; | ||
/** Validations manager for this client */ | ||
validations: ValidationStateManager; | ||
constructor(config?: Partial<ClientConfig>); | ||
@@ -28,0 +31,0 @@ /** Login user with username and password */ |
@@ -7,2 +7,3 @@ import { __awaiter, __generator } from "tslib"; | ||
import ResourceManager from "../managers/ResourceManager"; | ||
import ValidationStateManager from "../managers/ValidationStateManager"; | ||
/** | ||
@@ -17,2 +18,3 @@ * Main client of the lib. | ||
this.categories = new CategoryManager(this); | ||
this.validations = new ValidationStateManager(this); | ||
this.resources = new ResourceManager(this); | ||
@@ -32,2 +34,3 @@ this.users = new UserManager(this); | ||
this.categories = new CategoryManager(this); | ||
this.validations = new ValidationStateManager(this); | ||
this.resources = new ResourceManager(this); | ||
@@ -34,0 +37,0 @@ this.users = new UserManager(this); |
@@ -25,7 +25,13 @@ import { CreateAxiosDefaults } from 'axios'; | ||
setToken(token: string): void; | ||
/** Remove token in Authorization header */ | ||
removeToken(): void; | ||
private sendRequest; | ||
/** Send a get request to the API */ | ||
getRequest(url: string, needAuth?: boolean): Promise<any>; | ||
/** Send a post request to the API */ | ||
postRequest(url: string, data: object, needAuth?: boolean, waitedStatus?: number): Promise<any>; | ||
/** Send a put request to the API */ | ||
putRequest(url: string, data: object): Promise<any>; | ||
/** Send a delete request to the API */ | ||
deleteRequest(url: string): Promise<any>; | ||
} |
@@ -17,3 +17,3 @@ import { __assign, __awaiter, __generator } from "tslib"; | ||
function REST(client, RESTConfig) { | ||
this.instance = axios.create(__assign({ baseURL: "https://rr-api.aymeric-cucherousset.fr" }, RESTConfig)); | ||
this.instance = axios.create(__assign({ baseURL: "https://api.ressourcesrelationnelles.social" }, RESTConfig)); | ||
this.client = client; | ||
@@ -25,2 +25,6 @@ } | ||
}; | ||
/** Remove token in Authorization header */ | ||
REST.prototype.removeToken = function () { | ||
delete this.instance.defaults.headers["Authorization"]; | ||
}; | ||
REST.prototype.sendRequest = function (url, config) { | ||
@@ -53,2 +57,3 @@ return __awaiter(this, void 0, void 0, function () { | ||
}; | ||
/** Send a get request to the API */ | ||
REST.prototype.getRequest = function (url, needAuth) { | ||
@@ -66,2 +71,3 @@ if (needAuth === void 0) { needAuth = false; } | ||
}; | ||
/** Send a post request to the API */ | ||
REST.prototype.postRequest = function (url, data, needAuth, waitedStatus) { | ||
@@ -81,2 +87,3 @@ if (needAuth === void 0) { needAuth = true; } | ||
}; | ||
/** Send a put request to the API */ | ||
REST.prototype.putRequest = function (url, data) { | ||
@@ -94,2 +101,3 @@ return __awaiter(this, void 0, void 0, function () { | ||
}; | ||
/** Send a delete request to the API */ | ||
REST.prototype.deleteRequest = function (url) { | ||
@@ -96,0 +104,0 @@ return __awaiter(this, void 0, void 0, function () { |
export { default as Client, ClientConfig } from './client/Client'; | ||
export { default as Auth, LoginResponse } from "./client/Auth"; | ||
export { default as REST, RequestConfig, RequestMethod } from "./client/REST"; | ||
export { default as BaseManager } from "./managers/BaseManager"; | ||
export { default as CategoryManager } from "./managers/CategoryManager"; | ||
export { default as CategoryResourceManager } from "./managers/CategoryResourceManager"; | ||
export { default as ResourceManager } from "./managers/ResourceManager"; | ||
export { default as ResourceAttachmentManager } from "./managers/ResourceAttachmentManager"; | ||
export { default as ResourceCategoryManager } from "./managers/ResourceCategoryManager"; | ||
export { default as ResourceCommentManager } from "./managers/ResourceCommentManager"; | ||
export { default as ResourceUserLikeManager } from "./managers/ResourceLikeManager"; | ||
export { default as ResourceValidationStateManager } from "./managers/ResourceValidationStateManager"; | ||
export { default as UserManager } from "./managers/UserManager"; | ||
export { default as UserResourceManager } from "./managers/UserResourceManager"; | ||
export { default as ValidationStateManager } from "./managers/ValidationStateManager"; | ||
export { default as AttachmentBuilder, AttachmentDataBuilder } from "./builders/AttachmentBuilder"; | ||
export { default as CategoryBuilder, CategoryDataBuilder } from "./builders/CategoryBuilder"; | ||
export { default as CommentBuilder, CommentDataBuilder } from "./builders/CommentBuilder"; | ||
export { default as RessourceBuilder, ResourceDataBuilder } from "./builders/ResourceBuilder"; | ||
export { default as ResourceBuilder, ResourceDataBuilder } from "./builders/ResourceBuilder"; | ||
export { default as UserBuilder, UserDataBuilder } from "./builders/UserBuilder"; | ||
export { default as ValidStateBuilder, ValidStateDataBuilder, State } from "./builders/ValidStateBuilder"; | ||
export { default as Attachment, AttachmentData } from "./class/Attachment"; | ||
export { default as Category, CategoryData } from "./class/Category"; | ||
export { default as Comment, CommentData } from "./class/Comment"; | ||
export { default as Resource, ResourceData } from "./class/Resource"; | ||
export { default as User, UserData } from "./class/User"; | ||
export { default as ValidationState, ValidationStateData } from "./class/ValidationState"; | ||
export { default as UserLikeBuilder, UserLikeDataBuilder } from "./builders/UserLikeBuilder"; | ||
export { default as ValidationStateBuilder, ValidationStateDataBuilder } from "./builders/ValidationStateBuilder"; | ||
export { default as Attachment } from "./class/Attachment"; | ||
export { default as Base } from "./class/Base"; | ||
export { default as Category } from "./class/Category"; | ||
export { default as Comment } from "./class/Comment"; | ||
export { default as Resource } from "./class/Resource"; | ||
export { default as User } from "./class/User"; | ||
export { default as UserLike } from "./class/UserLike"; | ||
export { default as ValidationState } from "./class/ValidationState"; | ||
export * from "./@types"; |
@@ -6,5 +6,14 @@ // Export Clients | ||
// Managers | ||
export { default as BaseManager } from "./managers/BaseManager"; | ||
export { default as CategoryManager } from "./managers/CategoryManager"; | ||
export { default as CategoryResourceManager } from "./managers/CategoryResourceManager"; | ||
export { default as ResourceManager } from "./managers/ResourceManager"; | ||
export { default as ResourceAttachmentManager } from "./managers/ResourceAttachmentManager"; | ||
export { default as ResourceCategoryManager } from "./managers/ResourceCategoryManager"; | ||
export { default as ResourceCommentManager } from "./managers/ResourceCommentManager"; | ||
export { default as ResourceUserLikeManager } from "./managers/ResourceLikeManager"; | ||
export { default as ResourceValidationStateManager } from "./managers/ResourceValidationStateManager"; | ||
export { default as UserManager } from "./managers/UserManager"; | ||
export { default as UserResourceManager } from "./managers/UserResourceManager"; | ||
export { default as ValidationStateManager } from "./managers/ValidationStateManager"; | ||
// Builders | ||
@@ -14,7 +23,9 @@ export { default as AttachmentBuilder } from "./builders/AttachmentBuilder"; | ||
export { default as CommentBuilder } from "./builders/CommentBuilder"; | ||
export { default as RessourceBuilder } from "./builders/ResourceBuilder"; | ||
export { default as ResourceBuilder } from "./builders/ResourceBuilder"; | ||
export { default as UserBuilder } from "./builders/UserBuilder"; | ||
export { default as ValidStateBuilder, State } from "./builders/ValidStateBuilder"; | ||
export { default as UserLikeBuilder } from "./builders/UserLikeBuilder"; | ||
export { default as ValidationStateBuilder } from "./builders/ValidationStateBuilder"; | ||
// Class | ||
export { default as Attachment } from "./class/Attachment"; | ||
export { default as Base } from "./class/Base"; | ||
export { default as Category } from "./class/Category"; | ||
@@ -24,3 +35,6 @@ export { default as Comment } from "./class/Comment"; | ||
export { default as User } from "./class/User"; | ||
export { default as UserLike } from "./class/UserLike"; | ||
export { default as ValidationState } from "./class/ValidationState"; | ||
// Types | ||
export * from "./@types"; | ||
//# sourceMappingURL=index.js.map |
import { Collection } from "@discordjs/collection"; | ||
import Client from "../client/Client"; | ||
import BaseManager from "./BaseManager"; | ||
import Category from "../class/Category"; | ||
import CategoryBuilder from "../builders/CategoryBuilder"; | ||
import Category from "../class/Category"; | ||
/** Category manager which allow to manipulate | ||
* the categories in the api */ | ||
export default class CategoryManager { | ||
private client; | ||
export default class CategoryManager extends BaseManager { | ||
/** Categories cache */ | ||
@@ -10,0 +10,0 @@ cache: Collection<string, Category>; |
@@ -1,10 +0,13 @@ | ||
import { __awaiter, __generator } from "tslib"; | ||
import { __awaiter, __extends, __generator } from "tslib"; | ||
import { Collection } from "@discordjs/collection"; | ||
import BaseManager from "./BaseManager"; | ||
import Category from "../class/Category"; | ||
/** Category manager which allow to manipulate | ||
* the categories in the api */ | ||
var CategoryManager = /** @class */ (function () { | ||
var CategoryManager = /** @class */ (function (_super) { | ||
__extends(CategoryManager, _super); | ||
function CategoryManager(client) { | ||
this.client = client; | ||
this.cache = this.buildCache(); | ||
var _this = _super.call(this, client) || this; | ||
_this.cache = _this.buildCache(); | ||
return _this; | ||
} | ||
@@ -95,4 +98,4 @@ CategoryManager.prototype.buildCache = function () { | ||
return CategoryManager; | ||
}()); | ||
}(BaseManager)); | ||
export default CategoryManager; | ||
//# sourceMappingURL=CategoryManager.js.map |
import { Collection } from "@discordjs/collection"; | ||
import Client from "../client/Client"; | ||
import BaseManager from "./BaseManager"; | ||
import Resource from "../class/Resource"; | ||
import ResourceBuilder from "../builders/ResourceBuilder"; | ||
import Resource from "../class/Resource"; | ||
/** Resource manager which allow to manipulate | ||
* the resources in the api */ | ||
export default class ResourceManager { | ||
private client; | ||
export default class ResourceManager extends BaseManager { | ||
/** Resource cache */ | ||
@@ -10,0 +10,0 @@ cache: Collection<string, Resource>; |
@@ -1,10 +0,13 @@ | ||
import { __awaiter, __generator } from "tslib"; | ||
import { __awaiter, __extends, __generator } from "tslib"; | ||
import { Collection } from "@discordjs/collection"; | ||
import BaseManager from "./BaseManager"; | ||
import Resource from "../class/Resource"; | ||
/** Resource manager which allow to manipulate | ||
* the resources in the api */ | ||
var ResourceManager = /** @class */ (function () { | ||
var ResourceManager = /** @class */ (function (_super) { | ||
__extends(ResourceManager, _super); | ||
function ResourceManager(client) { | ||
this.client = client; | ||
this.cache = this.buildCache(); | ||
var _this = _super.call(this, client) || this; | ||
_this.cache = _this.buildCache(); | ||
return _this; | ||
} | ||
@@ -95,4 +98,4 @@ ResourceManager.prototype.buildCache = function () { | ||
return ResourceManager; | ||
}()); | ||
}(BaseManager)); | ||
export default ResourceManager; | ||
//# sourceMappingURL=ResourceManager.js.map |
import { Collection } from "@discordjs/collection"; | ||
import User from "../class/User"; | ||
import Client from "../client/Client"; | ||
import User from "../class/User"; | ||
import BaseManager from "./BaseManager"; | ||
import UserBuilder from "../builders/UserBuilder"; | ||
/** User manager which allow to manipulate | ||
* the users in the api */ | ||
export default class UserManager { | ||
private client; | ||
export default class UserManager extends BaseManager { | ||
/** Users caches */ | ||
@@ -10,0 +10,0 @@ cache: Collection<string, User>; |
@@ -1,10 +0,13 @@ | ||
import { __awaiter, __generator } from "tslib"; | ||
import { __awaiter, __extends, __generator } from "tslib"; | ||
import { Collection } from "@discordjs/collection"; | ||
import User from "../class/User"; | ||
import BaseManager from "./BaseManager"; | ||
/** User manager which allow to manipulate | ||
* the users in the api */ | ||
var UserManager = /** @class */ (function () { | ||
var UserManager = /** @class */ (function (_super) { | ||
__extends(UserManager, _super); | ||
function UserManager(client) { | ||
this.client = client; | ||
this.cache = this.buildCache(); | ||
var _this = _super.call(this, client) || this; | ||
_this.cache = _this.buildCache(); | ||
return _this; | ||
} | ||
@@ -95,4 +98,4 @@ UserManager.prototype.buildCache = function () { | ||
return UserManager; | ||
}()); | ||
}(BaseManager)); | ||
export default UserManager; | ||
//# sourceMappingURL=UserManager.js.map |
{ | ||
"name": "rr-apilib", | ||
"version": "0.2.7-alpha", | ||
"version": "0.3.0-alpha", | ||
"description": "Library for interact with RR-API", | ||
@@ -30,2 +30,2 @@ "main": "lib/index.js", | ||
] | ||
} | ||
} |
@@ -36,3 +36,3 @@ # rr-apilib | ||
// POST the new comment in API | ||
await ressource.addComment(newComment); | ||
await ressource.comments.add(newComment); | ||
@@ -39,0 +39,0 @@ // Log ressource comments |
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
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
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
158504
103
2245