npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

aws-scloud

v1.0.10

Published

Fast, security, superpower microservice of aws-scloud

Downloads

41

Readme

AWS-SCloud

Fast, security, superpower microservice of aws-scloud

Installation

You can install this package from npm:

npm install aws-scloud

Or with yarn:

yarn add aws-scloud

Usage

Let's take a look at minimal example:

import {auth, create_kv_store, get_kv_store, update_kv_store, delete_kv_store} from "aws-scloud";

auth("yyyyy","xxxxxxxxx.xxxxxxxx"); // MUST use your server id to replace 'yyyyy' and your api token to replace 'xxxxxxxxx.xxxxxxxx'

create_kv_store("your-key", "your-value")
    .then(res => console.log("Response data: ", res.data))
    .catch(err => console.error("Error: ", err));

get_kv_store("your-key")
    .then(res => console.log("Response data: ", res.data))
    .catch(err => console.error("Error: ", err));

update_kv_store("your-key", "your-new-value")
    .then(res => console.log("Response data: ", res.data))
    .catch(err => console.error("Error: ", err));

delete_kv_store("your-key")
    .then(res => console.log("Response data: ", res.data))
    .catch(err => console.error("Error: ", err));

API

auth(server,token) -> void

Use this function tell the library your api-token and it will be used in the following APIs.
NOTE: You MUST use this function before all others!
Financial: This function will NOT consume your money

  • server: string
    Your server id from the service provider.
  • token: string
    Your api key get from the service provider.

create_kv_store(key, value) -> Promise

Create a key-value pair in the cloud-server. If successful, in the response data, you can check the 'result' field which is marked as 'success', else it will raise an exception.
Financial: This function will consume your money

  • key: string
  • value: string

get_kv_store(key) -> Promise

Get a value assigned to the key from the cloud-server. If successful, in the response data, you can check the 'result' field which is marked as 'success' and get the value from 'value' field, else it will raise an exception.
Financial: This function will consume your money

  • key: string

update_kv_store(key, value) -> Promise

Update a value assigned to the key in the cloud-server. If successful, in the response data, you can check the 'result' field which is marked as 'success', else it will raise an exception.
Financial: This function will consume your money

  • key: string
  • value: string

delete_kv_store(key) -> Promise

Delete a key-value pair in the cloud-server. If successful, in the response data, you can check the 'result' field which is marked as 'success', else it will raise an exception.
Financial: This function will consume your money

  • key: string

create_customer(nickname, username, password, gender, external_id) -> Promise

Create a customer account which can be used to get some news in your cloud account. If successful, in the response data, you can check the 'result' field which is marked as 'success' and get the customer id from 'new-customer-id' field, else it will raise an exception.
Financial: This function will NOT consume your money

  • nickname: string
  • username: string
    The username MUST unique in your cloud account range
  • password: string
  • gender: string
    This field must be set, since the server will push some news by gender
  • external_id: string
    This field is optional, you can use it by your definition, else set this field as empty string("")

customer_login(username, password) -> Promise

Make the user login to your cloud account. If successful, you can get your api-token in 'owner_token' field and get the customer id in the 'customer_id' field from the response data, else it will raise an exception.
Financial: This function will NOT consume your money

  • username: string
  • password: string

get_news_for_customer(customer_id) -> Promise

Get some recommended and hot news for the customer. If successful, you can get a list of newses that contains 5 newses at least and each of that contains 'artical_id', 'title', 'summary' and 'content_link' of the news and all the types of these are strings, else it will raise an exception.
Financial: This function will consume your money

  • customer_id: string

set_artical_watchtime(customer_id, artical_id, start_at, duration, like, dislike) -> Promise

To improve the recommend accuracy, you should tell the cloud server your customer's hobby use this function. If successful, in the response data, you can check the 'result' field which is marked as 'success', else it will raise an exception.
Financial: This function will NOT consume your money

  • customer_id: string
  • artical_id: string
  • start_at: string
    The time point of the user read this artical. You MUST use the ISO-8601 format to present the time, or just call the helper function 'get_current_time_point()' to simplify your work.
  • duration: integer
    millisecond(ms)
  • like: boolean
    Whether or not the customer like this artical
  • dislike: boolean
    Whether or not the customer dislike this artical NOTE: If the customer not mention whether or not he or she like this artical, please mark both of 'like' and 'dislike' field as 'false'

post_artical_comment(artical_id, customer_id, comment, need_anonymous) -> Promise

Publish comment for the artical by the customer. If successful, in the response data, you can check the 'result' field which is marked as 'success', else it will raise an exception.
Financial: This function will NOT consume your money

  • artical_id: string
  • customer_id: string
  • comment: string
  • need_anonymous: boolean

toggle_customer_support(comment_id, customer_id) -> Promise

Wheher or not the user support the comment. When the user have already supported the comment, use this function means that the user don't support the comment anyway, and vice versa. Financial: This function will NOT consume your money

  • comment_id: string
  • customer_id: string

get_artical_comments(artical_id) -> Promise

Fetch the artical' comments, include the information of publisher and all customers who support it. If successful, in the response data, you will get a GetArticalComment object with some fields include: customer, artical_id, comment, time, comment_id, support_by_customers and etc, see below for details. Financial: This function will NOT consume your money

  • artical_id: string

Response Data

interface CommentCustomer{
    nickname: string;
    customer_id: string;
}

interface GetArticalComment{
    customer: CommentCustomer;
    artical_id: string;
    comment: string;
    time: datetime;
    comment_id: string;
    support_count: number;
} 

Response Schema

The response for a request contains the following information.

{
  // `data` is the response that was provided by the server
  // you can use this field to get the result
  data: {},

  // `status` is the HTTP status code from the server response
  status: 200,

  // `statusText` is the HTTP status message from the server response
  statusText: 'OK',

  // `headers` the HTTP headers that the server responded with
  // All header names are lower cased and can be accessed using the bracket notation.
  // Example: `response.headers['content-type']`
  headers: {},

  // `config` is the config that was provided to `axios` for the request
  config: {},

  // `request` is the request that generated this response
  // It is the last ClientRequest instance in node.js (in redirects)
  // and an XMLHttpRequest instance in the browser
  request: {}
}

When using then, you will receive the response as follows:

get_kv_store("your-key")
    .then(function (response) {
        console.log(response.data.action);
        console.log(response.data.key);
        console.log(response.data.value);
        console.log(response.data.result);

        console.log(response.status);
        console.log(response.statusText);
        console.log(response.headers);
        console.log(response.config);
  });

When using catch, or passing a rejection callback as second parameter of then, the response will be available through the error object as explained in the following Handling Errors section.

Handling Errors

get_kv_store("your-key")
  .catch(function (error) {
    if (error.response) {
      // The request was made and the server responded with a status code
      // that falls out of the range of 2xx
      console.log(error.response.data);
      console.log(error.response.status);
      console.log(error.response.headers);
    } else if (error.request) {
      // The request was made but no response was received
      // `error.request` is an instance of XMLHttpRequest in the browser and an instance of
      // http.ClientRequest in node.js
      console.log(error.request);
    } else {
      // Something happened in setting up the request that triggered an Error
      console.log('Error', error.message);
    }
    console.log(error.config);
  });

Using toJSON you get an object with more information about the HTTP error.

get_kv_store("your-key")
  .catch(function (error) {
    console.log(error.toJSON());
  });