Skip to content

Latest commit

 

History

History
257 lines (216 loc) · 8.35 KB

README.md

File metadata and controls

257 lines (216 loc) · 8.35 KB

SNEK Logo

SNEK - Social Network for Engineers and Knowledged

The SNEK project is an attempt to create a transparent, open-source non-profit platform that allows engineers to categorize and compare. It should enable engineers from adjacent fields to visualize each other's skills through visualization and project identification.
The client unifies the way external data is handled and unites it under a clean, well documented, modular, plug and play API written in beautiful typescript :)

Report bug · Request feature · Documentation

Table of contents

Installation

The system can be installed using the npm install command:

$ npm install snek-client

Usage

Set up

import SnekClient from "snek-client";

const headers = {}
const type = "testclient"

/* Init snekclient */
const snekclient = new SnekClient(""https://engine.snek.at/api/graphiql", headers, type)

Sessions

Session are completely handled by the Intel.

/* 
 * Starts the session for an anonymous user or maintains the session if
 * a user is logged in.
 */
await snekclient.session.begin();

/*
 * Overrides an active session with a new session using the credential
 * pair.
 */
await snekclient.session.begin({
  username: "schettn",
  password: "tschischkotschicko",
});

/* Ends the session */
await snekclient.session.end();

Tasks

All tasks are session aware! Every task has the capability of token handling. Modifying a token is not suggested.

/** Authorization Tasks */
/* Login an anonymous user on the snek-engine */
let userData =
    await snekclient.session.tasks.auth.anon();

/* Login a real user on the snek-engine */
let userData =
    await snekclient.session.tasks.auth.nonanon();

/* Refresh the user tokens on the snek-engine */
let refreshState =
    await snekclient.session.tasks.auth.refresh();

/* Revoke the user tokens on the snek-engine */
let revokeState =
    await snekclient.session.tasks.auth.revoke();


/** General Tasks */
/* Get all profile pages from snek-engine */
let pagesData =
    await snekclient.session.tasks.general.allPageUrls();

/* Get all GitLab servers from the snek-engine */
let gitlabServerData =
    await snekclient.session.tasks.general.gitlabServer();

/** User Tasks */
/* Get all GitLab servers from the snek-engine */
let cachePageData =
    await snekclient.session.tasks.user.cache();

/* Get the profile page data from the snek-engine */
let profilePageData =
    await snekclient.session.tasks.user.profile();

/* Get the registration data from snek-engine */
let registrationData =
    await snekclient.session.tasks.user.registration();

/* Get the whoami data from snek-engine */
let whoamiData =
    await snekclient.session.tasks.user.whoami();

Custom Tasks

/* 
 * Performs a custom session aware task. Authorization is handled via the session.
 */
await snekclient.session.customTask<{ data: { foo: string; bar: string } }>(
      "query",
      documentNode,
      variables
    );

Extend Project (Add new specific session with template set)

Ref: github.com/snek-at/client/blob/master/src/session/sessions.ts

//> Tasks
// Contains SNEK tasks
import CustomTasks from "../templates/customsnek/gql/tasks/index";

class CustomSession extends CookieSession {
  public tasks = CustomTasks;

  /**
   * Initializes a custom session.
   *
   * @constructor
   * @extends CookieSession Tokens are handled via cookies
   * @author Nico Schett <[email protected]>
   * @param {string} sId A session name
   * @param {Endpoint} ep A endpoint
   * @param {SnekTemplate} template A template set
   */
  constructor(
    sId: string,
    public ep: ApolloEndpoint,
    public template: SnekTemplate
  ) {
    super(sId);

    this.tokenName = sId + "-" + this.tokenName;
    this.refreshTokenName = sId + "-" + this.refreshTokenName;
    this.tasks = new CustomTasks(this);
  }

  //> Methods
}


/* Custom Client */
class CustomClient extends Client {
  gql: ApolloEndpoint;
  template: IMainTemplate;
  session: CustomSession;

  /**
   * Initializes a SNEK client.
   *
   * @constructor
   * @author Nico Schett <[email protected]>
   * @param url The base URL the SnekClient should be working on.
   *            Default: "https://engine.snek.at/api/graphiql".
   * @param headers A object containing various request headers
   * @param type A type description to differ between multiple instances
   */
  constructor(
    url: string = "https://engine.snek.at/api/graphiql",
    headers: object = {},
    type: string = "graphql"
  ) {
    super({ type, url, headers });

    this.template = new MainTemplate();
    this.gql = new Apollo(url, { headers });
    this.session = new CustomSession("snek", this.gql, this.template.snek);
  }
}

Contributing

GitHub last commit GitHub issues GitHub closed issues

Please read through our contributing guidelines. Included are directions for opening issues, coding standards, and notes on development.

All code should conform to the Code Guide, maintained by SNEK.

Bugs and feature requests

Do you have a bug or a feature request? Please first search for existing and closed issues. If your problem or idea has not been addressed yet, please open a new issue.

Versioning

GitHub package.json version

For reasons of transparency concering our release cycle and in striving to maintain backward compatibility, this repository is maintained under the Semantic Versioning guidelines. Some minor screw ups aside, we try to adhere to those rules whenever possible.

Creators

Avatar schettn Avatar pinterid Avatar kleberbaum
Nico Schett David Pinterics Florian Kleber

Thanks

We do not have any external contributors yet, but if you want your name to be here, feel free to contribute to our project.

Copyright and license

GitHub repository license

SPDX-License-Identifier: (EUPL-1.2) Copyright © 2019-2020 Simon Prast