@dianemo/plugin-newegg 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/NOTICE +5 -0
- package/README.md +59 -0
- package/dist/client.d.ts +16 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +92 -0
- package/dist/client.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/requests/feeds/index.d.ts +4 -0
- package/dist/requests/feeds/index.d.ts.map +1 -0
- package/dist/requests/feeds/index.js +49 -0
- package/dist/requests/feeds/index.js.map +1 -0
- package/dist/requests/feeds/types.d.ts +43 -0
- package/dist/requests/feeds/types.d.ts.map +1 -0
- package/dist/requests/feeds/types.js +2 -0
- package/dist/requests/feeds/types.js.map +1 -0
- package/dist/requests/index.d.ts +6 -0
- package/dist/requests/index.d.ts.map +1 -0
- package/dist/requests/index.js +6 -0
- package/dist/requests/index.js.map +1 -0
- package/dist/requests/inventory/index.d.ts +10 -0
- package/dist/requests/inventory/index.d.ts.map +1 -0
- package/dist/requests/inventory/index.js +55 -0
- package/dist/requests/inventory/index.js.map +1 -0
- package/dist/requests/inventory/types.d.ts +70 -0
- package/dist/requests/inventory/types.d.ts.map +1 -0
- package/dist/requests/inventory/types.js +2 -0
- package/dist/requests/inventory/types.js.map +1 -0
- package/dist/requests/orders/index.d.ts +10 -0
- package/dist/requests/orders/index.d.ts.map +1 -0
- package/dist/requests/orders/index.js +59 -0
- package/dist/requests/orders/index.js.map +1 -0
- package/dist/requests/orders/types.d.ts +241 -0
- package/dist/requests/orders/types.d.ts.map +1 -0
- package/dist/requests/orders/types.js +40 -0
- package/dist/requests/orders/types.js.map +1 -0
- package/dist/requests/pricing/index.d.ts +5 -0
- package/dist/requests/pricing/index.d.ts.map +1 -0
- package/dist/requests/pricing/index.js +40 -0
- package/dist/requests/pricing/index.js.map +1 -0
- package/dist/requests/pricing/types.d.ts +80 -0
- package/dist/requests/pricing/types.d.ts.map +1 -0
- package/dist/requests/pricing/types.js +11 -0
- package/dist/requests/pricing/types.js.map +1 -0
- package/dist/requests/returns/index.d.ts +3 -0
- package/dist/requests/returns/index.d.ts.map +1 -0
- package/dist/requests/returns/index.js +18 -0
- package/dist/requests/returns/index.js.map +1 -0
- package/dist/requests/returns/types.d.ts +93 -0
- package/dist/requests/returns/types.d.ts.map +1 -0
- package/dist/requests/returns/types.js +2 -0
- package/dist/requests/returns/types.js.map +1 -0
- package/dist/requests/types.d.ts +32 -0
- package/dist/requests/types.d.ts.map +1 -0
- package/dist/requests/types.js +26 -0
- package/dist/requests/types.js.map +1 -0
- package/dist/requests/utils.d.ts +22 -0
- package/dist/requests/utils.d.ts.map +1 -0
- package/dist/requests/utils.js +26 -0
- package/dist/requests/utils.js.map +1 -0
- package/docs/newegg-api.md +155 -0
- package/package.json +128 -0
- package/src/client.ts +120 -0
- package/src/index.ts +34 -0
- package/src/requests/feeds/index.ts +70 -0
- package/src/requests/feeds/types.ts +56 -0
- package/src/requests/index.ts +5 -0
- package/src/requests/inventory/index.ts +94 -0
- package/src/requests/inventory/types.ts +83 -0
- package/src/requests/orders/index.ts +94 -0
- package/src/requests/orders/types.ts +284 -0
- package/src/requests/pricing/index.ts +70 -0
- package/src/requests/pricing/types.ts +95 -0
- package/src/requests/returns/index.ts +30 -0
- package/src/requests/returns/types.ts +113 -0
- package/src/requests/types.ts +36 -0
- package/src/requests/utils.ts +26 -0
package/src/client.ts
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { CreateClientData, TokenCredentials } from "@dianemo/core/client/types";
|
|
2
|
+
import RequestHandler, { buildClientName } from "@dianemo/core";
|
|
3
|
+
|
|
4
|
+
interface NeweggCredentials extends TokenCredentials {
|
|
5
|
+
secretKey: string;
|
|
6
|
+
sellerId: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
declare module "@dianemo/core" {
|
|
10
|
+
interface ClientTemplates {
|
|
11
|
+
newegg: NeweggCredentials;
|
|
12
|
+
neweggBusiness: NeweggCredentials;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const tenThousandPerHourEndpoints = [
|
|
17
|
+
"getItemInventory",
|
|
18
|
+
"updateItemInventory",
|
|
19
|
+
"getItemPricing",
|
|
20
|
+
"updateItemPricing",
|
|
21
|
+
"getFeedStatus",
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
const oneThousandPerHourEndpoints = [
|
|
25
|
+
"getOrders",
|
|
26
|
+
"markOrderDownloaded",
|
|
27
|
+
"shipOrder",
|
|
28
|
+
"getRmaInfo",
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
const tenPerMinuteEndpoints = ["submitFeed"];
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* **Every figure below is this repo's own ceiling, not Newegg's.** Newegg
|
|
35
|
+
* documents that non-datafeed functions are metered per minute and datafeed
|
|
36
|
+
* functions per hour, but publishes no numbers for either — and returns the real
|
|
37
|
+
* per-function limit in `X-RateLimit-Limit` on every response, which is how they
|
|
38
|
+
* could be replaced with vendor-stated ones. The hourly buckets here are also
|
|
39
|
+
* drip-fed rather than burstable, which is safe against a per-minute limit but is
|
|
40
|
+
* not the shape of the limit: docs/newegg-api.md#rate-limits-the-mechanism-is-documented-the-numbers-are-not
|
|
41
|
+
*/
|
|
42
|
+
const getSubClients = (): CreateClientData[] => {
|
|
43
|
+
const subClients: CreateClientData[] = [];
|
|
44
|
+
for (const endpoint of tenThousandPerHourEndpoints) {
|
|
45
|
+
subClients.push({
|
|
46
|
+
name: endpoint,
|
|
47
|
+
rateLimit: {
|
|
48
|
+
type: "requestLimit",
|
|
49
|
+
interval: 360,
|
|
50
|
+
tokensToAdd: 1,
|
|
51
|
+
maxTokens: 10000,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
for (const endpoint of oneThousandPerHourEndpoints) {
|
|
56
|
+
subClients.push({
|
|
57
|
+
name: endpoint,
|
|
58
|
+
rateLimit: {
|
|
59
|
+
type: "requestLimit",
|
|
60
|
+
interval: 3600,
|
|
61
|
+
tokensToAdd: 1,
|
|
62
|
+
maxTokens: 1000,
|
|
63
|
+
},
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
for (const endpoint of tenPerMinuteEndpoints) {
|
|
67
|
+
subClients.push({
|
|
68
|
+
name: endpoint,
|
|
69
|
+
rateLimit: {
|
|
70
|
+
type: "requestLimit",
|
|
71
|
+
interval: 6000,
|
|
72
|
+
tokensToAdd: 1,
|
|
73
|
+
maxTokens: 10,
|
|
74
|
+
},
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return subClients;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const buildNeweggClient = (
|
|
81
|
+
name: string,
|
|
82
|
+
creds: NeweggCredentials
|
|
83
|
+
): CreateClientData => ({
|
|
84
|
+
name,
|
|
85
|
+
authentication: {
|
|
86
|
+
type: "token",
|
|
87
|
+
excludePrefix: true,
|
|
88
|
+
token: creds.token,
|
|
89
|
+
},
|
|
90
|
+
requestOptions: {
|
|
91
|
+
defaults: {
|
|
92
|
+
baseURL: creds.baseUrl,
|
|
93
|
+
headers: {
|
|
94
|
+
"Content-Type": "application/json",
|
|
95
|
+
Accept: "application/json",
|
|
96
|
+
SecretKey: creds.secretKey,
|
|
97
|
+
},
|
|
98
|
+
params: { sellerid: creds.sellerId },
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
subClients: getSubClients(),
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
export async function registerNeweggTemplate(handler: RequestHandler) {
|
|
105
|
+
await handler.registerClientTemplate(
|
|
106
|
+
"newegg",
|
|
107
|
+
(creds): CreateClientData[] => [
|
|
108
|
+
buildNeweggClient(buildClientName("newegg", creds), creds),
|
|
109
|
+
]
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export async function registerNeweggBusinessTemplate(handler: RequestHandler) {
|
|
114
|
+
await handler.registerClientTemplate(
|
|
115
|
+
"neweggBusiness",
|
|
116
|
+
(creds): CreateClientData[] => [
|
|
117
|
+
buildNeweggClient(buildClientName("neweggBusiness", creds), creds),
|
|
118
|
+
]
|
|
119
|
+
);
|
|
120
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { bindTryHandleRequest } from "@dianemo/plugin-kit";
|
|
2
|
+
import * as requests from "./requests/index.js";
|
|
3
|
+
import { definePlugin } from "@dianemo/core";
|
|
4
|
+
import {
|
|
5
|
+
registerNeweggTemplate,
|
|
6
|
+
registerNeweggBusinessTemplate,
|
|
7
|
+
} from "./client.js";
|
|
8
|
+
|
|
9
|
+
// Two templates, one API surface: the consumer and business marketplaces
|
|
10
|
+
// take separate credentials but share every request function.
|
|
11
|
+
export default definePlugin({
|
|
12
|
+
name: "newegg",
|
|
13
|
+
registerTemplate: async (handler) => {
|
|
14
|
+
await registerNeweggTemplate(handler);
|
|
15
|
+
await registerNeweggBusinessTemplate(handler);
|
|
16
|
+
},
|
|
17
|
+
createRequests: (ctx) => {
|
|
18
|
+
bindTryHandleRequest(ctx);
|
|
19
|
+
return requests;
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
export {
|
|
24
|
+
registerNeweggTemplate,
|
|
25
|
+
registerNeweggBusinessTemplate,
|
|
26
|
+
} from "./client.js";
|
|
27
|
+
export * from "./requests/index.js";
|
|
28
|
+
|
|
29
|
+
export * from "./requests/feeds/types.js";
|
|
30
|
+
export * from "./requests/inventory/types.js";
|
|
31
|
+
export * from "./requests/orders/types.js";
|
|
32
|
+
export * from "./requests/pricing/types.js";
|
|
33
|
+
export * from "./requests/returns/types.js";
|
|
34
|
+
export * from "./requests/types.js";
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { neweggSubClient, neweggSucceeded } from "../utils.js";
|
|
2
|
+
import { tryHandleRequest } from "@dianemo/plugin-kit";
|
|
3
|
+
import { RequestError } from "@dianemo/core";
|
|
4
|
+
import {
|
|
5
|
+
NeweggFeedResponse,
|
|
6
|
+
NeweggGetFeedStatusData,
|
|
7
|
+
NeweggSubmitFeedResponse,
|
|
8
|
+
} from "./types.js";
|
|
9
|
+
|
|
10
|
+
export const getFeedStatus = async (
|
|
11
|
+
clientName: string,
|
|
12
|
+
feedId: string
|
|
13
|
+
): Promise<NeweggFeedResponse> => {
|
|
14
|
+
const data: NeweggGetFeedStatusData = {
|
|
15
|
+
OperationType: "GetFeedStatusRequest",
|
|
16
|
+
RequestBody: {
|
|
17
|
+
GetRequestStatus: { RequestIDList: [{ RequestID: feedId }] },
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
const res = await tryHandleRequest<NeweggSubmitFeedResponse>(
|
|
21
|
+
{
|
|
22
|
+
clientName: neweggSubClient(clientName, "getFeedStatus"),
|
|
23
|
+
requestName: "newegg.feeds.getStatus",
|
|
24
|
+
url: `/datafeedmgmt/feeds/status`,
|
|
25
|
+
method: "PUT",
|
|
26
|
+
data,
|
|
27
|
+
},
|
|
28
|
+
"NWG_0007",
|
|
29
|
+
"Failed to get Newegg feed status"
|
|
30
|
+
);
|
|
31
|
+
const resData = res.data;
|
|
32
|
+
const feedData = resData.ResponseBody.ResponseList[0];
|
|
33
|
+
if (!feedData || !neweggSucceeded(resData)) {
|
|
34
|
+
throw new RequestError("NWG_0008", "Newegg feed status request failed", {
|
|
35
|
+
metadata: {
|
|
36
|
+
context: `${feedData?.RequestStatus ?? "No request status"} | MEMO: ${resData.Memo || "N/A"}`,
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return feedData;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export const submitFeed = async (
|
|
44
|
+
clientName: string,
|
|
45
|
+
requestType: string,
|
|
46
|
+
data: object
|
|
47
|
+
): Promise<NeweggFeedResponse> => {
|
|
48
|
+
const res = await tryHandleRequest<NeweggSubmitFeedResponse>(
|
|
49
|
+
{
|
|
50
|
+
clientName: neweggSubClient(clientName, "submitFeed"),
|
|
51
|
+
requestName: "newegg.feeds.submit",
|
|
52
|
+
url: `/datafeedmgmt/feeds/submitfeed`,
|
|
53
|
+
method: "POST",
|
|
54
|
+
params: { requesttype: requestType },
|
|
55
|
+
data,
|
|
56
|
+
},
|
|
57
|
+
"NWG_0005",
|
|
58
|
+
"Failed to submit Newegg feed"
|
|
59
|
+
);
|
|
60
|
+
const resData = res.data;
|
|
61
|
+
const feedData = resData.ResponseBody.ResponseList[0];
|
|
62
|
+
if (!feedData || !neweggSucceeded(resData)) {
|
|
63
|
+
throw new RequestError("NWG_0006", "Newegg feed submission failed", {
|
|
64
|
+
metadata: {
|
|
65
|
+
context: `${feedData?.RequestStatus ?? "No request status"} | MEMO: ${resData.Memo || "N/A"}`,
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
return feedData;
|
|
70
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
export type NeweggFeedType =
|
|
2
|
+
| "ITEM_DATA"
|
|
3
|
+
| "INVENTORY_AND_PRICE_DATA"
|
|
4
|
+
| "INVENTORY_DATA"
|
|
5
|
+
| "PRICE_DATA"
|
|
6
|
+
| "ITEM_COUNTRY_RESTRICTION_DATA"
|
|
7
|
+
| "ORDER_SHIP_NOTICE_DATA"
|
|
8
|
+
| "MULTICHANNEL_ORDER_DATA"
|
|
9
|
+
| "VOLUME_DISCOUNT_DATA"
|
|
10
|
+
| "ITEM_WARRANTY_DATA"
|
|
11
|
+
| "ITEM_CAPROP65_DATA"
|
|
12
|
+
| "ITEM_CHINATAXSETTING_DATA"
|
|
13
|
+
| "ITEM_SAFEGUARD_SETTING_DATA"
|
|
14
|
+
| "VEHICLE_SPECIFIC_ITEM_DATA";
|
|
15
|
+
|
|
16
|
+
export type NeweggFeedStatus =
|
|
17
|
+
"SUBMITTED" | "IN_PROGRESS" | "FINISHED" | "CANCELLED";
|
|
18
|
+
|
|
19
|
+
export interface NeweggGetFeedStatusData {
|
|
20
|
+
OperationType: "GetFeedStatusRequest";
|
|
21
|
+
RequestBody: {
|
|
22
|
+
GetRequestStatus: {
|
|
23
|
+
RequestIDList?: { RequestID: string }[];
|
|
24
|
+
RequestType?: NeweggFeedType;
|
|
25
|
+
MaxCount?: string;
|
|
26
|
+
RequestStatus?: "ALL" | NeweggFeedStatus;
|
|
27
|
+
RequestDateFrom?: string;
|
|
28
|
+
RequestDateTo?: string;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface NeweggSubmitFeedResponse {
|
|
34
|
+
/**
|
|
35
|
+
* A JSON boolean on this endpoint, per Newegg's published sample. Read it
|
|
36
|
+
* through `neweggSucceeded` rather than comparing directly — the same flag is
|
|
37
|
+
* a string on other Newegg endpoints.
|
|
38
|
+
*/
|
|
39
|
+
IsSuccess: boolean;
|
|
40
|
+
OperationType: string;
|
|
41
|
+
SellerID: string;
|
|
42
|
+
ResponseBody: { ResponseList: NeweggFeedResponse[] };
|
|
43
|
+
Memo?: string;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface NeweggFeedResponse {
|
|
47
|
+
/**
|
|
48
|
+
* `RequestId` here, but `RequestIDList.RequestID` in the request body above:
|
|
49
|
+
* Newegg spells the key differently by direction. Both are as published — not
|
|
50
|
+
* a typo to fix. docs/newegg-api.md#requestid-on-the-way-in-requestid-on-the-way-out
|
|
51
|
+
*/
|
|
52
|
+
RequestId: string;
|
|
53
|
+
RequestType: NeweggFeedType;
|
|
54
|
+
RequestDate: string;
|
|
55
|
+
RequestStatus: NeweggFeedStatus;
|
|
56
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { tryHandleRequest } from "@dianemo/plugin-kit";
|
|
2
|
+
import { NeweggItemUpdateType } from "../types.js";
|
|
3
|
+
import { submitFeed } from "../feeds/index.js";
|
|
4
|
+
import { neweggSubClient } from "../utils.js";
|
|
5
|
+
import {
|
|
6
|
+
NeweggBusinessInventoryResponse,
|
|
7
|
+
NeweggDetailedItemInventory,
|
|
8
|
+
NeweggGetInventoryData,
|
|
9
|
+
NeweggGetInventoryResponse,
|
|
10
|
+
NeweggInventoryFeedItemData,
|
|
11
|
+
NeweggItemInventory,
|
|
12
|
+
NeweggSubmitInventoryFeedData,
|
|
13
|
+
NeweggUpdateItemInventoryData,
|
|
14
|
+
NeweggUpdateItemInventoryResponse,
|
|
15
|
+
} from "./types.js";
|
|
16
|
+
|
|
17
|
+
export const getItemInventory = async (
|
|
18
|
+
clientName: string,
|
|
19
|
+
data: NeweggGetInventoryData
|
|
20
|
+
): Promise<NeweggDetailedItemInventory[]> => {
|
|
21
|
+
const res = await tryHandleRequest<NeweggGetInventoryResponse>(
|
|
22
|
+
{
|
|
23
|
+
clientName: neweggSubClient(clientName, "getItemInventory"),
|
|
24
|
+
requestName: "newegg.inventory.get",
|
|
25
|
+
url: `/contentmgmt/item/international/inventory`,
|
|
26
|
+
method: "PUT",
|
|
27
|
+
data,
|
|
28
|
+
},
|
|
29
|
+
"NWG_0009",
|
|
30
|
+
"Failed to get Newegg item inventory"
|
|
31
|
+
);
|
|
32
|
+
return res.data.InventoryAllocation;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Deliberately the same `getItemInventory` sub-client: it is the same logical
|
|
37
|
+
* operation against the same published budget, so the two share one bucket.
|
|
38
|
+
*/
|
|
39
|
+
export const getBusinessItemInventory = async (
|
|
40
|
+
clientName: string,
|
|
41
|
+
data: NeweggGetInventoryData
|
|
42
|
+
): Promise<NeweggBusinessInventoryResponse> => {
|
|
43
|
+
const res = await tryHandleRequest<NeweggBusinessInventoryResponse>(
|
|
44
|
+
{
|
|
45
|
+
clientName: neweggSubClient(clientName, "getItemInventory"),
|
|
46
|
+
requestName: "newegg.inventory.getBusiness",
|
|
47
|
+
url: `/contentmgmt/item/inventory`,
|
|
48
|
+
method: "POST",
|
|
49
|
+
params: { version: 304 },
|
|
50
|
+
data,
|
|
51
|
+
},
|
|
52
|
+
"NWG_0014",
|
|
53
|
+
"Failed to get Newegg business item inventory"
|
|
54
|
+
);
|
|
55
|
+
return res.data;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
export const submitInventoryFeed = async (
|
|
59
|
+
clientName: string,
|
|
60
|
+
inventory: NeweggInventoryFeedItemData[]
|
|
61
|
+
) => {
|
|
62
|
+
const data: NeweggSubmitInventoryFeedData = {
|
|
63
|
+
NeweggEnvelope: {
|
|
64
|
+
Header: { DocumentVersion: "2.0" },
|
|
65
|
+
MessageType: "Inventory",
|
|
66
|
+
Message: { Inventory: { Item: inventory } },
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
return await submitFeed(clientName, "INVENTORY_DATA", data);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const updateItemInventory = async (
|
|
73
|
+
clientName: string,
|
|
74
|
+
sku: string,
|
|
75
|
+
inventory: NeweggItemInventory[]
|
|
76
|
+
): Promise<NeweggUpdateItemInventoryResponse> => {
|
|
77
|
+
const data: NeweggUpdateItemInventoryData = {
|
|
78
|
+
Type: NeweggItemUpdateType.SellerPartNumber,
|
|
79
|
+
Value: sku,
|
|
80
|
+
InventoryList: { Inventory: inventory },
|
|
81
|
+
};
|
|
82
|
+
const res = await tryHandleRequest<NeweggUpdateItemInventoryResponse>(
|
|
83
|
+
{
|
|
84
|
+
clientName: neweggSubClient(clientName, "updateItemInventory"),
|
|
85
|
+
requestName: "newegg.inventory.update",
|
|
86
|
+
url: `/contentmgmt/item/international/inventory`,
|
|
87
|
+
method: "POST",
|
|
88
|
+
data,
|
|
89
|
+
},
|
|
90
|
+
"NWG_0010",
|
|
91
|
+
"Failed to update Newegg item inventory"
|
|
92
|
+
);
|
|
93
|
+
return res.data;
|
|
94
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import {
|
|
2
|
+
NeweggFeedWrapper,
|
|
3
|
+
NeweggItemCondition,
|
|
4
|
+
NeweggItemFulfillmentOption,
|
|
5
|
+
NeweggItemUpdateType,
|
|
6
|
+
} from "../types.js";
|
|
7
|
+
|
|
8
|
+
export interface NeweggGetInventoryData {
|
|
9
|
+
Type: NeweggItemUpdateType;
|
|
10
|
+
Value: string;
|
|
11
|
+
Condition?: NeweggItemCondition;
|
|
12
|
+
WarehouseLocation?: string;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface NeweggGetInventoryResponse {
|
|
16
|
+
SellerID: string;
|
|
17
|
+
ItemNumber: string;
|
|
18
|
+
SellerPartNumber: string;
|
|
19
|
+
InventoryAllocation: NeweggDetailedItemInventory[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The business marketplace answers a flat record rather than the international
|
|
24
|
+
* endpoint's `InventoryAllocation` array, and sends `FulfillmentOption` and
|
|
25
|
+
* `Active` as **strings** where the rest of this package models them as numeric
|
|
26
|
+
* enums. Typed as the wire sends them rather than as the enums they resemble —
|
|
27
|
+
* docs/newegg-api.md#the-business-marketplace-has-its-own-inventory-endpoint
|
|
28
|
+
*/
|
|
29
|
+
export interface NeweggBusinessInventoryResponse {
|
|
30
|
+
SellerID: string;
|
|
31
|
+
ItemNumber: string;
|
|
32
|
+
SellerPartNumber: string;
|
|
33
|
+
/** A string, not the enum. Only `"0"` has been observed. */
|
|
34
|
+
FulfillmentOption: string;
|
|
35
|
+
/** `"1"` active, `"0"` inactive — both observed. A string, not the enum. */
|
|
36
|
+
Active: string;
|
|
37
|
+
AvailableQuantity: number;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface NeweggDetailedItemInventory {
|
|
41
|
+
WarehouseLocation: string;
|
|
42
|
+
FulfillmentOption: NeweggItemFulfillmentOption;
|
|
43
|
+
AvailableQuantity: number;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export interface NeweggSubmitInventoryFeedData extends NeweggFeedWrapper<NeweggInventoryFeedMessage> {}
|
|
47
|
+
|
|
48
|
+
export interface NeweggInventoryFeedMessage {
|
|
49
|
+
Inventory: {
|
|
50
|
+
Item: NeweggInventoryFeedItemData[];
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export interface NeweggInventoryFeedItemData {
|
|
55
|
+
SellerPartNumber: string;
|
|
56
|
+
WarehouseLocation: string;
|
|
57
|
+
Inventory: number;
|
|
58
|
+
FulfillmentOption?: "Seller";
|
|
59
|
+
NeweggItemNumber?: string;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export interface NeweggUpdateItemInventoryData {
|
|
63
|
+
Type: NeweggItemUpdateType;
|
|
64
|
+
Value: string;
|
|
65
|
+
InventoryList: {
|
|
66
|
+
Inventory: NeweggItemInventory[];
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export interface NeweggItemInventory {
|
|
71
|
+
WarehouseLocation: string;
|
|
72
|
+
AvailableQuantity: number;
|
|
73
|
+
Condition?: NeweggItemCondition;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export interface NeweggUpdateItemInventoryResponse {
|
|
77
|
+
SellerID: string;
|
|
78
|
+
ItemNumber: string;
|
|
79
|
+
SellerPartNumber: string;
|
|
80
|
+
InventoryList: {
|
|
81
|
+
Inventory: NeweggItemInventory[];
|
|
82
|
+
};
|
|
83
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { tryHandleRequest } from "@dianemo/plugin-kit";
|
|
2
|
+
import { neweggSubClient } from "../utils.js";
|
|
3
|
+
import {
|
|
4
|
+
NeweggGetOrdersFilters,
|
|
5
|
+
NeweggGetOrdersData,
|
|
6
|
+
NeweggGetOrdersResponse,
|
|
7
|
+
NeweggMarkOrderDownloadedData,
|
|
8
|
+
NeweggMarkOrderDownloadedResponse,
|
|
9
|
+
NeweggShipOrderPackage,
|
|
10
|
+
NeweggShipOrderData,
|
|
11
|
+
NeweggShipOrderResponse,
|
|
12
|
+
} from "./types.js";
|
|
13
|
+
|
|
14
|
+
export const getOrders = async (
|
|
15
|
+
clientName: string,
|
|
16
|
+
filters: NeweggGetOrdersFilters
|
|
17
|
+
): Promise<NeweggGetOrdersResponse> => {
|
|
18
|
+
const data: NeweggGetOrdersData = {
|
|
19
|
+
OperationType: "GetOrderInfoRequest",
|
|
20
|
+
RequestBody: filters,
|
|
21
|
+
};
|
|
22
|
+
const res = await tryHandleRequest<NeweggGetOrdersResponse>(
|
|
23
|
+
{
|
|
24
|
+
clientName: neweggSubClient(clientName, "getOrders"),
|
|
25
|
+
requestName: "newegg.orders.list",
|
|
26
|
+
method: "PUT",
|
|
27
|
+
url: `/ordermgmt/order/orderinfo`,
|
|
28
|
+
params: { version: 315 },
|
|
29
|
+
data,
|
|
30
|
+
},
|
|
31
|
+
"NWG_0001",
|
|
32
|
+
"Failed to get Newegg orders"
|
|
33
|
+
);
|
|
34
|
+
return res.data;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const markOrderDownloaded = async (
|
|
38
|
+
clientName: string,
|
|
39
|
+
orderNumbers: string[]
|
|
40
|
+
) => {
|
|
41
|
+
const data: NeweggMarkOrderDownloadedData = {
|
|
42
|
+
OperationType: "OrderConfirmationRequest",
|
|
43
|
+
RequestBody: {
|
|
44
|
+
DownloadedOrderList: {
|
|
45
|
+
OrderNumber: orderNumbers,
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
const res = await tryHandleRequest<NeweggMarkOrderDownloadedResponse>(
|
|
50
|
+
{
|
|
51
|
+
clientName: neweggSubClient(clientName, "markOrderDownloaded"),
|
|
52
|
+
requestName: "newegg.orders.markDownloaded",
|
|
53
|
+
method: "POST",
|
|
54
|
+
url: `/ordermgmt/orderstatus/orders/confirmation`,
|
|
55
|
+
data,
|
|
56
|
+
},
|
|
57
|
+
"NWG_0002",
|
|
58
|
+
"Failed to mark Newegg order as downloaded"
|
|
59
|
+
);
|
|
60
|
+
return res.data.NeweggAPIResponse.ResponseBody;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export const shipOrder = async (
|
|
64
|
+
clientName: string,
|
|
65
|
+
orderNumber: string,
|
|
66
|
+
packages: NeweggShipOrderPackage[],
|
|
67
|
+
sellerId: string
|
|
68
|
+
): Promise<NeweggShipOrderResponse> => {
|
|
69
|
+
const data: NeweggShipOrderData = {
|
|
70
|
+
Action: "2",
|
|
71
|
+
Value: {
|
|
72
|
+
Shipment: {
|
|
73
|
+
Header: {
|
|
74
|
+
SellerID: sellerId,
|
|
75
|
+
SONumber: Number(orderNumber),
|
|
76
|
+
},
|
|
77
|
+
PackageList: { Package: packages },
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
const res = await tryHandleRequest<NeweggShipOrderResponse>(
|
|
82
|
+
{
|
|
83
|
+
clientName: neweggSubClient(clientName, "shipOrder"),
|
|
84
|
+
requestName: "newegg.orders.ship",
|
|
85
|
+
method: "PUT",
|
|
86
|
+
url: `/ordermgmt/orderstatus/orders/${orderNumber}`,
|
|
87
|
+
params: { version: 304, ordernumber: orderNumber },
|
|
88
|
+
data,
|
|
89
|
+
},
|
|
90
|
+
"NWG_0013",
|
|
91
|
+
"Failed to ship Newegg order"
|
|
92
|
+
);
|
|
93
|
+
return res.data;
|
|
94
|
+
};
|