Comparing version 0.1.1-alpha to 0.2.0-alpha
@@ -5,2 +5,4 @@ "use strict"; | ||
class AttachmentBuilder { | ||
file; | ||
resource; | ||
constructor(data) { | ||
@@ -7,0 +9,0 @@ this.file = data?.file ?? ""; |
@@ -5,2 +5,4 @@ "use strict"; | ||
class CategoryBuilder { | ||
name; | ||
isVisible; | ||
constructor(data) { | ||
@@ -7,0 +9,0 @@ this.name = data?.name ?? ""; |
@@ -6,3 +6,3 @@ import Resource from "../class/Resource"; | ||
} | ||
/** Represents a comment in in a resource */ | ||
/** Represents a comment in a resource */ | ||
export default class CommentBuilder implements CommentDataBuilder { | ||
@@ -9,0 +9,0 @@ comment: string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** Represents a comment in in a resource */ | ||
/** Represents a comment in a resource */ | ||
class CommentBuilder { | ||
comment; | ||
resource; | ||
constructor(data) { | ||
@@ -6,0 +8,0 @@ this.comment = data?.comment ?? ""; |
@@ -5,6 +5,6 @@ import Category from "../class/Category"; | ||
title: string; | ||
isPublic: boolean; | ||
description: string | null; | ||
isPublic: boolean; | ||
categories: Category[]; | ||
attachments: AttachmentBuilder[]; | ||
categories: Category[]; | ||
} | ||
@@ -14,4 +14,4 @@ /** Represents a resource */ | ||
title: string; | ||
isPublic: boolean; | ||
description: string | null; | ||
isPublic: boolean; | ||
attachments: AttachmentBuilder[]; | ||
@@ -18,0 +18,0 @@ categories: Category[]; |
@@ -5,8 +5,13 @@ "use strict"; | ||
class ResourceBuilder { | ||
title; | ||
isPublic; | ||
description; | ||
attachments; | ||
categories; | ||
constructor(data) { | ||
this.title = data?.title ?? ""; | ||
this.isPublic = data?.isPublic ?? false; | ||
this.description = data?.description ?? null; | ||
this.isPublic = data?.isPublic ?? false; | ||
this.categories = data?.categories ?? []; | ||
this.attachments = data?.attachments ?? []; | ||
this.categories = data?.categories ?? []; | ||
} | ||
@@ -13,0 +18,0 @@ setTitle(title) { |
export interface UserDataBuilder { | ||
name: string; | ||
email: string; | ||
password: string; | ||
name: string; | ||
firstname: string; | ||
@@ -9,5 +9,5 @@ } | ||
export default class UserBuilder implements UserDataBuilder { | ||
name: string; | ||
email: string; | ||
password: string; | ||
name: string; | ||
firstname: string; | ||
@@ -14,0 +14,0 @@ constructor(data?: Partial<UserDataBuilder>); |
@@ -5,6 +5,10 @@ "use strict"; | ||
class UserBuilder { | ||
name; | ||
email; | ||
password; | ||
firstname; | ||
constructor(data) { | ||
this.name = data?.name ?? ""; | ||
this.email = data?.email ?? ""; | ||
this.password = data?.password ?? ""; | ||
this.name = data?.name ?? ""; | ||
this.firstname = data?.firstname ?? ""; | ||
@@ -11,0 +15,0 @@ } |
import User from "../class/User"; | ||
export type State = "pending" | "validated" | "rejected"; | ||
export declare enum State { | ||
Pending = "pending", | ||
Validated = "validated", | ||
Rejected = "rejected" | ||
} | ||
export interface ValidStateDataBuilder { | ||
@@ -4,0 +8,0 @@ state: State; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.State = void 0; | ||
var State; | ||
(function (State) { | ||
State["Pending"] = "pending"; | ||
State["Validated"] = "validated"; | ||
State["Rejected"] = "rejected"; | ||
})(State = exports.State || (exports.State = {})); | ||
/** Represents a valid state */ | ||
class ValidStateBuilder { | ||
state; | ||
moderator; | ||
constructor(data) { | ||
this.state = data?.state ?? "pending"; | ||
this.state = data?.state ?? State.Pending; | ||
this.moderator = data?.moderator; | ||
@@ -8,0 +17,0 @@ } |
@@ -7,14 +7,12 @@ import User from "./User"; | ||
id: string; | ||
type: string; | ||
fileUrl: string; | ||
fileName: string; | ||
type: string; | ||
createdAt: string; | ||
isDeleted: boolean; | ||
} | ||
export default class Attachment extends Base { | ||
fileUrl: string; | ||
type: string; | ||
fileName: string; | ||
type: string; | ||
createdAt: Date; | ||
isDeleted: boolean; | ||
user: User | null; | ||
@@ -28,4 +26,3 @@ resource: Resource; | ||
ressource: string; | ||
isDeleted: boolean; | ||
}; | ||
} |
@@ -6,9 +6,14 @@ "use strict"; | ||
class Attachment extends Base_1.default { | ||
fileUrl; | ||
type; | ||
fileName; | ||
createdAt; | ||
user; | ||
resource; | ||
constructor(client, resource, user, data) { | ||
super(client, data.id, "/attachments"); | ||
this.fileUrl = data.fileUrl, | ||
this.fileName = data.fileName, | ||
this.type = data.type; | ||
this.createdAt = new Date(data.createdAt), | ||
this.isDeleted = data.isDeleted; | ||
this.fileUrl = data.fileUrl; | ||
this.type = data.type; | ||
this.fileName = data.fileName; | ||
this.createdAt = new Date(data.createdAt); | ||
this.user = user; | ||
@@ -23,3 +28,2 @@ this.resource = resource; | ||
ressource: this.resource.getIri(), | ||
isDeleted: this.isDeleted, | ||
}; | ||
@@ -26,0 +30,0 @@ } |
import Client from "../client/Client"; | ||
export default class Base { | ||
id: string; | ||
client: Client; | ||
id: string; | ||
private path; | ||
@@ -6,0 +6,0 @@ constructor(client: Client, id: string, path: string); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
class Base { | ||
id; | ||
client; | ||
path; | ||
constructor(client, id, path) { | ||
this.id = id; | ||
this.client = client; | ||
this.id = id; | ||
this.path = path; | ||
@@ -8,0 +11,0 @@ } |
@@ -12,3 +12,2 @@ import { Collection } from "@discordjs/collection"; | ||
updatedAt: string | null; | ||
isDeleted: boolean; | ||
creator: Partial<UserData> | null; | ||
@@ -21,3 +20,2 @@ } | ||
updatedAt: Date | null; | ||
isDeleted: boolean; | ||
creator: User | null; | ||
@@ -32,4 +30,3 @@ resources: Collection<string, Resource>; | ||
isVisible: boolean; | ||
isDeleted: boolean; | ||
}; | ||
} |
@@ -6,2 +6,8 @@ "use strict"; | ||
class Category extends Base_1.default { | ||
name; | ||
isVisible; | ||
createdAt; | ||
updatedAt; | ||
creator; | ||
resources; | ||
constructor(client, data) { | ||
@@ -13,3 +19,2 @@ super(client, data?.id, "/categories"); | ||
this.updatedAt = data.updatedAt ? new Date(data.updatedAt) : null; | ||
this.isDeleted = data.isDeleted; | ||
this.creator = this.getCreator(data?.creator?.id); | ||
@@ -24,6 +29,5 @@ this.resources = this.client.resources.cache.filter(r => r.categories.has(this.id)); | ||
return { | ||
id: this.name, | ||
id: this.id, | ||
name: this.name, | ||
isVisible: this.isVisible, | ||
isDeleted: this.isDeleted, | ||
}; | ||
@@ -30,0 +34,0 @@ } |
@@ -9,3 +9,3 @@ import Base from "./Base"; | ||
createdAt: string; | ||
isDeleted: boolean; | ||
updatedAt: string | null; | ||
} | ||
@@ -15,3 +15,3 @@ export default class Comment extends Base { | ||
createdAt: Date; | ||
isDeleted: boolean; | ||
updatedAt: Date | null; | ||
resource: Resource; | ||
@@ -24,4 +24,3 @@ user: User | null; | ||
comment: string; | ||
isDeleted: boolean; | ||
}; | ||
} |
@@ -6,2 +6,7 @@ "use strict"; | ||
class Comment extends Base_1.default { | ||
comment; | ||
createdAt; | ||
updatedAt; | ||
resource; | ||
user; | ||
constructor(client, resource, user, data) { | ||
@@ -13,3 +18,3 @@ super(client, data.id, "/comments"); | ||
this.createdAt = new Date(data.createdAt), | ||
this.isDeleted = data.isDeleted; | ||
this.updatedAt = data.updatedAt ? new Date(data.updatedAt) : null; | ||
} | ||
@@ -21,3 +26,2 @@ /** Return data for api request */ | ||
comment: this.comment, | ||
isDeleted: this.isDeleted, | ||
}; | ||
@@ -24,0 +28,0 @@ } |
@@ -15,5 +15,4 @@ import { Collection } from "@discordjs/collection"; | ||
createdAt: string; | ||
updatedAt: string; | ||
updatedAt: string | null; | ||
isPublic: boolean; | ||
isDeleted: boolean; | ||
user: Partial<UserData> | null; | ||
@@ -29,3 +28,2 @@ attachments: AttachmentData[]; | ||
updatedAt: Date | null; | ||
isDeleted: boolean; | ||
isPublic: boolean; | ||
@@ -57,5 +55,4 @@ user: User | null; | ||
isPublic: boolean; | ||
isDeleted: boolean; | ||
categories: string[]; | ||
}; | ||
} |
@@ -10,9 +10,17 @@ "use strict"; | ||
class Resource extends Base_1.default { | ||
title; | ||
description; | ||
createdAt; | ||
updatedAt; | ||
isPublic; | ||
user; | ||
attachments; | ||
categories; | ||
comments; | ||
constructor(client, data) { | ||
super(client, data.id, "/resources"); | ||
this.title = data.title, | ||
this.description = data.description, | ||
this.createdAt = new Date(data.createdAt), | ||
this.updatedAt = data.updatedAt ? new Date(data.updatedAt) : null, | ||
this.isDeleted = data.isDeleted; | ||
this.title = data.title; | ||
this.description = data.description; | ||
this.createdAt = new Date(data.createdAt); | ||
this.updatedAt = data.updatedAt ? new Date(data.updatedAt) : null; | ||
this.isPublic = data.isPublic; | ||
@@ -90,3 +98,2 @@ this.user = this.getCreator(data.user?.id); | ||
isPublic: this.isPublic, | ||
isDeleted: this.isDeleted, | ||
categories: Array.from(this.categories.keys()), | ||
@@ -93,0 +100,0 @@ }; |
@@ -12,4 +12,3 @@ import { Collection } from "@discordjs/collection"; | ||
createdAt: string; | ||
updatedAt: string; | ||
isBanned: boolean; | ||
updatedAt: string | null; | ||
} | ||
@@ -22,4 +21,3 @@ export default class User extends Base { | ||
createdAt: Date; | ||
updatedAt: Date; | ||
isBanned: boolean; | ||
updatedAt: Date | null; | ||
resources: Collection<string, Resource>; | ||
@@ -26,0 +24,0 @@ constructor(client: Client, data: UserData); |
@@ -6,2 +6,9 @@ "use strict"; | ||
class User extends Base_1.default { | ||
email; | ||
roles; | ||
name; | ||
firstname; | ||
createdAt; | ||
updatedAt; | ||
resources; | ||
constructor(client, data) { | ||
@@ -13,5 +20,4 @@ super(client, data.id, "/users"); | ||
this.firstname = data.firstname; | ||
this.createdAt = data.createdAt ? new Date(data.createdAt) : new Date(); | ||
this.createdAt = new Date(data.createdAt); | ||
this.updatedAt = data.updatedAt ? new Date(data.updatedAt) : new Date(); | ||
this.isBanned = data.isBanned || false; | ||
this.resources = this.client.resources.cache.filter(r => r.user?.id === this.id); | ||
@@ -18,0 +24,0 @@ } |
@@ -10,2 +10,12 @@ "use strict"; | ||
class Auth { | ||
client; | ||
/** | ||
* User currently logged in or null if no one | ||
* has logged in with their account | ||
*/ | ||
me; | ||
/** Token of user connected */ | ||
token; | ||
/** Refresh token of user connected */ | ||
refresh_token; | ||
constructor(client) { | ||
@@ -12,0 +22,0 @@ this.client = client; |
@@ -26,2 +26,4 @@ import { CreateAxiosDefaults } from "axios"; | ||
constructor(config?: Partial<ClientConfig>); | ||
/** Login user with username and password */ | ||
login(username: string, password: string): Promise<import("./Auth").LoginResponse>; | ||
} |
@@ -14,2 +14,10 @@ "use strict"; | ||
class Client { | ||
auth; | ||
rest; | ||
/** Users manager for this client */ | ||
users; | ||
/** Categories manager for this client */ | ||
categories; | ||
/** Ressources manager for this client */ | ||
resources; | ||
constructor(config) { | ||
@@ -22,4 +30,8 @@ this.rest = new REST_1.default(this, config); | ||
} | ||
/** Login user with username and password */ | ||
async login(username, password) { | ||
return this.auth.login(username, password); | ||
} | ||
} | ||
exports.default = Client; | ||
//# sourceMappingURL=Client.js.map |
import { CreateAxiosDefaults } from 'axios'; | ||
import Client from './Client'; | ||
export type RequestMethod = "GET" | "POST" | "PUT" | "DELETE"; | ||
export declare enum RequestMethod { | ||
Get = "GET", | ||
Post = "POST", | ||
Put = "PUT", | ||
Delete = "Delete" | ||
} | ||
export interface RequestConfig { | ||
@@ -5,0 +10,0 @@ method: RequestMethod; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.RequestMethod = void 0; | ||
const tslib_1 = require("tslib"); | ||
const axios_1 = tslib_1.__importDefault(require("axios")); | ||
var RequestMethod; | ||
(function (RequestMethod) { | ||
RequestMethod["Get"] = "GET"; | ||
RequestMethod["Post"] = "POST"; | ||
RequestMethod["Put"] = "PUT"; | ||
RequestMethod["Delete"] = "Delete"; | ||
})(RequestMethod = exports.RequestMethod || (exports.RequestMethod = {})); | ||
; | ||
/** | ||
@@ -10,2 +19,4 @@ * REST client for the lib | ||
class REST { | ||
client; | ||
instance; | ||
constructor(client, RESTConfig) { | ||
@@ -42,3 +53,3 @@ this.instance = axios_1.default.create({ | ||
return this.sendRequest(url, { | ||
method: "GET", | ||
method: RequestMethod.Get, | ||
waitedStatus: 200, | ||
@@ -50,3 +61,3 @@ needAuth, | ||
return this.sendRequest(url, { | ||
method: "POST", | ||
method: RequestMethod.Post, | ||
waitedStatus, | ||
@@ -59,3 +70,3 @@ needAuth, | ||
return this.sendRequest(url, { | ||
method: "PUT", | ||
method: RequestMethod.Put, | ||
waitedStatus: 200, | ||
@@ -68,4 +79,4 @@ needAuth: true, | ||
return this.sendRequest(url, { | ||
method: "DELETE", | ||
waitedStatus: 2004, | ||
method: RequestMethod.Delete, | ||
waitedStatus: 204, | ||
needAuth: true, | ||
@@ -72,0 +83,0 @@ }); |
@@ -18,1 +18,2 @@ export { default as Client, ClientConfig } from './client/Client'; | ||
export { default as User, UserData } from "./class/User"; | ||
export { default as ValidationState, ValidationStateData } from "./class/ValidationState"; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.User = exports.Resource = exports.Comment = exports.Category = exports.Attachment = exports.ValidStateBuilder = exports.UserBuilder = exports.RessourceBuilder = exports.CommentBuilder = exports.CategoryBuilder = exports.AttachmentBuilder = exports.UserManager = exports.ResourceManager = exports.CategoryManager = exports.REST = exports.Auth = exports.Client = void 0; | ||
exports.ValidationState = exports.User = exports.Resource = exports.Comment = exports.Category = exports.Attachment = exports.State = exports.ValidStateBuilder = exports.UserBuilder = exports.RessourceBuilder = exports.CommentBuilder = exports.CategoryBuilder = exports.AttachmentBuilder = exports.UserManager = exports.ResourceManager = exports.CategoryManager = exports.RequestMethod = exports.REST = exports.Auth = exports.Client = void 0; | ||
// Export Clients | ||
@@ -11,2 +11,3 @@ var Client_1 = require("./client/Client"); | ||
Object.defineProperty(exports, "REST", { enumerable: true, get: function () { return __importDefault(REST_1).default; } }); | ||
Object.defineProperty(exports, "RequestMethod", { enumerable: true, get: function () { return REST_1.RequestMethod; } }); | ||
// Managers | ||
@@ -32,2 +33,3 @@ var CategoryManager_1 = require("./managers/CategoryManager"); | ||
Object.defineProperty(exports, "ValidStateBuilder", { enumerable: true, get: function () { return __importDefault(ValidStateBuilder_1).default; } }); | ||
Object.defineProperty(exports, "State", { enumerable: true, get: function () { return ValidStateBuilder_1.State; } }); | ||
// Class | ||
@@ -44,3 +46,4 @@ var Attachment_1 = require("./class/Attachment"); | ||
Object.defineProperty(exports, "User", { enumerable: true, get: function () { return __importDefault(User_1).default; } }); | ||
// export { default as ValidState } from "./class/ValidState"; | ||
var ValidationState_1 = require("./class/ValidationState"); | ||
Object.defineProperty(exports, "ValidationState", { enumerable: true, get: function () { return __importDefault(ValidationState_1).default; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -13,3 +13,3 @@ import { Collection } from "@discordjs/collection"; | ||
private buildCache; | ||
/** Fetch all existing users from the api */ | ||
/** Fetch all existing categories from the api */ | ||
fetchAll(): Promise<Category[]>; | ||
@@ -16,0 +16,0 @@ /** Fetch one category with an id from the api */ |
@@ -9,2 +9,5 @@ "use strict"; | ||
class CategoryManager { | ||
client; | ||
/** Categories cache */ | ||
cache; | ||
constructor(client) { | ||
@@ -25,3 +28,3 @@ this.client = client; | ||
} | ||
/** Fetch all existing users from the api */ | ||
/** Fetch all existing categories from the api */ | ||
async fetchAll() { | ||
@@ -28,0 +31,0 @@ const data = await this.client.rest.getRequest("/categories"); |
@@ -9,2 +9,5 @@ "use strict"; | ||
class ResourceManager { | ||
client; | ||
/** Resource cache */ | ||
cache; | ||
constructor(client) { | ||
@@ -11,0 +14,0 @@ this.client = client; |
@@ -9,2 +9,5 @@ "use strict"; | ||
class UserManager { | ||
client; | ||
/** Users caches */ | ||
cache; | ||
constructor(client) { | ||
@@ -11,0 +14,0 @@ this.client = client; |
{ | ||
"name": "rr-apilib", | ||
"version": "0.1.1-alpha", | ||
"version": "0.2.0-alpha", | ||
"description": "Library for interact with RR-API", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
# rr-apilib | ||
<p> | ||
<a href="https://www.npmjs.com/package/rr-apilib"><img src="https://img.shields.io/npm/v/rr-apilib.svg?maxAge=3600" alt="npm version" /></a> | ||
<a href="https://github.com/cesi-pedoncule/RR-Lib/actions"><img src="https://github.com/cesi-pedoncule/RR-Lib/actions/workflows/codeql.yml/badge.svg" alt="CodeQL" /></a> | ||
<a href="https://www.npmjs.com/package/rr-apilib"><img src="https://img.shields.io/npm/v/rr-apilib.svg?maxAge=3600" alt="NPM Version" /></a> | ||
</p> | ||
@@ -18,30 +19,31 @@ | ||
```javascript | ||
const { Client, CommentBuilder } = require("rr-apilib"); | ||
import { Client, CommentBuilder } from "rr-apilib"; | ||
(async () => { | ||
// Declare the client and login the user | ||
const client = new Client(); | ||
await client.auth.login("me@mail.com", "password"); | ||
// Declare the client and login the user | ||
const client = new Client(); | ||
await client.login("me@mail.com", "password"); | ||
// Get an existing ressource in cache with id | ||
const resource = client.resources.cache.get("uuid"); | ||
console.log(resource); | ||
// Get an existing ressource in cache with id | ||
const resource = client.resources.cache.get("uuid"); | ||
console.log(resource); | ||
// Create new Comment | ||
const newComment = new CommentBuilder() | ||
.setComment(":D"); | ||
// Create new Comment | ||
const newComment = new CommentBuilder() | ||
.setComment(":D"); | ||
// POST the new comment in API | ||
await ressource.addComment(newComment); | ||
// POST the new comment in API | ||
await ressource.addComment(newComment); | ||
// Log ressource comments | ||
console.log(ressource.comments); | ||
// Log ressource comments | ||
console.log(ressource.comments); | ||
})(); | ||
``` | ||
## Documentation | ||
Documentation available soon... | ||
## Links | ||
[Github](https://github.com/cesi-pedoncule/RR-Lib) | ||
[Documentation](https://cesi-pedoncule.github.io/RR-Lib/) | ||
## Contact | ||
- Discord [Horziox#0007](https://discord.com/users/340212760870649866) |
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
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
99805
64
1376
48