Skip to content

Commit

Permalink
Merge pull request #46 from Butterstroke/development
Browse files Browse the repository at this point in the history
Release 1.11.1
  • Loading branch information
AurelicButter authored Feb 21, 2022
2 parents e9fef2b + 6a72b3d commit bc9c7c1
Show file tree
Hide file tree
Showing 7 changed files with 804 additions and 1,002 deletions.
3 changes: 2 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ utilities/
.gitignore
.prettierignore
.prettierrc.json
token.json
token.json
Jenkinsfile
40 changes: 40 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
pipeline {
agent any

tools { nodejs "Node 16" }

options {
buildDiscarder(logRotator(artifactNumToKeepStr: "5"))
copyArtifactPermission('/*-AniList-Node');
}

stages {
stage('Prepare') {
environment {
projVersion = sh(script: 'npm pkg get version | sed "s/^.//g" | sed "s/.$//"', , returnStdout: true).trim()
gitRevision = '${GIT_REVISION,length=6}'
buildCount = '${BUILD_NUMBER}'
}
steps {
buildName "${projVersion}.${buildCount}.${gitRevision}"
sh 'npm install'
}
}
stage('Test') {
steps {
sh 'npm run eslint'
}
}
stage('Build') {
steps {
sh 'npm run docs'

script {
zip zipFile: "anilist-node-built-${BUILD_NUMBER}.zip", archive: false, dir: 'docs'
}

archiveArtifacts artifacts: "anilist-node-built-${BUILD_NUMBER}.zip", fingerprint: true, followSymlinks: false, onlyIfSuccessful: true
}
}
}
}
19 changes: 9 additions & 10 deletions lib/activity.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,21 @@ class Activity {
* @returns {TextActivity}
* @since 1.11.0
*/
postText(text, id) {
async postText(text, id) {
if (typeof text !== "string") {
throw new Error("Text is not a string type.");
}
if (id && typeof id !== "number") {
throw new Error("Provided ID is not a number type.");
}

const data = this.util.send(
const data = await this.util.send(
`mutation ($id: Int, $text: String) {
SaveTextActivity(id: $id, text: $text) {
${TextActivityQuery}
} }`,
SaveTextActivity(id: $id, text: $text) {
${TextActivityQuery}
} }`,
{ id: id, text: text }
);

return data.SaveTextActivity;
}

Expand All @@ -113,7 +112,7 @@ class Activity {
* @returns {MessageActivity}
* @since 1.11.0
*/
postMessage(text, recipientId, isPrivate = false, id) {
async postMessage(text, recipientId, isPrivate = false, id) {
if (typeof text !== "string") {
throw new Error("Text is not a string type.");
}
Expand All @@ -124,7 +123,7 @@ class Activity {
throw new Error("Provided ID is not a number type.");
}

const data = this.util.send(
const data = await this.util.send(
`mutation ($id: Int, $text: String, $recipientId: Int, $private: Boolean) {
SaveMessageActivity(message: $text, id: $id, recipientId: $recipientId, private: $private) {
${MessageActivityQuery}
Expand All @@ -142,12 +141,12 @@ class Activity {
* @returns {Boolean} Returns true if successful
* @since 1.11.0
*/
delete(id) {
async delete(id) {
if (typeof id !== "number") {
throw new Error("ID is not a number type.");
}

const data = this.util.send(`mutation ($id: Int) { DeleteActivity(id: $id) { deleted } }`, { id: id });
const data = await this.util.send(`mutation ($id: Int) { DeleteActivity(id: $id) { deleted } }`, { id: id });

return data.DeleteActivity.deleted;
}
Expand Down
4 changes: 4 additions & 0 deletions lib/fetcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ module.exports = {
throw new Error("Query or variables are not given!");
}

if (query.startsWith("mutation") && this.key === null) {
throw new Error("Function requires authenciation but no authorization found.");
}

const controller = new AbortController();
const requestTimeout = setTimeout(() => {
controller.abort();
Expand Down
20 changes: 13 additions & 7 deletions lib/user.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
const { UserProfileQuery, UserStatsQuery, UserUpdateQuery } = require("./consts");
const {
UserProfileQuery,
UserStatsQuery,
UserUpdateQuery,
ListActivityQuery,
TextActivityQuery,
MessageActivityQuery
} = require("./consts");

/**
* Access AniList's user data.
Expand Down Expand Up @@ -67,10 +74,9 @@ class User {
`query ($page: Int, $perPage: Int, $user: Int) {
Page (page: $page, perPage: $perPage) { pageInfo { total currentPage lastPage hasNextPage perPage }
activities(userId: $user, sort:ID_DESC) {
... on ListActivity { id status type progress media { id title { romaji english native userPreferred } type }
createdAt likeCount replies { id text likeCount } }
... on TextActivity { id userId type text createdAt likeCount replies { id text likeCount } }
... on MessageActivity { id recipientId type message createdAt likeCount replies { id text likeCount } }
... on ListActivity { ${ListActivityQuery} }
... on TextActivity { ${TextActivityQuery} }
... on MessageActivity { ${MessageActivityQuery} }
} } }`,
{ user: user, page: 1, perPage: 25 }
);
Expand All @@ -97,12 +103,12 @@ class User {
*
* @since 1.10.0
*/
update(options) {
async update(options) {
if (!options || Object.keys(options).length === 0) {
throw new Error("Options were not provided for updating user!");
}

const data = this.util.send(UserUpdateQuery, options);
const data = await this.util.send(UserUpdateQuery, options);
return data.updateUser;
}
}
Expand Down
Loading

0 comments on commit bc9c7c1

Please sign in to comment.