fix: Several parts of the API client were broken. Example code compiles now.
This commit is contained in:
parent
2293cf5b89
commit
b9ca1fd88b
|
@ -21,7 +21,7 @@
|
|||
* https://webservices.amazon.com/paapi5/documentation/getbrowsenodes.html
|
||||
*/
|
||||
|
||||
var ProductAdvertisingAPIv1 = require('./src/index');
|
||||
import * as ProductAdvertisingAPIv1 from '../src/index.mjs';
|
||||
|
||||
var defaultClient = ProductAdvertisingAPIv1.ApiClient.instance;
|
||||
|
||||
|
@ -77,7 +77,7 @@ function parseResponse(browseNodesResponseList) {
|
|||
|
||||
function onSuccess(data) {
|
||||
console.log('API called successfully.');
|
||||
var getBrowseNodesResponse = ProductAdvertisingAPIv1.GetBrowseNodesResponse.constructFromObject(data);
|
||||
var getBrowseNodesResponse = ProductAdvertisingAPIv1.GetBrowseNodesResponse.constructFromObject(data)!;
|
||||
console.log('Complete Response: \n' + JSON.stringify(getBrowseNodesResponse, null, 1));
|
||||
if (getBrowseNodesResponse['BrowseNodesResult'] !== undefined) {
|
||||
console.log('Printing all browse node information in BrowseNodesResult:');
|
|
@ -21,7 +21,7 @@
|
|||
* https://webservices.amazon.com/paapi5/documentation/get-items.html
|
||||
*/
|
||||
|
||||
var ProductAdvertisingAPIv1 = require('./src/index');
|
||||
import * as ProductAdvertisingAPIv1 from '../src/index.mjs';
|
||||
|
||||
var defaultClient = ProductAdvertisingAPIv1.ApiClient.instance;
|
||||
|
||||
|
@ -72,7 +72,7 @@ function parseResponse(itemsResponseList) {
|
|||
|
||||
function onSuccess(data) {
|
||||
console.log('API called successfully.');
|
||||
var getItemsResponse = ProductAdvertisingAPIv1.GetItemsResponse.constructFromObject(data);
|
||||
var getItemsResponse = ProductAdvertisingAPIv1.GetItemsResponse.constructFromObject(data)!;
|
||||
console.log('Complete Response: \n' + JSON.stringify(getItemsResponse, null, 1));
|
||||
if (getItemsResponse['ItemsResult'] !== undefined) {
|
||||
console.log('Printing All Item Information in ItemsResult:');
|
|
@ -21,7 +21,7 @@
|
|||
* https://webservices.amazon.com/paapi5/documentation/get-variations.html
|
||||
*/
|
||||
|
||||
var ProductAdvertisingAPIv1 = require('./src/index');
|
||||
import * as ProductAdvertisingAPIv1 from '../src/index.mjs';
|
||||
|
||||
var defaultClient = ProductAdvertisingAPIv1.ApiClient.instance;
|
||||
|
||||
|
@ -62,7 +62,7 @@ getVariationsRequest['Resources'] = [
|
|||
|
||||
function onSuccess(data) {
|
||||
console.log('API called successfully.');
|
||||
var getVariationsResponse = ProductAdvertisingAPIv1.GetVariationsResponse.constructFromObject(data);
|
||||
var getVariationsResponse = ProductAdvertisingAPIv1.GetVariationsResponse.constructFromObject(data)!;
|
||||
console.log('Complete Response: \n' + JSON.stringify(getVariationsResponse, null, 1));
|
||||
if (getVariationsResponse['VariationsResult'] !== undefined) {
|
||||
//console.log('Complete VariationsResult: \n' + JSON.stringify(getVariationsResponse['VariationsResult'], null, 1));
|
||||
|
@ -74,7 +74,7 @@ function onSuccess(data) {
|
|||
console.log('VariationCount: ' + getVariationsResponse['VariationsResult']['VariationSummary']['VariationCount']);
|
||||
}
|
||||
console.log('Printing First Item Information in VariationsResult:');
|
||||
var item_0 = getVariationsResponse['VariationsResult']['Items'][0];
|
||||
var item_0 = getVariationsResponse['VariationsResult']['Items']![0];
|
||||
if (item_0 !== undefined) {
|
||||
if (item_0['ASIN'] !== undefined) {
|
||||
console.log('ASIN: ' + item_0['ASIN']);
|
|
@ -21,7 +21,7 @@
|
|||
* https://webservices.amazon.com/paapi5/documentation/search-items.html
|
||||
*/
|
||||
|
||||
var ProductAdvertisingAPIv1 = require('./src/index');
|
||||
import * as ProductAdvertisingAPIv1 from '../src/index.mjs';
|
||||
|
||||
var defaultClient = ProductAdvertisingAPIv1.ApiClient.instance;
|
||||
|
||||
|
@ -66,11 +66,11 @@ searchItemsRequest['Resources'] = ['Images.Primary.Medium', 'ItemInfo.Title', 'O
|
|||
|
||||
function onSuccess(data) {
|
||||
console.log('API called successfully.');
|
||||
var searchItemsResponse = ProductAdvertisingAPIv1.SearchItemsResponse.constructFromObject(data);
|
||||
var searchItemsResponse = ProductAdvertisingAPIv1.SearchItemsResponse.constructFromObject(data)!;
|
||||
console.log('Complete Response: \n' + JSON.stringify(searchItemsResponse, null, 1));
|
||||
if (searchItemsResponse['SearchResult'] !== undefined) {
|
||||
console.log('Printing First Item Information in SearchResult:');
|
||||
var item_0 = searchItemsResponse['SearchResult']['Items'][0];
|
||||
var item_0 = searchItemsResponse['SearchResult']['Items']![0];
|
||||
if (item_0 !== undefined) {
|
||||
if (item_0['ASIN'] !== undefined) {
|
||||
console.log('ASIN: ' + item_0['ASIN']);
|
4
package-lock.json
generated
4
package-lock.json
generated
|
@ -1,12 +1,12 @@
|
|||
{
|
||||
"name": "amazon-pa-api5-node-ts",
|
||||
"version": "2.2.3",
|
||||
"version": "2.2.4",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "amazon-pa-api5-node-ts",
|
||||
"version": "2.2.2",
|
||||
"version": "2.2.4",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"superagent": "^9.0.0"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "amazon-pa-api5-node-ts",
|
||||
"version": "2.2.3",
|
||||
"version": "2.2.4",
|
||||
"description": "ProductAdvertisingAPI 5.0 NodeJS SDK rewritten in TypeScript.",
|
||||
"license": "Apache-2.0",
|
||||
"main": "dist/src/index.mjs",
|
||||
|
|
|
@ -68,6 +68,11 @@
|
|||
*/
|
||||
MULTI = 'multi',
|
||||
};
|
||||
|
||||
export interface ApiResponse<T> {
|
||||
data: T;
|
||||
response: any;
|
||||
}
|
||||
|
||||
/**
|
||||
* Manages low level client-server communications, parameter marshalling, etc. There should not be any need for an
|
||||
|
@ -344,9 +349,9 @@
|
|||
* constructor for a complex type.
|
||||
* @returns {Promise} A {@link https://www.promisejs.org/|Promise} object.
|
||||
*/
|
||||
public callApi(path: string, httpMethod: string, apiName: string, pathParams: Record<string, string>,
|
||||
public callApi<T>(path: string, httpMethod: string, apiName: string, pathParams: Record<string, string>,
|
||||
queryParams: Record<string, any>, collectionQueryParams: Record<string, any>, headerParams: Record<string, any>, formParams: Record<string, any>, bodyParam: any, authNames: string[], contentTypes: string[], accepts: string[],
|
||||
returnType: string|string[]|any|any[]) {
|
||||
returnType: string|string[]|any|any[]): Promise<ApiResponse<T>> {
|
||||
|
||||
// Throw error if credentials are not specified
|
||||
if (this.accessKey === undefined || this.secretKey === undefined || this.accessKey === null || this.secretKey === null) {
|
||||
|
@ -454,13 +459,13 @@
|
|||
this.agent.attachCookies(request);
|
||||
}
|
||||
|
||||
return new Promise(function(resolve, reject) {
|
||||
return new Promise<ApiResponse<T>>(function(resolve, reject) {
|
||||
request.end(function(error, response) {
|
||||
if (error) {
|
||||
reject(error);
|
||||
} else {
|
||||
try {
|
||||
var data = self.deserialize(response, returnType);
|
||||
var data = self.deserialize(response, returnType) as T;
|
||||
if (self.enableCookies && typeof window === 'undefined'){
|
||||
self.agent.saveCookies(response);
|
||||
}
|
||||
|
|
|
@ -21,7 +21,8 @@
|
|||
*
|
||||
*/
|
||||
|
||||
import { ApiClient } from "../ApiClient.mjs";
|
||||
import { ApiClient, type ApiResponse } from "../ApiClient.mjs";
|
||||
import type { GetItemsResource } from "../index.mjs";
|
||||
import { GetBrowseNodesRequest } from "../model/GetBrowseNodesRequest.mjs";
|
||||
import { GetBrowseNodesResponse } from "../model/GetBrowseNodesResponse.mjs";
|
||||
import { GetItemsRequest } from "../model/GetItemsRequest.mjs";
|
||||
|
@ -55,7 +56,7 @@
|
|||
* @param {module:model/GetBrowseNodesRequest} getBrowseNodesRequest GetBrowseNodesRequest
|
||||
* @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/GetBrowseNodesResponse} and HTTP response
|
||||
*/
|
||||
public getBrowseNodesWithHttpInfo(getBrowseNodesRequest: GetBrowseNodesRequest) {
|
||||
public getBrowseNodesWithHttpInfo(getBrowseNodesRequest: GetBrowseNodesRequest): Promise<ApiResponse<GetBrowseNodesResponse>> {
|
||||
var postBody = getBrowseNodesRequest;
|
||||
|
||||
// verify the required parameter 'getBrowseNodesRequest' is set
|
||||
|
@ -91,11 +92,9 @@
|
|||
* @param {module:model/GetBrowseNodesRequest} getBrowseNodesRequest GetBrowseNodesRequest
|
||||
* @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/GetBrowseNodesResponse}
|
||||
*/
|
||||
public getBrowseNodes(getBrowseNodesRequest: GetBrowseNodesRequest) {
|
||||
public getBrowseNodes(getBrowseNodesRequest: GetBrowseNodesRequest): Promise<GetBrowseNodesResponse> {
|
||||
return this.getBrowseNodesWithHttpInfo(getBrowseNodesRequest)
|
||||
.then(function(response_and_data: any) {
|
||||
return response_and_data.data;
|
||||
});
|
||||
.then((response_and_data: ApiResponse<GetBrowseNodesResponse>) => response_and_data.data);
|
||||
}
|
||||
|
||||
|
||||
|
@ -103,7 +102,7 @@
|
|||
* @param {module:model/GetItemsRequest} getItemsRequest GetItemsRequest
|
||||
* @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/GetItemsResponse} and HTTP response
|
||||
*/
|
||||
public getItemsWithHttpInfo(getItemsRequest: GetItemsRequest) {
|
||||
public getItemsWithHttpInfo(getItemsRequest: GetItemsRequest): Promise<ApiResponse<GetItemsResponse>> {
|
||||
var postBody = getItemsRequest;
|
||||
|
||||
// verify the required parameter 'getItemsRequest' is set
|
||||
|
@ -139,11 +138,9 @@
|
|||
* @param {module:model/GetItemsRequest} getItemsRequest GetItemsRequest
|
||||
* @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/GetItemsResponse}
|
||||
*/
|
||||
public getItems(getItemsRequest: GetItemsRequest) {
|
||||
public getItems(getItemsRequest: GetItemsRequest): Promise<GetItemsResponse> {
|
||||
return this.getItemsWithHttpInfo(getItemsRequest)
|
||||
.then(function(response_and_data: any) {
|
||||
return response_and_data.data;
|
||||
});
|
||||
.then((response_and_data: ApiResponse<GetItemsResponse>) => response_and_data.data);
|
||||
}
|
||||
|
||||
|
||||
|
@ -151,7 +148,7 @@
|
|||
* @param {module:model/GetVariationsRequest} getVariationsRequest GetVariationsRequest
|
||||
* @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/GetVariationsResponse} and HTTP response
|
||||
*/
|
||||
public getVariationsWithHttpInfo(getVariationsRequest: GetVariationsRequest) {
|
||||
public getVariationsWithHttpInfo(getVariationsRequest: GetVariationsRequest): Promise<ApiResponse<GetVariationsResponse>> {
|
||||
var postBody = getVariationsRequest;
|
||||
|
||||
// verify the required parameter 'getVariationsRequest' is set
|
||||
|
@ -187,11 +184,9 @@
|
|||
* @param {module:model/GetVariationsRequest} getVariationsRequest GetVariationsRequest
|
||||
* @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/GetVariationsResponse}
|
||||
*/
|
||||
public getVariations(getVariationsRequest: GetVariationsRequest) {
|
||||
public getVariations(getVariationsRequest: GetVariationsRequest): Promise<GetVariationsResponse> {
|
||||
return this.getVariationsWithHttpInfo(getVariationsRequest)
|
||||
.then(function(response_and_data: any) {
|
||||
return response_and_data.data;
|
||||
});
|
||||
.then((response_and_data: ApiResponse<GetVariationsResponse>) => response_and_data.data);
|
||||
}
|
||||
|
||||
|
||||
|
@ -199,7 +194,7 @@
|
|||
* @param {module:model/SearchItemsRequest} searchItemsRequest SearchItemsRequest
|
||||
* @return {Promise} a {@link https://www.promisejs.org/|Promise}, with an object containing data of type {@link module:model/SearchItemsResponse} and HTTP response
|
||||
*/
|
||||
public searchItemsWithHttpInfo(searchItemsRequest: SearchItemsRequest) {
|
||||
public searchItemsWithHttpInfo(searchItemsRequest: SearchItemsRequest): Promise<ApiResponse<SearchItemsResponse>> {
|
||||
var postBody = searchItemsRequest;
|
||||
|
||||
// verify the required parameter 'searchItemsRequest' is set
|
||||
|
@ -235,11 +230,9 @@
|
|||
* @param {module:model/SearchItemsRequest} searchItemsRequest SearchItemsRequest
|
||||
* @return {Promise} a {@link https://www.promisejs.org/|Promise}, with data of type {@link module:model/SearchItemsResponse}
|
||||
*/
|
||||
public searchItems(searchItemsRequest: SearchItemsRequest) {
|
||||
public searchItems(searchItemsRequest: SearchItemsRequest): Promise<SearchItemsResponse> {
|
||||
return this.searchItemsWithHttpInfo(searchItemsRequest)
|
||||
.then(function(response_and_data: any) {
|
||||
return response_and_data.data;
|
||||
});
|
||||
.then((response_and_data: ApiResponse<SearchItemsResponse>) => response_and_data.data);
|
||||
}
|
||||
};
|
||||
|
|
@ -63,7 +63,7 @@ export class GetBrowseNodesRequest {
|
|||
/**
|
||||
* @member {Array.<module:model/GetBrowseNodesResource>} Resources
|
||||
*/
|
||||
public Resources?: GetBrowseNodesResource;
|
||||
public Resources?: GetBrowseNodesResource[];
|
||||
|
||||
// not sure if this is ever going to be relevant:
|
||||
// public constructor(browseNodeIds, partnerTag, partnerType) {
|
||||
|
|
|
@ -26,17 +26,17 @@
|
|||
* @enum {}
|
||||
* @readonly
|
||||
*/
|
||||
export const enum GetBrowseNodesResourceValues {
|
||||
export const GetBrowseNodesResourceValues = {
|
||||
/**
|
||||
* value: "BrowseNodes.Ancestor"
|
||||
* @const
|
||||
*/
|
||||
Ancestor = "BrowseNodes.Ancestor",
|
||||
"BrowseNodes.Ancestor": "BrowseNodes.Ancestor",
|
||||
/**
|
||||
* value: "BrowseNodes.Children"
|
||||
* @const
|
||||
*/
|
||||
Children = "BrowseNodes.Children"
|
||||
"BrowseNodes.Children": "BrowseNodes.Children",
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -45,20 +45,14 @@ export const enum GetBrowseNodesResourceValues {
|
|||
* @readonly
|
||||
*/
|
||||
export class GetBrowseNodesResource extends String {
|
||||
/**
|
||||
* value: "BrowseNodes.Ancestor"
|
||||
* @const
|
||||
*/
|
||||
public static get Ancestor() { return GetBrowseNodesResourceValues.Ancestor; }
|
||||
/**
|
||||
* value: "BrowseNodes.Children"
|
||||
* @const
|
||||
*/
|
||||
public static get Children() { return GetBrowseNodesResourceValues.Children; }
|
||||
public constructor(s: string) {
|
||||
super(GetBrowseNodesResourceValues[s]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a <code>GetBrowseNodesResource</code> enum value from a Javascript object name.
|
||||
* @param {Object} data The plain JavaScript object containing the name of the enum value.
|
||||
* @return {module:model/GetBrowseNodesResource} The enum <code>GetBrowseNodesResource</code> value.
|
||||
*/
|
||||
public static constructFromObject(object: GetBrowseNodesResource|GetBrowseNodesResourceValues|string) { return object; }
|
||||
public static constructFromObject(object: GetBrowseNodesResource|string) { return object; }
|
||||
};
|
||||
|
|
|
@ -330,12 +330,9 @@ export const GetItemsResourceValues = {
|
|||
* @enum {}
|
||||
* @readonly
|
||||
*/
|
||||
export class GetItemsResource {
|
||||
[key: string]: any;
|
||||
|
||||
public constructor() {
|
||||
const self = this;
|
||||
Object.keys(GetItemsResourceValues).forEach((key: string) => self[key] = GetItemsResource[key]);
|
||||
export class GetItemsResource extends String {
|
||||
public constructor(s: string) {
|
||||
super(GetItemsResourceValues[s]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
* @enum {}
|
||||
* @readonly
|
||||
*/
|
||||
export const GetVariationsResourceValues = {
|
||||
export const GetVariationsResourceValues: Record<string, string> = {
|
||||
/**
|
||||
* value: "BrowseNodeInfo.BrowseNodes"
|
||||
* @const
|
||||
|
@ -336,7 +336,7 @@ export const GetVariationsResourceValues = {
|
|||
* value: "VariationSummary.VariationDimension"
|
||||
* @const
|
||||
*/
|
||||
"VariationSummary.VariationDimension": "VariationSummary.VariationDimension"
|
||||
"VariationSummary.VariationDimension": "VariationSummary.VariationDimension",
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -344,12 +344,9 @@ export const GetVariationsResourceValues = {
|
|||
* @enum {}
|
||||
* @readonly
|
||||
*/
|
||||
export class GetVariationsResource {
|
||||
[key: string]: any;
|
||||
|
||||
public constructor() {
|
||||
const self = this;
|
||||
Object.keys(GetVariationsResourceValues).forEach((key: string) => self[key] = GetVariationsResourceValues[key]);
|
||||
export class GetVariationsResource extends String {
|
||||
public constructor(s: string) {
|
||||
super(GetVariationsResourceValues[s]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue
Block a user