Comparing version
# ae_sdk | ||
## 0.4.14 | ||
### Patch Changes | ||
- ## Documentation | ||
- Write a simple documentation for basic usage | ||
## Other | ||
- Refactor some code for aesthtics | ||
- Add initial unit tests | ||
## 0.4.13 | ||
@@ -4,0 +17,0 @@ |
@@ -12,4 +12,2 @@ type AE_API_NAMES = DS_API_NAMES | AFFILIATE_API_NAMES | SYSTEM_API_NAMES; | ||
* @param {String} timestamp Indicates the time stamp in the format of yyyy-MM-dd HH:mm:ss and in the time zone of GMT+8. For example, 2016-01-01 12:00:00. The Taobao API server allows a maximum time error of 10 minutes for a request from a client. | ||
* @param {String} format Indicates the response format. The default value is xml. The value can be set to xml or json. | ||
* @param {String} v Indicates the API protocol version. The value can be set to 2.0. | ||
* @param {Boolean} simplify Indicates whether the simplified JSON return format is used. This parameter is valid only if format is set to json. The default value is false. | ||
@@ -44,10 +42,3 @@ * @param {String} sign_method Indicates the signature digest algorithm. The value can be set to hmac or md5. | ||
session: string; | ||
url?: string; | ||
/** | ||
* @param {String} format Indicates the response format. The default value is xml. The value can be set to xml or json. | ||
* @default json | ||
*/ | ||
format?: AE_Response_Format; | ||
} | ||
type AE_Response_Format = "xml" | "json"; | ||
type AliexpressMethod<T extends AE_API_NAMES> = T extends "/auth/token/security/create" ? { | ||
@@ -639,3 +630,3 @@ method: T; | ||
/** @description image name in fileserver,max size 100 KB */ | ||
image_file_bytes: Uint8Array; | ||
image_file_bytes: string; | ||
} | ||
@@ -1186,6 +1177,5 @@ interface DS_Image_Search_Result { | ||
readonly session: string; | ||
readonly url: string; | ||
readonly format: AE_Response_Format; | ||
readonly migrated_apis_url = "https://api-sg.aliexpress.com/sync"; | ||
readonly new_apis_url = "https://api-sg.aliexpress.com/rest"; | ||
protected readonly format = "json"; | ||
protected readonly migrated_apis_url = "https://api-sg.aliexpress.com/sync"; | ||
protected readonly new_apis_url = "https://api-sg.aliexpress.com/rest"; | ||
protected readonly sign_method = "sha256"; | ||
@@ -1192,0 +1182,0 @@ constructor(init: AE_Base_Client); |
@@ -81,13 +81,24 @@ "use strict"; | ||
var import_crypto = require("crypto"); | ||
// src/constants.ts | ||
var AE_TOP_API_URL = "https://api-sg.aliexpress.com/sync"; | ||
var AE_OP_API_URL = "https://api-sg.aliexpress.com/rest"; | ||
var SIGN_METHOD = "sha256"; | ||
var SIGN_METHOD_ENCODING = "utf-8"; | ||
var RESPONSE_FORMAT = "json"; | ||
var API_RESPONSE_MESSAGE = { | ||
BAD_REQUEST: "Bad request.", | ||
INTERNAL_ERROR: "Internal error." | ||
}; | ||
// src/utils/client.ts | ||
var AEBaseClient = class { | ||
constructor(init) { | ||
this.migrated_apis_url = "https://api-sg.aliexpress.com/sync"; | ||
this.new_apis_url = "https://api-sg.aliexpress.com/rest"; | ||
this.sign_method = "sha256"; | ||
var _a, _b; | ||
this.format = RESPONSE_FORMAT; | ||
this.migrated_apis_url = AE_TOP_API_URL; | ||
this.new_apis_url = AE_OP_API_URL; | ||
this.sign_method = SIGN_METHOD; | ||
this.app_key = init.app_key; | ||
this.app_secret = init.app_secret; | ||
this.session = init.session; | ||
this.url = (_a = init.url) != null ? _a : this.migrated_apis_url; | ||
this.format = (_b = init.format) != null ? _b : "json"; | ||
} | ||
@@ -102,3 +113,5 @@ sign(params) { | ||
basestring += Object.keys(p).sort().map((key) => key + p[key]).join(""); | ||
return (0, import_crypto.createHmac)("sha256", this.app_secret, { encoding: "utf-8" }).update(basestring).digest("hex").toUpperCase(); | ||
return (0, import_crypto.createHmac)(SIGN_METHOD, this.app_secret, { | ||
encoding: SIGN_METHOD_ENCODING | ||
}).update(basestring).digest("hex").toUpperCase(); | ||
} | ||
@@ -128,3 +141,3 @@ call(params) { | ||
ok: false, | ||
message: "Bad request.", | ||
message: API_RESPONSE_MESSAGE.BAD_REQUEST, | ||
request_id: data.error_response.request_id | ||
@@ -136,3 +149,3 @@ }; | ||
ok: false, | ||
message: "Internal error." | ||
message: API_RESPONSE_MESSAGE.INTERNAL_ERROR | ||
}; | ||
@@ -469,7 +482,7 @@ } | ||
*/ | ||
// todo | ||
// async searchByImage(args: DS_Image_Search_Params) { | ||
// let response = await this.execute("aliexpress.ds.image.search", args); | ||
// if (response.ok) { | ||
// let data = | ||
// response.data.aliexpress_ds_image_search_response.data.products; | ||
// let data = response.data.aliexpress_ds_image_search_response.data; | ||
// data = parse_affiliate_products(data); | ||
@@ -486,4 +499,5 @@ // } | ||
if (response.ok) { | ||
let data = response.data.aliexpress_ds_recommend_feed_get_response.resp_result.result; | ||
data = parse_affiliate_products(data); | ||
response.data.aliexpress_ds_recommend_feed_get_response.resp_result.result = parse_affiliate_products( | ||
response.data.aliexpress_ds_recommend_feed_get_response.resp_result.result | ||
); | ||
} | ||
@@ -490,0 +504,0 @@ return response; |
{ | ||
"name": "ae_sdk", | ||
"version": "0.4.13", | ||
"version": "0.4.14", | ||
"description": "A simple SDK for Aliexpress (dropshipping and affiliate) APIs.", | ||
@@ -5,0 +5,0 @@ "private": false, |
@@ -12,51 +12,31 @@ # Aliexpress SDK  | ||
## Overview | ||
## Introduction | ||
Aliexpress launched a new open platform to consume their APIs. They fully migrated and upgraded their services from the old [Taobao Open Platform](https://developers.aliexpress.com) to the new [Open Platform for International Developers](https://openservice.aliexpress.com). The issue is, with this update, [they have yet to release a Node.js SDK](https://openservice.aliexpress.com/doc/doc.htm?nodeId=27493&docId=118729#/?docId=1371). | ||
[An overview of the SDK and its features.](https://github.com/moh3a/ae_sdk/blob/main/docs/01-introduction.md) | ||
## Features | ||
## Prerequisites | ||
This library is an unofficial and **simple** SDK that can do the following: | ||
[Check the important steps to take before being able to use this library](https://github.com/moh3a/ae_sdk/blob/main/docs/02-prerequisites.md) | ||
- Compose a request, generate an encryption (method signature) and interprete the response. | ||
- Pass the right parameters for your API call with type safe methods. | ||
- Currently supports the **system tools for authentication**, **Affiliate API** and **Dropshipping API**. | ||
## Installation | ||
```sh | ||
# using npm | ||
npm i ae_sdk | ||
# using pnpm | ||
pnpm add ae_sdk | ||
# using yarn | ||
yarn add ae_sdk | ||
npm install ae_sdk | ||
``` | ||
## Usage | ||
## Basic usage | ||
To be able to use this SDK, you must first [become a developer](https://openservice.aliexpress.com/doc/doc.htm?nodeId=27493&docId=118729#/?docId=1362), follow the steps to register an application, to then retrive your `app_key` and `app_secret`. | ||
Lastly an access token is required to access the API, follow the steps for the authorization process [described in this link](https://openservice.aliexpress.com/doc/doc.htm?nodeId=27493&docId=118729#/?docId=1364). When you get your access token, make sure to pass it the client initialization as `session`. | ||
```ts | ||
// step 1: import the AE affiliate (`AffiliateClient`) or dropshipping (`DropshipperClient`) client | ||
import { DropshipperClient /* AffiliateClient */ } from "ae_sdk"; | ||
// step 1: import the AE client | ||
import { AffiliateClient } from "ae_sdk"; | ||
// step 2: initilize the client | ||
const client = new DropshipperClient({ | ||
const client = new AffiliateClient({ | ||
app_key: "123", | ||
app_secret: "123456abcdef", // process.env.AE_DS_APP_SECRET | ||
session: "oauth_access_token", // process.env.AE_DS_ACCESS_TOKEN or fetch from DB | ||
app_secret: "123456abcdef", | ||
session: "oauth_access_token", | ||
}); | ||
// step 3: you are all set ! | ||
const result = await client.productDetails({ | ||
product_id: 1005004043442825, | ||
ship_to_country: "DZ", | ||
target_currency: "USD", | ||
target_language: "en", | ||
}); | ||
const result = await client.featuredPromoInfo({}); | ||
@@ -66,45 +46,2 @@ console.log(result); | ||
If the call was successfull, you will get back the following results. | ||
> Inside the `data` object is the API response. | ||
```text | ||
{ | ||
ok: true, | ||
data: { | ||
aliexpress_ds_product_get_response: { | ||
result: {...}, | ||
rsp_code: 200, | ||
rsp_msg: "Call succeeds", | ||
request_id: "..." | ||
} | ||
} | ||
} | ||
``` | ||
Else if an error occured you will receive the following: | ||
> Make sure you to pass the right parameters, but if the problem persits, please contact me | ||
```text | ||
{ | ||
ok: false, | ||
message: "..." | ||
} | ||
``` | ||
### Directly call the API | ||
If you wish to call a different Aliexpress API that is not by the current version. You can do the following: | ||
```ts | ||
const result = await client.callAPIDirectly("aliexpress.api.endpoint", { | ||
[string]: string | number | boolean, | ||
}); | ||
``` | ||
## Todos | ||
- Add file parameter to pass `bytes[]` as a method argument, example: query product using an image. | ||
- Add unit tests. | ||
- Write documentation. | ||
[Click here for a more in depth usage guide.](https://github.com/moh3a/ae_sdk/blob/main/docs/03-usage-guide.md) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
2725
0.52%151422
-1.53%46
-57.8%