@sp-api-sdk/vendor-direct-fulfillment-inventory-api-v1
Version:
The Selling Partner API for Direct Fulfillment Inventory Updates provides programmatic access to a direct fulfillment vendor's inventory updates.
266 lines (265 loc) • 13.1 kB
JavaScript
import { createAxiosInstance } from "@sp-api-sdk/common";
import globalAxios from "axios";
//#region src/api-model/base.ts
const BASE_PATH = "https://sellingpartnerapi-na.amazon.com".replace(/\/+$/, "");
var BaseAPI = class {
basePath;
axios;
configuration;
constructor(configuration, basePath = BASE_PATH, axios = globalAxios) {
this.basePath = basePath;
this.axios = axios;
if (configuration) {
this.configuration = configuration;
this.basePath = configuration.basePath ?? basePath;
}
}
};
var RequiredError = class extends Error {
field;
constructor(field, msg) {
super(msg);
this.field = field;
this.name = "RequiredError";
}
};
const operationServerMap = {};
//#endregion
//#region src/api-model/common.ts
const DUMMY_BASE_URL = "https://example.com";
/**
*
* @throws {RequiredError}
*/
const assertParamExists = function(functionName, paramName, paramValue) {
if (paramValue === null || paramValue === void 0) throw new RequiredError(paramName, `Required parameter ${paramName} was null or undefined when calling ${functionName}.`);
};
function setFlattenedQueryParams(urlSearchParams, parameter, key = "") {
if (parameter == null) return;
if (typeof parameter === "object") if (Array.isArray(parameter) || parameter instanceof Set) parameter.forEach((item) => setFlattenedQueryParams(urlSearchParams, item, key));
else Object.keys(parameter).forEach((currentKey) => setFlattenedQueryParams(urlSearchParams, parameter[currentKey], `${key}${key !== "" ? "." : ""}${currentKey}`));
else if (urlSearchParams.has(key)) urlSearchParams.append(key, parameter);
else urlSearchParams.set(key, parameter);
}
const setSearchParams = function(url, ...objects) {
const searchParams = new URLSearchParams(url.search);
setFlattenedQueryParams(searchParams, objects);
url.search = searchParams.toString();
};
/**
* JSON serialization helper function which replaces instances of unserializable types with serializable ones.
* This function will run for every key-value pair encountered by JSON.stringify while traversing an object.
* Converting a set to a string will return an empty object, so an intermediate conversion to an array is required.
*/
const replaceWithSerializableTypeIfNeeded = function(key, value) {
if (value instanceof Set) return Array.from(value);
else return value;
};
const serializeDataIfNeeded = function(value, requestOptions, configuration) {
const nonString = typeof value !== "string";
return (nonString && configuration && configuration.isJsonMime ? configuration.isJsonMime(requestOptions.headers["Content-Type"]) : nonString) ? JSON.stringify(value !== void 0 ? value : {}, replaceWithSerializableTypeIfNeeded) : value || "";
};
const toPathString = function(url) {
return url.pathname + url.search + url.hash;
};
const createRequestFunction = function(axiosArgs, globalAxios, BASE_PATH, configuration) {
return (axios = globalAxios, basePath = BASE_PATH) => {
const axiosRequestArgs = {
...axiosArgs.options,
url: (axios.defaults.baseURL ? "" : configuration?.basePath ?? basePath) + axiosArgs.url
};
return axios.request(axiosRequestArgs);
};
};
//#endregion
//#region src/api-model/api/vendor-direct-fulfillment-inventory-api.ts
/**
* VendorDirectFulfillmentInventoryApi - axios parameter creator
*/
const VendorDirectFulfillmentInventoryApiAxiosParamCreator = function(configuration) {
return {
/**
* Submits inventory updates for the specified warehouse for either a partial or full feed of inventory items. **Usage Plan:** | Rate (requests per second) | Burst | | ---- | ---- | | 10 | 10 | The `x-amzn-RateLimit-Limit` response header returns the usage plan rate limits that were applied to the requested operation, when available. The table above indicates the default rate and burst values for this operation. Selling partners whose business demands require higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
* @param {string} warehouseId Identifier for the warehouse for which to update inventory.
* @param {SubmitInventoryUpdateRequest} body The request body containing the inventory update data to submit.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
submitInventoryUpdate: async (warehouseId, body, options = {}) => {
assertParamExists("submitInventoryUpdate", "warehouseId", warehouseId);
assertParamExists("submitInventoryUpdate", "body", body);
const localVarPath = `/vendor/directFulfillment/inventory/v1/warehouses/{warehouseId}/items`.replace("{warehouseId}", encodeURIComponent(String(warehouseId)));
const localVarUrlObj = new URL(localVarPath, DUMMY_BASE_URL);
let baseOptions;
if (configuration) baseOptions = configuration.baseOptions;
const localVarRequestOptions = {
method: "POST",
...baseOptions,
...options
};
const localVarHeaderParameter = {};
const localVarQueryParameter = {};
localVarHeaderParameter["Content-Type"] = "application/json";
localVarHeaderParameter["Accept"] = "application/json";
setSearchParams(localVarUrlObj, localVarQueryParameter);
let headersFromBaseOptions = baseOptions && baseOptions.headers ? baseOptions.headers : {};
localVarRequestOptions.headers = {
...localVarHeaderParameter,
...headersFromBaseOptions,
...options.headers
};
localVarRequestOptions.data = serializeDataIfNeeded(body, localVarRequestOptions, configuration);
return {
url: toPathString(localVarUrlObj),
options: localVarRequestOptions
};
} };
};
/**
* VendorDirectFulfillmentInventoryApi - functional programming interface
*/
const VendorDirectFulfillmentInventoryApiFp = function(configuration) {
const localVarAxiosParamCreator = VendorDirectFulfillmentInventoryApiAxiosParamCreator(configuration);
return {
/**
* Submits inventory updates for the specified warehouse for either a partial or full feed of inventory items. **Usage Plan:** | Rate (requests per second) | Burst | | ---- | ---- | | 10 | 10 | The `x-amzn-RateLimit-Limit` response header returns the usage plan rate limits that were applied to the requested operation, when available. The table above indicates the default rate and burst values for this operation. Selling partners whose business demands require higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
* @param {string} warehouseId Identifier for the warehouse for which to update inventory.
* @param {SubmitInventoryUpdateRequest} body The request body containing the inventory update data to submit.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
async submitInventoryUpdate(warehouseId, body, options) {
const localVarAxiosArgs = await localVarAxiosParamCreator.submitInventoryUpdate(warehouseId, body, options);
const localVarOperationServerIndex = configuration?.serverIndex ?? 0;
const localVarOperationServerBasePath = operationServerMap["VendorDirectFulfillmentInventoryApi.submitInventoryUpdate"]?.[localVarOperationServerIndex]?.url;
return (axios, basePath) => createRequestFunction(localVarAxiosArgs, globalAxios, BASE_PATH, configuration)(axios, localVarOperationServerBasePath || basePath);
} };
};
/**
* VendorDirectFulfillmentInventoryApi - factory interface
*/
const VendorDirectFulfillmentInventoryApiFactory = function(configuration, basePath, axios) {
const localVarFp = VendorDirectFulfillmentInventoryApiFp(configuration);
return {
/**
* Submits inventory updates for the specified warehouse for either a partial or full feed of inventory items. **Usage Plan:** | Rate (requests per second) | Burst | | ---- | ---- | | 10 | 10 | The `x-amzn-RateLimit-Limit` response header returns the usage plan rate limits that were applied to the requested operation, when available. The table above indicates the default rate and burst values for this operation. Selling partners whose business demands require higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
* @param {VendorDirectFulfillmentInventoryApiSubmitInventoryUpdateRequest} requestParameters Request parameters.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
submitInventoryUpdate(requestParameters, options) {
return localVarFp.submitInventoryUpdate(requestParameters.warehouseId, requestParameters.body, options).then((request) => request(axios, basePath));
} };
};
/**
* VendorDirectFulfillmentInventoryApi - object-oriented interface
*/
var VendorDirectFulfillmentInventoryApi = class extends BaseAPI {
/**
* Submits inventory updates for the specified warehouse for either a partial or full feed of inventory items. **Usage Plan:** | Rate (requests per second) | Burst | | ---- | ---- | | 10 | 10 | The `x-amzn-RateLimit-Limit` response header returns the usage plan rate limits that were applied to the requested operation, when available. The table above indicates the default rate and burst values for this operation. Selling partners whose business demands require higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
* @param {VendorDirectFulfillmentInventoryApiSubmitInventoryUpdateRequest} requestParameters Request parameters.
* @param {*} [options] Override http request option.
* @throws {RequiredError}
*/
submitInventoryUpdate(requestParameters, options) {
return VendorDirectFulfillmentInventoryApiFp(this.configuration).submitInventoryUpdate(requestParameters.warehouseId, requestParameters.body, options).then((request) => request(this.axios, this.basePath));
}
};
//#endregion
//#region src/api-model/configuration.ts
var Configuration = class {
/**
* parameter for apiKey security
* @param name security name
*/
apiKey;
/**
* parameter for basic security
*/
username;
/**
* parameter for basic security
*/
password;
/**
* parameter for oauth2 security
* @param name security name
* @param scopes oauth2 scope
*/
accessToken;
/**
* parameter for aws4 signature security
* @param {Object} AWS4Signature - AWS4 Signature security
* @param {string} options.region - aws region
* @param {string} options.service - name of the service.
* @param {string} credentials.accessKeyId - aws access key id
* @param {string} credentials.secretAccessKey - aws access key
* @param {string} credentials.sessionToken - aws session token
* @memberof Configuration
*/
awsv4;
/**
* override base path
*/
basePath;
/**
* override server index
*/
serverIndex;
/**
* base options for axios calls
*/
baseOptions;
/**
* The FormData constructor that will be used to create multipart form data
* requests. You can inject this here so that execution environments that
* do not support the FormData class can still run the generated client.
*
* @type {new () => FormData}
*/
formDataCtor;
constructor(param = {}) {
this.apiKey = param.apiKey;
this.username = param.username;
this.password = param.password;
this.accessToken = param.accessToken;
this.awsv4 = param.awsv4;
this.basePath = param.basePath;
this.serverIndex = param.serverIndex;
this.baseOptions = {
...param.baseOptions,
headers: { ...param.baseOptions?.headers }
};
this.formDataCtor = param.formDataCtor;
}
/**
* Check if the given MIME is a JSON MIME.
* JSON MIME examples:
* application/json
* application/json; charset=UTF8
* APPLICATION/JSON
* application/vnd.company+json
* @param mime - MIME (Multipurpose Internet Mail Extensions)
* @return True if the given MIME is JSON, false otherwise.
*/
isJsonMime(mime) {
return mime !== null && /^(application\/json|[^;/ \t]+\/[^;/ \t]+[+]json)[ \t]*(;.*)?$/i.test(mime);
}
};
//#endregion
//#region src/client.ts
const clientRateLimits = [{
method: "post",
urlRegex: /^\/vendor\/directFulfillment\/inventory\/v1\/warehouses\/[^\/]*\/items$/v,
rate: 10,
burst: 10
}];
var VendorDirectFulfillmentInventoryApiClient = class extends VendorDirectFulfillmentInventoryApi {
constructor(configuration) {
const { axios, endpoint } = createAxiosInstance(configuration, clientRateLimits);
super(new Configuration(), endpoint, axios);
}
};
//#endregion
export { VendorDirectFulfillmentInventoryApi, VendorDirectFulfillmentInventoryApiAxiosParamCreator, VendorDirectFulfillmentInventoryApiClient, VendorDirectFulfillmentInventoryApiFactory, VendorDirectFulfillmentInventoryApiFp, clientRateLimits };
//# sourceMappingURL=index.js.map