1.0.10 • Published 4 years ago

aws-scloud v1.0.10

Weekly downloads
-
License
ISC
Repository
-
Last release
4 years ago

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.
```javascript
{
  // `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());
  });
1.0.10

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.5

4 years ago

1.0.4

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago