项目作者: branch8

项目描述 :
Lazada Open Platform SDK for Nodejs
高级语言: JavaScript
项目地址: git://github.com/branch8/lazada-open-platform-sdk.git
创建时间: 2018-06-21T17:04:29Z
项目社区:https://github.com/branch8/lazada-open-platform-sdk

开源协议:MIT License

下载


Nodejs wrapper for Lazada Open Platform API

Build Status

| ! WIP project

Usage

  1. Install sdk

    1. [~/project/dir] $ npm install lazada-open-platform-sdk
  2. Require LazadaAPI class

    1. import LazadaAPI from 'lazada-open-platform-sdk'
    2. // OR
    3. const LazadaAPI = require('lazada-open-platform-sdk')
  3. Instantiate a LazadaAPI Object

    1. /**
    2. * LazadaAPI class constructor
    3. * @param {string} appKey
    4. * @param {string} appSecret
    5. * @param {Venture} countryCode @ref: 'src/LazadaClient/constants.js'
    6. * countryCode should be one of the following
    7. * | 'SINGAPORE'
    8. * | 'THAILAND'
    9. * | 'MALAYSIA'
    10. * | 'VIETNAM'
    11. * | 'PHILIPPINES'
    12. * | 'INDONESIA'
    13. * @param {string?} accessToken require for some API
    14. */
    15. const aLazadaAPI = new LazadaAPI(appKey, appSecret, 'SINGAPORE')
    16. // OR
    17. const accessToken = 'some_access_token'
    18. const aLazadaAPIWithToken = new LazadaAPI(appKey, appSecret, 'SINGAPORE', accessToken)
    1. Call API action with proper parameters

      1. // all API action return promise
      2. aLazadaAPI
      3. .generateAccessToken({ code: 'auth_code' })
      4. .then(response => {
      5. const { access_token } = response // JSON data from Lazada's API
      6. })
      7. // for API action that require authorization, you must set the accessToken first
      8. aLazadaAPI.accessToken = 'some_access_token'
      9. aLazadaAPI
      10. .getShipmentProviders()
      11. .then(response => {
      12. // JSON data from Lazada's API
      13. })
    2. For available API actions, check the support table. For proper API request parameters, check Lazada’s offcial documentation and source code located in src/LazadaClient/<namespace>

API Support

Order status
getDocument :heavy_check_mark:
getFailureReasons :heavy_check_mark:
getMultipleOrderItems :heavy_check_mark:
getOrder :heavy_check_mark:
getOrderItems :heavy_check_mark:
getOrders :heavy_check_mark:
setInvoiceNumber :heavy_check_mark:
setStatusToCanceled :heavy_check_mark:
setStatusToPackedByMarketplace :heavy_check_mark:
setStatusToReadyToShip :heavy_check_mark:

Product status
createProduct :heavy_check_mark:
getBrands :heavy_check_mark:
getCategoryAttributes :heavy_check_mark:
getCategoryTree :heavy_check_mark:
getProducts :heavy_check_mark:
getQcStatus :no_entry_sign:
getResponse :no_entry_sign:
migrateImage :heavy_check_mark:
migrateImages :no_entry_sign:
removeProduct :heavy_check_mark:
setImages :heavy_check_mark:
updatePriceQuantity :heavy_check_mark:
updateProduct :heavy_check_mark:
uploadImage :no_entry_sign:

Finance status
getPayoutStatus :no_entry_sign:
getTransactionDetails :no_entry_sign:

Logistics status
getShipmentProviders :heavy_check_mark:

Seller status
getSeller :no_entry_sign:
updateSeller :no_entry_sign:
updateUser :no_entry_sign:

System status
generateAccessToken :heavy_check_mark:
refreshAccessToken :heavy_check_mark:

DataMoat status
dataMoatBatchLog :no_entry_sign:
dataMoatComputeRisk :no_entry_sign:
dataMoatLogin :no_entry_sign:
dataMoatOrder :no_entry_sign:

Development

Tools

  • node - runtime
  • babel - js transpiler
  • flow - type checker
  • jest - test runner
  • eslint - linter
  • vscode - recommended text editor

Convention

  1. sdk variables: camelCase
  2. api variables: snake_case or PascalCase

File structure

  1. src/
  2. ├── LazadaAPI // LazadaAPI: top level controller class
  3. └── index.js
  4. ├── LazadaClient // LazadaClient: namespace seperated API actions
  5. ├── index.js
  6. ├── logistics.js
  7. ├── order.js
  8. ├── product.js
  9. └── system.js
  10. ├── LazadaRequest // LazadaRequest: responsible for network request
  11. ├── index.js
  12. └── signature // logic for signing API request
  13. └── index.js
  14. ├── __tests__ // all tests located here
  15. └── index.js // a.k.a. main.c

Design

  1. const APIRequest = {
  2. appKey: ":require",
  3. appSecret: ":require",
  4. baseURL: ":require" // Protocol (default: https) + Gateway (location specific)
  5. HttpAction: "GET OR POST", // API specific
  6. apiPath: "action/path", // API specific
  7. accessToken: ":optional", // API specific
  8. payload: {} // API specific
  9. };

Reference

Lazada API Doc

https://open.lazada.com/doc/api.htm