Coder Social home page Coder Social logo

replapi-it / replapi.it-nodejs Goto Github PK

View Code? Open in Web Editor NEW
34.0 5.0 1.0 2.61 MB

[DEPRECIATED] ๐™€๐™ซ๐™š๐™ง๐™ฎ๐™ฉ๐™๐™ž๐™ฃ๐™œ ๐™๐™š๐™ฅ๐™ก๐™ž๐™ฉ, ๐™–๐™ก๐™ก ๐™–๐™ฉ ๐™ฎ๐™ค๐™ช๐™ง ๐™™๐™ž๐™จ๐™ฅ๐™ค๐™จ๐™–๐™ก. This is the single most extensive Replit package, allowing you to access various parts of the site with just a few classes and methods. Maintained by @RayhanADev.

License: GNU General Public License v3.0

JavaScript 100.00%
nodejs node-js api-wrapper replit repl-talk graphql api replapi-it package api-package

replapi.it-nodejs's Introduction

โš ๏ธ IMPORTANT: This project has been depreciated. Read more here โš ๏ธ

Contributors Forks Stargazers Issues MIT License Downloads


Logo

ReplAPI.it

A Simple and Complete Replit API Package
Explore the docs ยป

View Package on NPM ยท Report Bug ยท Request Feature

Table of Contents

  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgements

About The Project

Code Screenshot

The Replit GraphQL API is an extraordinary way to make projects unique and special, yet with the numerous packages available few such projects have been made. Why would that be? Most likely due to how complicated writing code can get and the limitations of their queries. My package, ReplAPI.it, changes that with a simple to use structure and many queries, some of which are:

  • Queries for Data on Users (such as Profile, Posts, Comments)
  • Queries for Data on Posts (such as Upvoters, Content)
  • Queries for Data on Repls (such as Files, Comments)
  • Mutations for Commenting, Reporting, and Posting
  • Queries for Data on Leaderboard (with filters such as cycles since)
  • and lots more!

My package is also simple to use with it's class-based structure. Simply create a new class for your User, Post, or whatever your heart desires and use built in functions with options to query data your way.

Built With

Getting Started

I suggest requiring the ReplAPI.it module until ES imports in NodeJS are stabilized.

Prerequisites

If you have not already download npm:

  • npm
    npm install npm@latest -g

Installation

  1. Install the latest version of the package
    $ npm install replapi-it
  2. Require the package in your code
    import ReplAPI from 'replapi-it';
  3. Initilize the package
    const replapi = ReplAPI({
       username: 'your-username-here'
    });

Usage

Using ReplAPI.it is very simple! Let's create a simple user and ask for their cycles:

import ReplAPI from 'replapi-it';
const replapi = ReplAPI({
  username: 'your-username-here'
});

const myUser = new replapi.User("RayhanADev");

async function getCycles() {
  let info = await myUser.userGraphQLDataFull();
  let cycles = info.karma; // Yep, it's karma!
  console.log(`User Cycles: ${cycles}`)
}

getCycles()

Output:

User Cycles: 1008

That was fun! Now how about getting a specific post? Let's create a simple post and ask for it's title:

import ReplAPI from 'replapi-it';
const replapi = ReplAPI({
  username: 'your-username-here'
});

const myPost = new replapi.Post(78043);

async function getTitle() {
  let info = await myPost.postDataFull();
  let title = info.title;
  console.log(`Post Title: ${title}`)
}

getTitle()

Output:

Post Title: Presenting... ๐Ÿค” RayhanADev ๐Ÿค”? (GraphQL Success!)

For more examples, please refer to the Documentation

Roadmap

See the open issues for a list of proposed features (and known issues).

I'm considering adding in support for Crosis communications after they distribute developer keys again. Right now I'm experimenting with WSS and eval.repl.it for code execution!

Contributing

Contributions are much appreciated, and if you have a cool idea that feels right in this package then you should check out our contributing page.

License

Distributed under the GPL-3.0 License. See LICENSE for more information.

Contact

RayhanADev - @RayhanADev - [email protected]

Project Link: https://github.com/ReplAPI-it/ReplAPI.it-NodeJS

Acknowledgements

replapi.it-nodejs's People

Contributors

7ih avatar dependabot[bot] avatar rayhanadev avatar ttury avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

ahmad225

replapi.it-nodejs's Issues

Setup Github Repository

This was one of my first Github Repositories so I did not know any of the tricks and tips I do now. Sometime along the way this Github Repository needs to be setup properly.

Update Repl Class

Add in ReplCommentConnection to retrieve the comments made on a Repl project from the Spotlight screen.

Use Consistent Configuration File Format

Right now we have .---rc's and ---.config.json's and ---.config.js's everywhere and frankly it's a pain. We need to use a consistent file format to maintain our configuration files.

I'm opting with ---.config.cjs since it's most natural.

Upgrade Fetching to HTTPS

Recently Replit blocked off the staging subdomain behind a username-password (htaccess?) and fetching the standard GraphQL endpoint via node-fetch has been blocked by CloudFlare. In search of solutions I tried the top five methods of fetching data:

  1. https native
  2. request (depreciated)
  3. node-fetch (current)
  4. r2
  5. axios

My research has yielded that native https, request, and axios work when fetching and the rest are blocked by CloudFlare. The particulars as to why I have not looked into.

I dropped request because it is depreciated, which leaves native https (headache) and axios.

Switching from node-fetch to axios should not be too hard and a restructuring of the package dogfooding the Custom classes was in order for some time however comparing the sizes of the packages (node-fetch and axios) there seems to be a huge difference. It is also possible to create custom fetching functions optimized for GraphQL while also using the native https package so that is also an option.

TL;DR The options are:

  • Switch everything from node-fetch to axios w/o any changes to the structure
    • Pros
      • ReplAPI.it will work
    • Cons
      • Huge dependencies size
  • Fix up the Custom classes w/ axios and dogfood off that
    • Pros
      • Clean package structure, no excessive codebytes and copy-pasted functions
      • One shot fetch change and then simply change all node-fetch instances to match with Custom class
    • Cons
      • Huge dependencies size
  • Fix up the Custom classes w/ https and dogfood off that
    • Pros
      • Clean package structure, no excessive codebytes and copy-pasted functions
      • One shot fetch change and then simply change all node-fetch instances to match with Custom class
      • No fetching dependencies
    • Cons
      • Messing with the https API is so bad and not human friendly in the least

While I think over these, I'm also open to any other ideas. LMK in the comments.

Implement Code Evaluation

Either in the form of connecting to Crosis or WSS connection to eval.repl.it, implement code evaluation through Repl.it.

Add in Missing Queries and Mutations

This Replit Package is a patchwork of what I found over the past few months, but I recently acquired a slightly older but still working copy of the entire schema, so adding in the missing GraphQL Queries and Mutations are imperative.

Add newRepls Query

Ummm yeah very weird Repl has a newRepls query which shows ALL the new Repls that are created...?


{
  newRepls {
    items {
      slug
    }
  }
}

Response: An array of Repls

{
  "data": {
    "newRepls": {
      "items": [
        {
          "slug": "DESAFIO01AULA01",
          "user": {
            "username": "beatrizol"
          }
        },
        {
          "slug": "surto",
          "user": {
            "username": "MariaEduardaE74"
          }
        },
        {
          "slug": "SurefootedRadiantPriorities",
          "user": {
            "username": "EILEENCHICASGUE"
          }
        },
        {
          "slug": "322-Starting-Code",
          "user": {
            "username": "MckennaJenkins"
          }
        },
        {
          "slug": "Uno",
          "user": {
            "username": "EvelynAlamilla"
          }
        },
        {
          "slug": "PortlyUnsightlyApplicationprogrammer",
          "user": {
            "username": "Yeraldin1621"
          }
        },
        {
          "slug": "FrankUntidyFtpclient",
          "user": {
            "username": "MaximusMottram"
          }
        },
        {
          "slug": "Loops-notes",
          "user": {
            "username": "OliviaJames2"
          }
        },
        {
          "slug": "band-name-generator-end",
          "user": {
            "username": "AndyYao2"
          }
        },
        {
          "slug": "mu2c",
          "user": {
            "username": "whysimp"
          }
        }
      ]
    }
  }
}

Add Queries for Replit Achievement Class

I don't quite know if Replit Achievements went defunct but I know they disappeared. In any case the GraphQL query is apparently still there, so we can use it.


{
  achievements {
    title
    description
  }
}

Returns: List of all Achievements

{
  "data": {
    "achievements": [
      {
        "title": "Mask Off",
        "description": "Change your profile picture and bio"
      },
      {
        "title": "Repl.it Contributor",
        "description": "Submit good posts on Repl Talk"
      },
      {
        "title": "Repl.it Guide",
        "description": "Have your comments be accepted as answers on someone's Repl Talk post"
      },
      {
        "title": "Unstoppable Repler",
        "description": "This is a streak that shows how many days in a row you have coded on Repl.it"
      },
      {
        "title": "Multiplayer",
        "description": "Join some new multiplayer repls and collaborate on coding projects"
      },
      {
        "title": "Repl.it Famous",
        "description": "Have a Repl Talk post trend on the Repl.it home page"
      },
      {
        "title": "1 Year Club",
        "description": "Be an active Repl.it user for over a year"
      }
    ]
  }
}

{
  achievement(id: 1) {
    title
    description
    isLeveled
    level
    showProgressBar
    progressBarStatus
  }
}

Returns: A Specific Achievement

{
  "data": {
    "achievement": {
      "title": "Mask Off",
      "description": "Change your profile picture and bio",
      "isLeveled": false,
      "level": null,
      "showProgressBar": false,
      "progressBarStatus": 100
    }
  }
}

Restructure Package Meta

This issue correlates with the similar project. Tasks include:

  • Redesign the Custom Class to match up with the current design of API Classes
  • Implement lightfetch for HTTPS fetching (#67)
  • Add helper functions to parse custom Objects to GraphQL querystrings
  • Rewrite all API Classes to dogfood the new Custom Class

This will be released as 2.4.x, a minor version and beta releases will be made under 2.4.0-beta.x. As always, help is appreciated!

Edit: I thought a table documenting the current progress might be useful (to me).

Key:

  • โœ”๏ธ: Completed
  • โŒ: Not Started
  • โœ๏ธ: In Progress
Class Name Status
Board โœ”๏ธ
Comment โœ๏ธ
Explore โœ”๏ธ
Leaderboard โŒ
Post โŒ
Repl โŒ
User โŒ

* Note: This chart discludes non-GraphQL related classes that won't be getting structural changes. The Login class has been (yet again) revamped in addition to usage of logged-in queries.

Add Configuration Options

A possible enhancement to the package could be adding config options. This could be implemented by reading a config.json or other supplied file. Some possible options could be:

  • Client Username
  • Client Password
  • Recursive Item Count Returns
  • Replit GraphQL Endpoint

and more ideas are welcome.

[BUG] User is not a constructor

Describe the bug
In the shell I cant use the package because it says that User is not a contructor.
To Reproduce
Steps to reproduce the behavior:

  1. Make a new repl with the cycle code in your readme
  2. Run it

Expected behavior
I wanted it to return my cycle data
Screenshots
image

Desktop (please complete the following information):

  • Chromebook(im usually on mac)
  • Chrome
  • Latest

[BUG] ~ `User` doesn't exist??

Describe the bug
The User class doesn't appear to work, in that it is undefined.

To Reproduce
Steps to reproduce the behaviour:

  1. Create a node script
  2. Install replapi-it
  3. Paste in this script:
const { User } = require("replapi-it");
console.log(`User is ${ User }`);
  1. Logged to console will be "User is undefined"

Expected behaviour
If you were to follow these steps, "[class User]" or similar should be output.

Server

  • OS: GNU/Linux x86-64 Ubuntu 18.04 Bionic
  • Runtime: NodeJS 12.22.1
  • Platform: Replit

Additional context
This seems to be recent, and it comes with a few other problems I've experienced; I was only made aware of these issues yesterday due to error pages on my site.

ReplDB interfacing options for ReplAPI.it

One idea no Replit API package has managed so far (to my knowledge), is an interfacing option with ReplDB. I don't quite mean enveloping the ReplDB package with ReplAPI.it, but rather sending requests to the endpoint.

Ideas:

  • First initialize a ReplDB class, parameter can be to supply the endpoint URL
  • Use the normal functions (set, get, delete, list), just like the current ReplDB package
  • Add more utility functions?

This doesn't do much with just the basic functions and it could possibly be easier for users if there are utilities...

Separate Fixed Queries

Several of the GraphQL Queries have fixed values, such as the amount of voters retrieved from a post or the amount of comments retrieved from a post. This issue highlights separating these Queries and adding more customizability in these values.

[REQUEST] ~ what is the point of the .replapirc file

When I first installed the package, it installed a .replapirc file with some default initiative values. I feel like it would be fine to remove this file since the values are already set when the server starts, unless there's some weird reason.

[BUG] ~ Links

Describe the bug
A wrong link or not updated yet.

To Reproduce
Steps to reproduce the behavior:

  1. Go to 'README.md'
  2. Click on 'Explore the docs ยป'
  3. This doesn't look like the right page

Expected behavior
Documentation on the ReplAPI.it

Desktop (please complete the following information):

  • OS: [e.g. iOS] - macOS Catalina 10.15.7
  • Browser [e.g. chrome, safari] - Google Chrome | 91.0.4472.77ย (Official Build)ย (x86_64)

Add Custom Query Class

Create a new class that allows for the usage of queries or customized versions of queries that are not included in the package. This allows the user to not be limited by the options presented. This would mean creating a sort of interface... JS psuedocode below:

/* Class */

Custom {
  constructor(queryName, query, variables) {
    this.queryName = queryName;
    this.query = query;
    this.variables = variables;
  }
  
  async run() {
    // Add fetch request to https://staging.replit.com/graphql with the query
  }
}

/* User Creating Custom Query */

let queryName = "UserCyclesSince"
let variables = { username: "RayhanADev", since: "PAST_24_HOURS" }
let query = `
  userByUsername(username: $username) {
    karma(since: $since)
  }
`

let myQuery = new KarmaSince extends replapi.Custom() {
  constructor(queryName, query, variables) {
    super(queryName, query, variables)
  }
  // additional user created functions
};

// ... now use the myQuery class for something

Decrease Package Bloat

When I made this package I was quite inexperienced, and truthfully I downloaded whatever I felt like at the moment. Over time this has caused some major package bloat. It has come to the point where ReplAPI.it for NodeJS is 7.05 MB in size, which is... disturbing. To decrease package bloat we could:

  • Remove unnecessary dependencies
  • Homebrew some packages and utilities
  • Use a module bundler, uglifier, and tree-shaker (Rollup is what I had in mind)

I'll fix this in while working on the refactor.

[REQUEST] ~ Autodoc or Full API

Is your feature request related to a problem? Please describe.
I'm (as you probably know) heading the Python version of this project. The docs show the Nextra tutorial and README.md only shows a minimal amount of features.

Describe the solution you'd like
Please update the docs or add autodoc so that I can support all of the features.

Additional context
I'm not very good with Nodejs, so that's why I can't just read the source. Sorry!

Refactor The Package

Right now, users have some customizability, but not as much as you possibly could. Since I want to provide my users the best possible it would be wise to refactor the package to include these changes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.