Comparing version 0.1.0 to 0.2.0
# ae_sdk | ||
## 0.2.0 | ||
### Minor Changes | ||
- Migrate to new AE API and add affiliate methods | ||
## 0.1.0 | ||
@@ -4,0 +10,0 @@ |
@@ -23,11 +23,8 @@ type AE_API_NAMES = DS_API_NAMES | AFFILIATE_API_NAMES | TOP_AUTH_API_NAMES; | ||
interface PublicParams { | ||
method: AE_API_NAMES; | ||
app_key: string; | ||
session?: string; | ||
access_token?: string; | ||
timestamp: string; | ||
format?: AE_Response_Format; | ||
v: string; | ||
sign_method: "hmac" | "md5" | "sha256"; | ||
sign?: string; | ||
simplify?: boolean; | ||
sign_method: "hmac" | "md5"; | ||
sign?: string; | ||
} | ||
@@ -659,6 +656,6 @@ interface AE_Base_Client { | ||
protected readonly v = "2.0"; | ||
protected readonly sign_method = "md5"; | ||
protected readonly sign_method = "sha256"; | ||
constructor(init: AE_Base_Client); | ||
protected sign(params: any): string; | ||
protected call<T extends PublicParams, K>(params: T): Promise<K | undefined>; | ||
protected sign(method: AE_API_NAMES, params: any): string; | ||
protected call<T extends PublicParams, K>(method: AE_API_NAMES, params: T): Promise<K | undefined>; | ||
protected get_timestamp(d?: Timestamp): string; | ||
@@ -670,2 +667,7 @@ } | ||
protected execute<K extends AFFILIATE_API_NAMES>(method: K, params: AE_AFFILIATE_EXECUTE_FN_PARAMS<K>): Promise<AE_AFFILIATE_EXECUTE_FN_RESULT<K> | undefined>; | ||
queryProducts(args: Affiliate_Products_Params): Promise<Affiliate_Products_Result | undefined>; | ||
queryHotProducts(args: Affiliate_Products_Params): Promise<Affiliate_Products_Result | undefined>; | ||
categories(): Promise<Affiliate_Categories_Result | undefined>; | ||
featuredPromo(args: Affiliate_Featured_Promo_Products_Params): Promise<Affiliate_Featured_Promo_Products_Result | undefined>; | ||
productDetails(args: Affiliate_Product_Details_Params): Promise<Affiliate_Product_Details_Result | undefined>; | ||
} | ||
@@ -672,0 +674,0 @@ |
@@ -70,27 +70,62 @@ "use strict"; | ||
this.v = "2.0"; | ||
this.sign_method = "md5"; | ||
this.sign_method = "sha256"; | ||
var _a, _b; | ||
this.app_key = init.app_key; | ||
this.app_secret = init.app_secret; | ||
this.url = (_a = init.url) != null ? _a : "https://api.taobao.com/router/rest"; | ||
this.url = (_a = init.url) != null ? _a : "https://api-sg.aliexpress.com/sync"; | ||
this.format = (_b = init.format) != null ? _b : "json"; | ||
} | ||
sign(params) { | ||
// protected sign(params: any): string { | ||
// let sorted = Object.keys(params).sort(); | ||
// let basestring = this.app_secret; | ||
// for (let i = 0; i < sorted.length; i++) { | ||
// basestring += sorted[i] + params[sorted[i] as keyof typeof params]; | ||
// } | ||
// basestring += this.app_secret; | ||
// return createHash("md5") | ||
// .update(basestring, "utf-8") | ||
// .digest("hex") | ||
// .toUpperCase(); | ||
// } | ||
sign(method, params) { | ||
let basestring = method; | ||
let sorted = Object.keys(params).sort(); | ||
let basestring = this.app_secret; | ||
for (let i = 0; i < sorted.length; i++) { | ||
basestring += sorted[i] + params[sorted[i]]; | ||
} | ||
basestring += this.app_secret; | ||
return (0, import_crypto.createHash)("md5").update(basestring, "utf-8").digest("hex").toUpperCase(); | ||
return (0, import_crypto.createHmac)("sha256", this.app_secret, { encoding: "utf-8" }).update(basestring).digest("hex"); | ||
} | ||
call(params) { | ||
// protected async call<T extends PublicParams, K>(params: T) { | ||
// try { | ||
// let basestring = this.url; | ||
// let sorted = Object.keys(params).sort(); | ||
// for (let i = 0; i < sorted.length; i++) { | ||
// let symbol = i === 0 ? "?" : "&"; | ||
// if (params[sorted[i] as keyof typeof params]) | ||
// basestring += | ||
// symbol + | ||
// sorted[i] + | ||
// "=" + | ||
// encodeURIComponent( | ||
// params[sorted[i] as keyof typeof params] as | ||
// | number | ||
// | string | ||
// | boolean, | ||
// ); | ||
// } | ||
// const res = await fetch(basestring, { method: "POST" }); | ||
// return (await res.json()) as K; | ||
// } catch (error) { | ||
// console.error(error); | ||
// return; | ||
// } | ||
// } | ||
call(method, params) { | ||
return __async(this, null, function* () { | ||
try { | ||
let basestring = this.url; | ||
let basestring = this.url + "?method=" + method; | ||
let sorted = Object.keys(params).sort(); | ||
for (let i = 0; i < sorted.length; i++) { | ||
let symbol = i === 0 ? "?" : "&"; | ||
if (params[sorted[i]]) | ||
basestring += symbol + sorted[i] + "=" + encodeURIComponent( | ||
basestring += "&" + sorted[i] + "=" + encodeURIComponent( | ||
params[sorted[i]] | ||
@@ -147,13 +182,38 @@ ); | ||
app_key: this.app_key, | ||
method, | ||
simplify: true, | ||
v: this.v, | ||
format: this.format, | ||
sign_method: this.sign_method, | ||
timestamp: this.get_timestamp() | ||
}); | ||
parameters.sign = this.sign(parameters); | ||
return yield this.call(parameters); | ||
parameters.sign = this.sign(method, parameters); | ||
return yield this.call(method, parameters); | ||
}); | ||
} | ||
queryProducts(args) { | ||
return __async(this, null, function* () { | ||
return yield this.execute("aliexpress.affiliate.product.query", args); | ||
}); | ||
} | ||
queryHotProducts(args) { | ||
return __async(this, null, function* () { | ||
return yield this.execute("aliexpress.affiliate.hotproduct.query", args); | ||
}); | ||
} | ||
categories() { | ||
return __async(this, null, function* () { | ||
return yield this.execute("aliexpress.affiliate.category.get", null); | ||
}); | ||
} | ||
featuredPromo(args) { | ||
return __async(this, null, function* () { | ||
return yield this.execute( | ||
"aliexpress.affiliate.featuredpromo.products.get", | ||
args | ||
); | ||
}); | ||
} | ||
productDetails(args) { | ||
return __async(this, null, function* () { | ||
return yield this.execute("aliexpress.affiliate.productdetail.get", args); | ||
}); | ||
} | ||
}; | ||
@@ -171,12 +231,9 @@ | ||
app_key: this.app_key, | ||
session: this.session, | ||
method, | ||
access_token: this.session, | ||
simplify: true, | ||
v: this.v, | ||
format: this.format, | ||
sign_method: this.sign_method, | ||
timestamp: this.get_timestamp() | ||
timestamp: Date.now().toString() | ||
}); | ||
parameters.sign = this.sign(parameters); | ||
return yield this.call(parameters); | ||
parameters.sign = this.sign(method, parameters); | ||
return yield this.call(method, parameters); | ||
}); | ||
@@ -183,0 +240,0 @@ } |
{ | ||
"name": "ae_sdk", | ||
"version": "0.1.0", | ||
"version": "0.2.0", | ||
"description": "A simple SDK for Aliexpress (dropshipping and affiliate) APIs.", | ||
@@ -5,0 +5,0 @@ "private": false, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
69750
1234
2