@shopnex/cj-plugin 1.0.1 → 1.0.3
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/README.md +110 -0
- package/dist/CjConfig.d.ts +7 -0
- package/dist/CjConfig.js +93 -0
- package/dist/CjConfig.js.map +1 -0
- package/dist/api-client.d.ts +2 -0
- package/dist/api-client.js +27 -0
- package/dist/api-client.js.map +1 -0
- package/dist/auth.d.ts +15 -0
- package/dist/auth.js +47 -0
- package/dist/auth.js.map +1 -0
- package/dist/cj-settings.d.ts +2 -0
- package/dist/cj-settings.js +90 -0
- package/dist/cj-settings.js.map +1 -0
- package/dist/error-handler.d.ts +12 -0
- package/dist/error-handler.js +41 -0
- package/dist/error-handler.js.map +1 -0
- package/dist/error-types.d.ts +20 -0
- package/dist/error-types.js +7 -0
- package/dist/error-types.js.map +1 -0
- package/dist/exports/rsc.d.ts +1 -0
- package/dist/exports/rsc.js +3 -0
- package/dist/exports/rsc.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +56 -0
- package/dist/index.js.map +1 -0
- package/dist/rsc/ApiToken.d.ts +9 -0
- package/dist/rsc/ApiToken.js +21 -0
- package/dist/rsc/ApiToken.js.map +1 -0
- package/dist/rsc/ApiToken.scss +5 -0
- package/dist/sdk/access-token.d.ts +9 -0
- package/dist/sdk/access-token.js +24 -0
- package/dist/sdk/access-token.js.map +1 -0
- package/dist/sdk/cj-sdk.d.ts +4 -0
- package/dist/sdk/cj-sdk.js +6 -0
- package/dist/sdk/cj-sdk.js.map +1 -0
- package/dist/sdk/dispute/dispute-types.d.ts +64 -0
- package/dist/sdk/dispute/dispute-types.js +4 -0
- package/dist/sdk/dispute/dispute-types.js.map +1 -0
- package/dist/sdk/dispute/dispute.d.ts +4 -0
- package/dist/sdk/dispute/dispute.js +52 -0
- package/dist/sdk/dispute/dispute.js.map +1 -0
- package/dist/sdk/inventory/inventory-types.d.ts +7 -0
- package/dist/sdk/inventory/inventory-types.js +3 -0
- package/dist/sdk/inventory/inventory-types.js.map +1 -0
- package/dist/sdk/inventory/inventory.d.ts +3 -0
- package/dist/sdk/inventory/inventory.js +41 -0
- package/dist/sdk/inventory/inventory.js.map +1 -0
- package/dist/sdk/orders/order-types.d.ts +135 -0
- package/dist/sdk/orders/order-types.js +3 -0
- package/dist/sdk/orders/order-types.js.map +1 -0
- package/dist/sdk/orders/orders.d.ts +16 -0
- package/dist/sdk/orders/orders.js +167 -0
- package/dist/sdk/orders/orders.js.map +1 -0
- package/dist/sdk/products/product-types.d.ts +186 -0
- package/dist/sdk/products/product-types.js +5 -0
- package/dist/sdk/products/product-types.js.map +1 -0
- package/dist/sdk/products/products.d.ts +9 -0
- package/dist/sdk/products/products.js +96 -0
- package/dist/sdk/products/products.js.map +1 -0
- package/dist/sdk/settings/settings-api.d.ts +2 -0
- package/dist/sdk/settings/settings-api.js +20 -0
- package/dist/sdk/settings/settings-api.js.map +1 -0
- package/dist/sdk/settings/settings-types.d.ts +22 -0
- package/dist/sdk/settings/settings-types.js +3 -0
- package/dist/sdk/settings/settings-types.js.map +1 -0
- package/dist/sdk/variants/variant-types.d.ts +18 -0
- package/dist/sdk/variants/variant-types.js +3 -0
- package/dist/sdk/variants/variant-types.js.map +1 -0
- package/dist/sdk/variants/variants.d.ts +8 -0
- package/dist/sdk/variants/variants.js +76 -0
- package/dist/sdk/variants/variants.js.map +1 -0
- package/dist/service/convert-html-to-lexical.d.ts +0 -0
- package/dist/service/convert-html-to-lexical.js +75 -0
- package/dist/service/convert-html-to-lexical.js.map +1 -0
- package/dist/service/create-order.hook.d.ts +12 -0
- package/dist/service/create-order.hook.js +70 -0
- package/dist/service/create-order.hook.js.map +1 -0
- package/dist/service/sync-products.d.ts +4 -0
- package/dist/service/sync-products.js +148 -0
- package/dist/service/sync-products.js.map +1 -0
- package/dist/types.d.ts +74 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/ui/refund-button.d.ts +3 -0
- package/dist/ui/refund-button.js +24 -0
- package/dist/ui/refund-button.js.map +1 -0
- package/dist/util/manage-tokens.d.ts +4 -0
- package/dist/util/manage-tokens.js +41 -0
- package/dist/util/manage-tokens.js.map +1 -0
- package/package.json +1 -1
@@ -0,0 +1,21 @@
|
|
1
|
+
"use client";
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
3
|
+
import React from "react";
|
4
|
+
import { PasswordField } from "@payloadcms/ui";
|
5
|
+
import "./ApiToken.scss";
|
6
|
+
export function ApiToken({ path, readOnly, label = "API Token" }) {
|
7
|
+
return /*#__PURE__*/ _jsx(PasswordField, {
|
8
|
+
autoComplete: "new-password",
|
9
|
+
field: {
|
10
|
+
name: "password",
|
11
|
+
label: "API Token"
|
12
|
+
},
|
13
|
+
indexPath: "",
|
14
|
+
parentPath: "",
|
15
|
+
parentSchemaPath: "",
|
16
|
+
path: path,
|
17
|
+
schemaPath: "password"
|
18
|
+
});
|
19
|
+
}
|
20
|
+
|
21
|
+
//# sourceMappingURL=ApiToken.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/rsc/ApiToken.tsx"],"sourcesContent":["\"use client\";\n\nimport React from \"react\";\nimport { PasswordField } from \"@payloadcms/ui\";\nimport \"./ApiToken.scss\";\n\ninterface ApiTokenProps {\n path: string;\n readOnly?: boolean;\n label?: string;\n}\n\nexport function ApiToken({ path, readOnly, label = \"API Token\" }: ApiTokenProps) {\n return (\n <PasswordField\n autoComplete=\"new-password\"\n field={{\n name: \"password\",\n label: \"API Token\",\n }}\n indexPath=\"\"\n parentPath=\"\"\n parentSchemaPath=\"\"\n path={path}\n schemaPath=\"password\"\n />\n );\n}\n"],"names":["React","PasswordField","ApiToken","path","readOnly","label","autoComplete","field","name","indexPath","parentPath","parentSchemaPath","schemaPath"],"mappings":"AAAA;;AAEA,OAAOA,WAAW,QAAQ;AAC1B,SAASC,aAAa,QAAQ,iBAAiB;AAC/C,OAAO,kBAAkB;AAQzB,OAAO,SAASC,SAAS,EAAEC,IAAI,EAAEC,QAAQ,EAAEC,QAAQ,WAAW,EAAiB;IAC3E,qBACI,KAACJ;QACGK,cAAa;QACbC,OAAO;YACHC,MAAM;YACNH,OAAO;QACX;QACAI,WAAU;QACVC,YAAW;QACXC,kBAAiB;QACjBR,MAAMA;QACNS,YAAW;;AAGvB"}
|
@@ -0,0 +1,9 @@
|
|
1
|
+
type Credentials = {
|
2
|
+
emailAddress: string;
|
3
|
+
password: string;
|
4
|
+
refreshToken?: string;
|
5
|
+
};
|
6
|
+
export declare const getCurrentAccessToken: () => Promise<string>;
|
7
|
+
export declare const setTenantCredentials: (shopId: string, creds: Credentials) => void;
|
8
|
+
export declare const getTenantAccessToken: (shopId: string) => Promise<string>;
|
9
|
+
export {};
|
@@ -0,0 +1,24 @@
|
|
1
|
+
import * as cjSdk from "./cj-sdk";
|
2
|
+
const tenantCredentialsMap = new Map();
|
3
|
+
export const getCurrentAccessToken = async ()=>{
|
4
|
+
const shopId = '1';
|
5
|
+
const accessToken = await getTenantAccessToken(shopId);
|
6
|
+
return accessToken;
|
7
|
+
};
|
8
|
+
export const setTenantCredentials = (shopId, creds)=>{
|
9
|
+
tenantCredentialsMap.set(shopId, creds);
|
10
|
+
};
|
11
|
+
export const getTenantAccessToken = async (shopId)=>{
|
12
|
+
const creds = tenantCredentialsMap.get(shopId);
|
13
|
+
if (!creds?.emailAddress || !creds?.password) {
|
14
|
+
throw new Error(`Credentials for tenant ${shopId} are missing or incomplete`);
|
15
|
+
}
|
16
|
+
const { emailAddress, password, refreshToken } = creds;
|
17
|
+
let accessToken = (await cjSdk.refreshAccessToken(refreshToken || "")).accessToken;
|
18
|
+
if (!accessToken) {
|
19
|
+
accessToken = (await cjSdk.getAccessToken(emailAddress, password)).accessToken;
|
20
|
+
}
|
21
|
+
return accessToken;
|
22
|
+
};
|
23
|
+
|
24
|
+
//# sourceMappingURL=access-token.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/sdk/access-token.ts"],"sourcesContent":["import * as cjSdk from \"./cj-sdk\";\n\ntype Credentials = {\n emailAddress: string;\n password: string;\n refreshToken?: string;\n};\n\nconst tenantCredentialsMap = new Map<string, Credentials>();\n\nexport const getCurrentAccessToken = async () => {\n const shopId = '1'\n const accessToken = await getTenantAccessToken(shopId);\n return accessToken\n};\n\nexport const setTenantCredentials = (shopId: string, creds: Credentials) => {\n tenantCredentialsMap.set(shopId, creds);\n};\n\nexport const getTenantAccessToken = async (shopId: string) => {\n const creds = tenantCredentialsMap.get(shopId);\n\n if (!creds?.emailAddress || !creds?.password) {\n throw new Error(`Credentials for tenant ${shopId} are missing or incomplete`);\n }\n\n const { emailAddress, password, refreshToken } = creds;\n let accessToken = (await cjSdk.refreshAccessToken(refreshToken || \"\")).accessToken;\n if (!accessToken) {\n accessToken = (await cjSdk.getAccessToken(emailAddress, password)).accessToken;\n }\n return accessToken;\n};\n"],"names":["cjSdk","tenantCredentialsMap","Map","getCurrentAccessToken","shopId","accessToken","getTenantAccessToken","setTenantCredentials","creds","set","get","emailAddress","password","Error","refreshToken","refreshAccessToken","getAccessToken"],"mappings":"AAAA,YAAYA,WAAW,WAAW;AAQlC,MAAMC,uBAAuB,IAAIC;AAEjC,OAAO,MAAMC,wBAAwB;IACjC,MAAMC,SAAS;IACf,MAAMC,cAAc,MAAMC,qBAAqBF;IAC/C,OAAOC;AACX,EAAE;AAEF,OAAO,MAAME,uBAAuB,CAACH,QAAgBI;IACjDP,qBAAqBQ,GAAG,CAACL,QAAQI;AACrC,EAAE;AAEF,OAAO,MAAMF,uBAAuB,OAAOF;IACvC,MAAMI,QAAQP,qBAAqBS,GAAG,CAACN;IAEvC,IAAI,CAACI,OAAOG,gBAAgB,CAACH,OAAOI,UAAU;QAC1C,MAAM,IAAIC,MAAM,CAAC,uBAAuB,EAAET,OAAO,0BAA0B,CAAC;IAChF;IAEA,MAAM,EAAEO,YAAY,EAAEC,QAAQ,EAAEE,YAAY,EAAE,GAAGN;IACjD,IAAIH,cAAc,AAAC,CAAA,MAAML,MAAMe,kBAAkB,CAACD,gBAAgB,GAAE,EAAGT,WAAW;IAClF,IAAI,CAACA,aAAa;QACdA,cAAc,AAAC,CAAA,MAAML,MAAMgB,cAAc,CAACL,cAAcC,SAAQ,EAAGP,WAAW;IAClF;IACA,OAAOA;AACX,EAAE"}
|
@@ -0,0 +1,4 @@
|
|
1
|
+
export { getAccessToken, logout, refreshAccessToken } from '../auth';
|
2
|
+
export { confirmOrder, createOrder, deleteOrder, listOrders, queryOrder } from './orders/orders';
|
3
|
+
export { getProductCategory, getProductDetails, getProductList } from './products/products';
|
4
|
+
export { getSettings } from './settings/settings-api';
|
@@ -0,0 +1,6 @@
|
|
1
|
+
export { getAccessToken, logout, refreshAccessToken } from '../auth';
|
2
|
+
export { confirmOrder, createOrder, deleteOrder, listOrders, queryOrder } from './orders/orders';
|
3
|
+
export { getProductCategory, getProductDetails, getProductList } from './products/products';
|
4
|
+
export { getSettings } from './settings/settings-api';
|
5
|
+
|
6
|
+
//# sourceMappingURL=cj-sdk.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../src/sdk/cj-sdk.ts"],"sourcesContent":["export { getAccessToken, logout, refreshAccessToken } from '../auth'\nexport { confirmOrder, createOrder, deleteOrder, listOrders, queryOrder } from './orders/orders'\nexport { getProductCategory, getProductDetails, getProductList } from './products/products'\nexport { getSettings } from './settings/settings-api'\n"],"names":["getAccessToken","logout","refreshAccessToken","confirmOrder","createOrder","deleteOrder","listOrders","queryOrder","getProductCategory","getProductDetails","getProductList","getSettings"],"mappings":"AAAA,SAASA,cAAc,EAAEC,MAAM,EAAEC,kBAAkB,QAAQ,UAAS;AACpE,SAASC,YAAY,EAAEC,WAAW,EAAEC,WAAW,EAAEC,UAAU,EAAEC,UAAU,QAAQ,kBAAiB;AAChG,SAASC,kBAAkB,EAAEC,iBAAiB,EAAEC,cAAc,QAAQ,sBAAqB;AAC3F,SAASC,WAAW,QAAQ,0BAAyB"}
|
@@ -0,0 +1,64 @@
|
|
1
|
+
export interface CreateDisputeRequest {
|
2
|
+
businessDisputeId: string;
|
3
|
+
disputeReasonId: number;
|
4
|
+
expectType: number;
|
5
|
+
imageUrl?: string[];
|
6
|
+
messageText: string;
|
7
|
+
orderId: string;
|
8
|
+
productInfoList: {
|
9
|
+
lineItemId: string;
|
10
|
+
price?: number;
|
11
|
+
quantity: number;
|
12
|
+
}[];
|
13
|
+
refundType: number;
|
14
|
+
videoUrl?: string[];
|
15
|
+
}
|
16
|
+
export interface DisputeAPIResponse {
|
17
|
+
code: number;
|
18
|
+
data: any;
|
19
|
+
message: string;
|
20
|
+
redirectUri?: string;
|
21
|
+
requestId?: string;
|
22
|
+
result: boolean;
|
23
|
+
}
|
24
|
+
export interface ConfirmDisputeRequest {
|
25
|
+
orderId: string;
|
26
|
+
productInfoList: {
|
27
|
+
lineItemId: string;
|
28
|
+
price?: number;
|
29
|
+
quantity: number;
|
30
|
+
}[];
|
31
|
+
}
|
32
|
+
export interface ConfirmDisputeResponse {
|
33
|
+
code: number;
|
34
|
+
data: {
|
35
|
+
disputeReasonList: {
|
36
|
+
disputeReasonId: number;
|
37
|
+
reasonName: string;
|
38
|
+
}[];
|
39
|
+
expectResultOptionList: string[];
|
40
|
+
maxAmount: number;
|
41
|
+
maxIossHandTaxAmount: number;
|
42
|
+
maxIossTaxAmount: number;
|
43
|
+
maxPostage: number;
|
44
|
+
maxProductPrice: number;
|
45
|
+
orderId: string;
|
46
|
+
orderNumber: string;
|
47
|
+
productInfoList: {
|
48
|
+
canChoose: boolean;
|
49
|
+
cjImage: string;
|
50
|
+
cjProductId: string;
|
51
|
+
cjProductName: string;
|
52
|
+
cjVariantId: string;
|
53
|
+
lineItemId: string;
|
54
|
+
price: number;
|
55
|
+
quantity: number;
|
56
|
+
sku: string;
|
57
|
+
supplierName: string;
|
58
|
+
}[];
|
59
|
+
};
|
60
|
+
message: string;
|
61
|
+
requestId: string;
|
62
|
+
result: boolean;
|
63
|
+
success: boolean;
|
64
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../src/sdk/dispute/dispute-types.ts"],"sourcesContent":["// disputes-types.ts\nexport interface CreateDisputeRequest {\n businessDisputeId: string\n disputeReasonId: number\n expectType: number\n imageUrl?: string[]\n messageText: string\n orderId: string\n productInfoList: {\n lineItemId: string\n price?: number // If necessary\n quantity: number\n }[]\n refundType: number\n videoUrl?: string[]\n}\n\nexport interface DisputeAPIResponse {\n code: number\n data: any // Adjust based on the actual structure\n message: string\n redirectUri?: string\n requestId?: string\n result: boolean\n}\n\n// dispute-types.ts\nexport interface ConfirmDisputeRequest {\n orderId: string\n productInfoList: {\n lineItemId: string\n price?: number // If necessary\n quantity: number\n }[]\n}\n\nexport interface ConfirmDisputeResponse {\n code: number\n data: {\n disputeReasonList: {\n disputeReasonId: number\n reasonName: string\n }[]\n expectResultOptionList: string[]\n maxAmount: number\n maxIossHandTaxAmount: number\n maxIossTaxAmount: number\n maxPostage: number\n maxProductPrice: number\n orderId: string\n orderNumber: string\n productInfoList: {\n canChoose: boolean\n cjImage: string\n cjProductId: string\n cjProductName: string\n cjVariantId: string\n lineItemId: string\n price: number\n quantity: number\n sku: string\n supplierName: string\n }[]\n }\n message: string\n requestId: string\n result: boolean\n success: boolean\n}\n"],"names":[],"mappings":"AAAA,oBAAoB;AAoCpB,WAgCC"}
|
@@ -0,0 +1,4 @@
|
|
1
|
+
import type { APIResponse } from '../../error-types';
|
2
|
+
import type { ConfirmDisputeRequest, ConfirmDisputeResponse, CreateDisputeRequest, DisputeAPIResponse } from './dispute-types.ts';
|
3
|
+
export declare function createDispute(requestData: CreateDisputeRequest): Promise<APIResponse<DisputeAPIResponse>>;
|
4
|
+
export declare function confirmDispute(requestData: ConfirmDisputeRequest): Promise<APIResponse<ConfirmDisputeResponse>>;
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import { cjApiClient } from '../../api-client';
|
2
|
+
import { getCurrentAccessToken } from '../access-token';
|
3
|
+
export async function createDispute(requestData) {
|
4
|
+
try {
|
5
|
+
const accessToken = await getCurrentAccessToken() // Ensure to populate this with a valid token
|
6
|
+
;
|
7
|
+
const response = await cjApiClient.post('disputes/create', requestData, {
|
8
|
+
headers: {
|
9
|
+
'CJ-Access-Token': accessToken
|
10
|
+
}
|
11
|
+
});
|
12
|
+
if (!response.data.result) {
|
13
|
+
return {
|
14
|
+
error: response.data.message || 'Failed to create dispute'
|
15
|
+
};
|
16
|
+
}
|
17
|
+
return {
|
18
|
+
data: response.data
|
19
|
+
};
|
20
|
+
} catch (error) {
|
21
|
+
console.error(`Error creating dispute [${error.code}]: ${error.message}`);
|
22
|
+
return {
|
23
|
+
error: error.message || 'An unknown error occurred'
|
24
|
+
};
|
25
|
+
}
|
26
|
+
}
|
27
|
+
export async function confirmDispute(requestData) {
|
28
|
+
try {
|
29
|
+
const accessToken = await getCurrentAccessToken() // Ensure to populate this with a valid token
|
30
|
+
;
|
31
|
+
const response = await cjApiClient.post('disputes/disputeConfirmInfo', requestData, {
|
32
|
+
headers: {
|
33
|
+
'CJ-Access-Token': accessToken
|
34
|
+
}
|
35
|
+
});
|
36
|
+
if (!response.data.result) {
|
37
|
+
return {
|
38
|
+
error: response.data.message || 'Failed to confirm dispute'
|
39
|
+
};
|
40
|
+
}
|
41
|
+
return {
|
42
|
+
data: response.data
|
43
|
+
};
|
44
|
+
} catch (error) {
|
45
|
+
console.error(`Error confirming dispute [${error.code}]: ${error.message}`);
|
46
|
+
return {
|
47
|
+
error: error.message || 'An unknown error occurred'
|
48
|
+
};
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
//# sourceMappingURL=dispute.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../src/sdk/dispute/dispute.ts"],"sourcesContent":["import type { APIResponse } from '../../error-types'\nimport type {\n ConfirmDisputeRequest,\n ConfirmDisputeResponse,\n CreateDisputeRequest,\n DisputeAPIResponse,\n} from './dispute-types.ts'\n\nimport { cjApiClient } from '../../api-client'\nimport { getCurrentAccessToken } from '../access-token'\n\nexport async function createDispute(\n requestData: CreateDisputeRequest,\n): Promise<APIResponse<DisputeAPIResponse>> {\n try {\n const accessToken = await getCurrentAccessToken() // Ensure to populate this with a valid token\n const response = await cjApiClient.post<DisputeAPIResponse>('disputes/create', requestData, {\n headers: {\n 'CJ-Access-Token': accessToken,\n },\n })\n\n if (!response.data.result) {\n return {\n error: response.data.message || 'Failed to create dispute',\n }\n }\n\n return { data: response.data }\n } catch (error: any) {\n console.error(`Error creating dispute [${error.code}]: ${error.message}`)\n return { error: error.message || 'An unknown error occurred' }\n }\n}\n\nexport async function confirmDispute(\n requestData: ConfirmDisputeRequest,\n): Promise<APIResponse<ConfirmDisputeResponse>> {\n try {\n const accessToken = await getCurrentAccessToken() // Ensure to populate this with a valid token\n const response = await cjApiClient.post<ConfirmDisputeResponse>(\n 'disputes/disputeConfirmInfo',\n requestData,\n {\n headers: {\n 'CJ-Access-Token': accessToken,\n },\n },\n )\n\n if (!response.data.result) {\n return {\n error: response.data.message || 'Failed to confirm dispute',\n }\n }\n\n return { data: response.data }\n } catch (error: any) {\n console.error(`Error confirming dispute [${error.code}]: ${error.message}`)\n return { error: error.message || 'An unknown error occurred' }\n }\n}\n"],"names":["cjApiClient","getCurrentAccessToken","createDispute","requestData","accessToken","response","post","headers","data","result","error","message","console","code","confirmDispute"],"mappings":"AAQA,SAASA,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,qBAAqB,QAAQ,kBAAiB;AAEvD,OAAO,eAAeC,cACpBC,WAAiC;IAEjC,IAAI;QACF,MAAMC,cAAc,MAAMH,wBAAwB,6CAA6C;;QAC/F,MAAMI,WAAW,MAAML,YAAYM,IAAI,CAAqB,mBAAmBH,aAAa;YAC1FI,SAAS;gBACP,mBAAmBH;YACrB;QACF;QAEA,IAAI,CAACC,SAASG,IAAI,CAACC,MAAM,EAAE;YACzB,OAAO;gBACLC,OAAOL,SAASG,IAAI,CAACG,OAAO,IAAI;YAClC;QACF;QAEA,OAAO;YAAEH,MAAMH,SAASG,IAAI;QAAC;IAC/B,EAAE,OAAOE,OAAY;QACnBE,QAAQF,KAAK,CAAC,CAAC,wBAAwB,EAAEA,MAAMG,IAAI,CAAC,GAAG,EAAEH,MAAMC,OAAO,EAAE;QACxE,OAAO;YAAED,OAAOA,MAAMC,OAAO,IAAI;QAA4B;IAC/D;AACF;AAEA,OAAO,eAAeG,eACpBX,WAAkC;IAElC,IAAI;QACF,MAAMC,cAAc,MAAMH,wBAAwB,6CAA6C;;QAC/F,MAAMI,WAAW,MAAML,YAAYM,IAAI,CACrC,+BACAH,aACA;YACEI,SAAS;gBACP,mBAAmBH;YACrB;QACF;QAGF,IAAI,CAACC,SAASG,IAAI,CAACC,MAAM,EAAE;YACzB,OAAO;gBACLC,OAAOL,SAASG,IAAI,CAACG,OAAO,IAAI;YAClC;QACF;QAEA,OAAO;YAAEH,MAAMH,SAASG,IAAI;QAAC;IAC/B,EAAE,OAAOE,OAAY;QACnBE,QAAQF,KAAK,CAAC,CAAC,0BAA0B,EAAEA,MAAMG,IAAI,CAAC,GAAG,EAAEH,MAAMC,OAAO,EAAE;QAC1E,OAAO;YAAED,OAAOA,MAAMC,OAAO,IAAI;QAA4B;IAC/D;AACF"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../src/sdk/inventory/inventory-types.ts"],"sourcesContent":["export interface Inventory {\n areaEn: string\n areaId: string\n countryCode: string\n storageNum: number\n vid: string\n}\n"],"names":[],"mappings":"AAAA,WAMC"}
|
@@ -0,0 +1,41 @@
|
|
1
|
+
import { cjApiClient } from '../../api-client';
|
2
|
+
import { getCurrentAccessToken } from '../access-token';
|
3
|
+
export async function getInventoryByVariantId(vid) {
|
4
|
+
if (!vid) {
|
5
|
+
return {
|
6
|
+
error: 'vid must be provided.'
|
7
|
+
};
|
8
|
+
}
|
9
|
+
try {
|
10
|
+
const accessToken = await getCurrentAccessToken() // Ensure you populate this with a valid token
|
11
|
+
;
|
12
|
+
const response = await cjApiClient.get('product/stock/queryByVid', {
|
13
|
+
headers: {
|
14
|
+
'CJ-Access-Token': accessToken
|
15
|
+
},
|
16
|
+
params: {
|
17
|
+
vid
|
18
|
+
}
|
19
|
+
});
|
20
|
+
if (!response.data.result) {
|
21
|
+
return {
|
22
|
+
error: response.data.message || 'Failed to fetch inventory'
|
23
|
+
};
|
24
|
+
}
|
25
|
+
if (!response.data.data) {
|
26
|
+
return {
|
27
|
+
error: 'No inventory found'
|
28
|
+
};
|
29
|
+
}
|
30
|
+
return {
|
31
|
+
data: response.data.data
|
32
|
+
};
|
33
|
+
} catch (error) {
|
34
|
+
console.error(`Error fetching inventory by variant ID [${error.code}]: ${error.message}`);
|
35
|
+
return {
|
36
|
+
error: error.message || 'An unknown error occurred'
|
37
|
+
};
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
//# sourceMappingURL=inventory.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../src/sdk/inventory/inventory.ts"],"sourcesContent":["import type { APIResponse } from '../../error-types'\nimport type { CJApiResponse } from '../../types'\nimport type { Inventory } from './inventory-types.ts'\n\nimport { cjApiClient } from '../../api-client'\nimport { getCurrentAccessToken } from '../access-token'\n\nexport async function getInventoryByVariantId(vid: string): Promise<APIResponse<Inventory[]>> {\n if (!vid) {\n return { error: 'vid must be provided.' }\n }\n\n try {\n const accessToken = await getCurrentAccessToken() // Ensure you populate this with a valid token\n const response = await cjApiClient.get<CJApiResponse<Inventory[]>>('product/stock/queryByVid', {\n headers: {\n 'CJ-Access-Token': accessToken,\n },\n params: { vid },\n })\n\n if (!response.data.result) {\n return {\n error: response.data.message || 'Failed to fetch inventory',\n }\n }\n\n if (!response.data.data) {\n return { error: 'No inventory found' }\n }\n\n return { data: response.data.data }\n } catch (error: any) {\n console.error(`Error fetching inventory by variant ID [${error.code}]: ${error.message}`)\n return { error: error.message || 'An unknown error occurred' }\n }\n}\n"],"names":["cjApiClient","getCurrentAccessToken","getInventoryByVariantId","vid","error","accessToken","response","get","headers","params","data","result","message","console","code"],"mappings":"AAIA,SAASA,WAAW,QAAQ,mBAAkB;AAC9C,SAASC,qBAAqB,QAAQ,kBAAiB;AAEvD,OAAO,eAAeC,wBAAwBC,GAAW;IACvD,IAAI,CAACA,KAAK;QACR,OAAO;YAAEC,OAAO;QAAwB;IAC1C;IAEA,IAAI;QACF,MAAMC,cAAc,MAAMJ,wBAAwB,8CAA8C;;QAChG,MAAMK,WAAW,MAAMN,YAAYO,GAAG,CAA6B,4BAA4B;YAC7FC,SAAS;gBACP,mBAAmBH;YACrB;YACAI,QAAQ;gBAAEN;YAAI;QAChB;QAEA,IAAI,CAACG,SAASI,IAAI,CAACC,MAAM,EAAE;YACzB,OAAO;gBACLP,OAAOE,SAASI,IAAI,CAACE,OAAO,IAAI;YAClC;QACF;QAEA,IAAI,CAACN,SAASI,IAAI,CAACA,IAAI,EAAE;YACvB,OAAO;gBAAEN,OAAO;YAAqB;QACvC;QAEA,OAAO;YAAEM,MAAMJ,SAASI,IAAI,CAACA,IAAI;QAAC;IACpC,EAAE,OAAON,OAAY;QACnBS,QAAQT,KAAK,CAAC,CAAC,wCAAwC,EAAEA,MAAMU,IAAI,CAAC,GAAG,EAAEV,MAAMQ,OAAO,EAAE;QACxF,OAAO;YAAER,OAAOA,MAAMQ,OAAO,IAAI;QAA4B;IAC/D;AACF"}
|
@@ -0,0 +1,135 @@
|
|
1
|
+
export interface OrderProduct {
|
2
|
+
quantity: number;
|
3
|
+
vid: string;
|
4
|
+
unitPrice?: number;
|
5
|
+
}
|
6
|
+
export interface CreateOrderPayload {
|
7
|
+
orderNumber: string;
|
8
|
+
shippingZip: string;
|
9
|
+
shippingCountryCode: string;
|
10
|
+
shippingCountry: string;
|
11
|
+
shippingProvince: string;
|
12
|
+
shippingCity: string;
|
13
|
+
shippingCounty?: string;
|
14
|
+
shippingPhone: string;
|
15
|
+
shippingCustomerName: string;
|
16
|
+
shippingAddress: string;
|
17
|
+
shippingAddress2?: string;
|
18
|
+
houseNumber?: string;
|
19
|
+
email?: string;
|
20
|
+
taxId?: string;
|
21
|
+
remark?: string;
|
22
|
+
consigneeID?: string;
|
23
|
+
payType?: 2 | 3;
|
24
|
+
shopAmount?: number;
|
25
|
+
logisticName: string;
|
26
|
+
fromCountryCode: string;
|
27
|
+
platform?: string;
|
28
|
+
iossType?: 1 | 2 | 3;
|
29
|
+
iossNumber?: string;
|
30
|
+
products: OrderProduct[];
|
31
|
+
podProperties?: {
|
32
|
+
areaName: string;
|
33
|
+
links: string[];
|
34
|
+
type: string;
|
35
|
+
layer?: unknown[];
|
36
|
+
}[];
|
37
|
+
}
|
38
|
+
interface ProductInfo {
|
39
|
+
isGroup: boolean;
|
40
|
+
lineItemId: string;
|
41
|
+
quantity: number;
|
42
|
+
subOrderProducts: {
|
43
|
+
lineItemId: string;
|
44
|
+
quantity: number;
|
45
|
+
variantId: string;
|
46
|
+
}[];
|
47
|
+
variantId: string;
|
48
|
+
}
|
49
|
+
interface InterceptOrderReason {
|
50
|
+
code: number;
|
51
|
+
message: string;
|
52
|
+
}
|
53
|
+
export interface CreateOrderResponse {
|
54
|
+
actualPayment?: number;
|
55
|
+
cjPayUrl?: string;
|
56
|
+
interceptOrderReasons: InterceptOrderReason[];
|
57
|
+
iossAmount?: number;
|
58
|
+
iossTaxHandlingFee?: number;
|
59
|
+
logisticsMiss?: boolean;
|
60
|
+
orderAmount?: number;
|
61
|
+
orderId: string;
|
62
|
+
orderNumber: string;
|
63
|
+
orderOriginalAmount?: number;
|
64
|
+
orderStatus: string;
|
65
|
+
postageAmount?: number;
|
66
|
+
postageDiscountAmount?: number;
|
67
|
+
postageOriginalAmount?: number;
|
68
|
+
productAmount?: number;
|
69
|
+
productDiscountAmount?: number;
|
70
|
+
productInfoList: ProductInfo[];
|
71
|
+
productOriginalAmount?: number;
|
72
|
+
shipmentOrderId: string;
|
73
|
+
totalDiscountAmount?: number;
|
74
|
+
}
|
75
|
+
export interface Order {
|
76
|
+
cjOrderId: null | string;
|
77
|
+
createDate: string;
|
78
|
+
logisticName?: string;
|
79
|
+
orderAmount?: number;
|
80
|
+
orderId: string;
|
81
|
+
orderNum: string;
|
82
|
+
orderStatus: string;
|
83
|
+
orderWeight: number;
|
84
|
+
paymentDate?: string;
|
85
|
+
postageAmount?: number;
|
86
|
+
productAmount: number;
|
87
|
+
productList?: any[];
|
88
|
+
remark?: string;
|
89
|
+
shippingAddress: string;
|
90
|
+
shippingCity: string;
|
91
|
+
shippingCountryCode: string;
|
92
|
+
shippingCustomerName: string;
|
93
|
+
shippingPhone: string;
|
94
|
+
shippingProvince: string;
|
95
|
+
trackNumber?: string;
|
96
|
+
}
|
97
|
+
export interface ListOrderResponse {
|
98
|
+
list: Order[];
|
99
|
+
pageNum: number;
|
100
|
+
pageSize: number;
|
101
|
+
total: number;
|
102
|
+
}
|
103
|
+
export interface QueryOrderParams {
|
104
|
+
orderId?: string;
|
105
|
+
orderNum?: string;
|
106
|
+
}
|
107
|
+
export interface ProductListEntry {
|
108
|
+
quantity: number;
|
109
|
+
sellPrice: number;
|
110
|
+
vid: string;
|
111
|
+
}
|
112
|
+
export interface QueryOrderResponse {
|
113
|
+
cjOrderId: null | string;
|
114
|
+
createDate: string;
|
115
|
+
isComplete: number;
|
116
|
+
logisticName?: string;
|
117
|
+
orderAmount: number;
|
118
|
+
orderId: string;
|
119
|
+
orderNum: string;
|
120
|
+
orderStatus: string;
|
121
|
+
orderWeight: number;
|
122
|
+
paymentDate?: string;
|
123
|
+
postageAmount: number;
|
124
|
+
productAmount: number;
|
125
|
+
productList: ProductListEntry[];
|
126
|
+
remark?: string;
|
127
|
+
shippingAddress: string;
|
128
|
+
shippingCity: string;
|
129
|
+
shippingCountryCode: string;
|
130
|
+
shippingCustomerName: string;
|
131
|
+
shippingPhone: string;
|
132
|
+
shippingProvince: string;
|
133
|
+
trackNumber?: string;
|
134
|
+
}
|
135
|
+
export {};
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../../../src/sdk/orders/order-types.ts"],"sourcesContent":["export interface OrderProduct {\n quantity: number;\n vid: string;\n unitPrice?: number;\n}\n\nexport interface CreateOrderPayload {\n orderNumber: string;\n shippingZip: string;\n shippingCountryCode: string;\n shippingCountry: string;\n shippingProvince: string;\n shippingCity: string;\n shippingCounty?: string;\n shippingPhone: string;\n shippingCustomerName: string;\n shippingAddress: string;\n shippingAddress2?: string;\n houseNumber?: string;\n email?: string;\n taxId?: string;\n remark?: string;\n consigneeID?: string;\n payType?: 2 | 3;\n shopAmount?: number;\n logisticName: string;\n fromCountryCode: string;\n platform?: string;\n iossType?: 1 | 2 | 3;\n iossNumber?: string;\n products: OrderProduct[];\n podProperties?: {\n areaName: string;\n links: string[];\n type: string;\n layer?: unknown[];\n }[];\n}\n\ninterface ProductInfo {\n isGroup: boolean;\n lineItemId: string;\n quantity: number;\n subOrderProducts: {\n lineItemId: string;\n quantity: number;\n variantId: string;\n }[];\n variantId: string;\n}\n\n// Define the order interception reasons structure\ninterface InterceptOrderReason {\n code: number;\n message: string;\n}\n\nexport interface CreateOrderResponse {\n actualPayment?: number;\n cjPayUrl?: string;\n interceptOrderReasons: InterceptOrderReason[];\n iossAmount?: number;\n iossTaxHandlingFee?: number;\n logisticsMiss?: boolean;\n orderAmount?: number;\n orderId: string;\n orderNumber: string;\n orderOriginalAmount?: number;\n orderStatus: string;\n postageAmount?: number;\n postageDiscountAmount?: number;\n postageOriginalAmount?: number;\n productAmount?: number;\n productDiscountAmount?: number;\n productInfoList: ProductInfo[];\n productOriginalAmount?: number;\n shipmentOrderId: string;\n totalDiscountAmount?: number;\n}\n\nexport interface Order {\n cjOrderId: null | string;\n createDate: string;\n logisticName?: string;\n orderAmount?: number;\n orderId: string;\n orderNum: string;\n orderStatus: string;\n orderWeight: number;\n paymentDate?: string;\n postageAmount?: number;\n productAmount: number;\n productList?: any[]; // You may replace `any` with a more specific type if known\n remark?: string;\n shippingAddress: string;\n shippingCity: string;\n shippingCountryCode: string;\n shippingCustomerName: string;\n shippingPhone: string;\n shippingProvince: string;\n trackNumber?: string;\n}\n\nexport interface ListOrderResponse {\n list: Order[];\n pageNum: number;\n pageSize: number;\n total: number;\n}\n\nexport interface QueryOrderParams {\n orderId?: string;\n orderNum?: string;\n}\n\nexport interface ProductListEntry {\n quantity: number;\n sellPrice: number;\n vid: string;\n}\n\nexport interface QueryOrderResponse {\n cjOrderId: null | string;\n createDate: string;\n isComplete: number;\n logisticName?: string;\n orderAmount: number;\n orderId: string;\n orderNum: string;\n orderStatus: string;\n orderWeight: number;\n paymentDate?: string;\n postageAmount: number;\n productAmount: number;\n productList: ProductListEntry[];\n remark?: string;\n shippingAddress: string;\n shippingCity: string;\n shippingCountryCode: string;\n shippingCustomerName: string;\n shippingPhone: string;\n shippingProvince: string;\n trackNumber?: string;\n}\n"],"names":[],"mappings":"AAyHA,WAsBC"}
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import type { APIResponse } from '../../error-types';
|
2
|
+
import type { CreateOrderPayload, CreateOrderResponse, ListOrderResponse, QueryOrderParams, QueryOrderResponse } from './order-types.ts';
|
3
|
+
interface ListOrderParams {
|
4
|
+
orderIds?: string[];
|
5
|
+
pageNum?: number;
|
6
|
+
pageSize?: number;
|
7
|
+
status?: string;
|
8
|
+
}
|
9
|
+
export declare function createOrder(orderData: CreateOrderPayload): Promise<APIResponse<CreateOrderResponse>>;
|
10
|
+
export declare function listOrders(accessToken: string, params?: ListOrderParams): Promise<APIResponse<ListOrderResponse>>;
|
11
|
+
export declare function queryOrder(params: QueryOrderParams): Promise<APIResponse<QueryOrderResponse>>;
|
12
|
+
export declare function deleteOrder(orderId: string): Promise<APIResponse<{
|
13
|
+
data: string;
|
14
|
+
}>>;
|
15
|
+
export declare function confirmOrder(orderId: string): Promise<APIResponse<string>>;
|
16
|
+
export {};
|
@@ -0,0 +1,167 @@
|
|
1
|
+
import { cjApiClient } from '../../api-client';
|
2
|
+
import { getCurrentAccessToken } from '../access-token';
|
3
|
+
export async function createOrder(orderData) {
|
4
|
+
try {
|
5
|
+
const accessToken = await getCurrentAccessToken();
|
6
|
+
const response = await cjApiClient.post('shopping/order/createOrderV2', orderData, {
|
7
|
+
headers: {
|
8
|
+
'CJ-Access-Token': accessToken,
|
9
|
+
'Content-Type': 'application/json'
|
10
|
+
}
|
11
|
+
});
|
12
|
+
if (!response.data.result) {
|
13
|
+
return {
|
14
|
+
error: response.data.message || 'Failed to create order'
|
15
|
+
};
|
16
|
+
}
|
17
|
+
if (!response.data.data) {
|
18
|
+
return {
|
19
|
+
error: 'No order created'
|
20
|
+
};
|
21
|
+
}
|
22
|
+
return {
|
23
|
+
data: response.data.data
|
24
|
+
};
|
25
|
+
} catch (error) {
|
26
|
+
console.error(`Error creating order [${error.code}]: ${error.message}`);
|
27
|
+
return {
|
28
|
+
error: error.message || 'An unknown error occurred'
|
29
|
+
};
|
30
|
+
}
|
31
|
+
}
|
32
|
+
export async function listOrders(accessToken, params = {}) {
|
33
|
+
try {
|
34
|
+
const response = await cjApiClient.get('shopping/order/list', {
|
35
|
+
headers: {
|
36
|
+
'CJ-Access-Token': accessToken
|
37
|
+
},
|
38
|
+
params
|
39
|
+
});
|
40
|
+
if (!response.data.result) {
|
41
|
+
return {
|
42
|
+
error: response.data.message || 'Failed to retrieve orders'
|
43
|
+
};
|
44
|
+
}
|
45
|
+
if (!response.data.data) {
|
46
|
+
return {
|
47
|
+
error: 'No orders found'
|
48
|
+
};
|
49
|
+
}
|
50
|
+
return {
|
51
|
+
data: response.data.data
|
52
|
+
};
|
53
|
+
} catch (error) {
|
54
|
+
console.error(`Error listing orders [${error.code}]: ${error.message}`);
|
55
|
+
return {
|
56
|
+
error: error.message || 'An unknown error occurred'
|
57
|
+
};
|
58
|
+
}
|
59
|
+
}
|
60
|
+
export async function queryOrder(params) {
|
61
|
+
if (!params.orderId && !params.orderNum) {
|
62
|
+
return {
|
63
|
+
error: 'Either orderId or orderNum must be provided.'
|
64
|
+
};
|
65
|
+
}
|
66
|
+
try {
|
67
|
+
const accessToken = await getCurrentAccessToken();
|
68
|
+
const response = await cjApiClient.get('shopping/order/getOrderDetail', {
|
69
|
+
headers: {
|
70
|
+
'CJ-Access-Token': accessToken
|
71
|
+
},
|
72
|
+
params
|
73
|
+
});
|
74
|
+
if (!response.data.result) {
|
75
|
+
return {
|
76
|
+
error: response.data.message || 'Failed to retrieve order details'
|
77
|
+
};
|
78
|
+
}
|
79
|
+
if (!response.data.data) {
|
80
|
+
return {
|
81
|
+
error: 'No order details found'
|
82
|
+
};
|
83
|
+
}
|
84
|
+
return {
|
85
|
+
data: response.data.data
|
86
|
+
};
|
87
|
+
} catch (error) {
|
88
|
+
console.error(`Error querying order [${error.code}]: ${error.message}`);
|
89
|
+
return {
|
90
|
+
error: error.message || 'An unknown error occurred'
|
91
|
+
};
|
92
|
+
}
|
93
|
+
}
|
94
|
+
export async function deleteOrder(orderId) {
|
95
|
+
if (!orderId) {
|
96
|
+
return {
|
97
|
+
error: 'orderId must be provided.'
|
98
|
+
};
|
99
|
+
}
|
100
|
+
try {
|
101
|
+
const accessToken = await getCurrentAccessToken();
|
102
|
+
const response = await cjApiClient.delete('shopping/order/deleteOrder', {
|
103
|
+
headers: {
|
104
|
+
'CJ-Access-Token': accessToken
|
105
|
+
},
|
106
|
+
params: {
|
107
|
+
orderId
|
108
|
+
}
|
109
|
+
});
|
110
|
+
if (!response.data.result) {
|
111
|
+
return {
|
112
|
+
error: response.data.message || 'Failed to delete order'
|
113
|
+
};
|
114
|
+
}
|
115
|
+
if (!response.data.data) {
|
116
|
+
return {
|
117
|
+
error: 'Order deletion not confirmed, no data returned'
|
118
|
+
};
|
119
|
+
}
|
120
|
+
return {
|
121
|
+
data: response.data.data
|
122
|
+
};
|
123
|
+
} catch (error) {
|
124
|
+
console.error(`Error deleting order [${error.code}]: ${error.message}`);
|
125
|
+
return {
|
126
|
+
error: error.message || 'An unknown error occurred'
|
127
|
+
};
|
128
|
+
}
|
129
|
+
}
|
130
|
+
export async function confirmOrder(orderId) {
|
131
|
+
if (!orderId) {
|
132
|
+
return {
|
133
|
+
error: 'orderId must be provided.'
|
134
|
+
};
|
135
|
+
}
|
136
|
+
try {
|
137
|
+
const accessToken = await getCurrentAccessToken();
|
138
|
+
const response = await cjApiClient.patch('shopping/order/confirmOrder', {
|
139
|
+
orderId
|
140
|
+
}, {
|
141
|
+
headers: {
|
142
|
+
'CJ-Access-Token': accessToken,
|
143
|
+
'Content-Type': 'application/json'
|
144
|
+
}
|
145
|
+
});
|
146
|
+
if (!response.data.result) {
|
147
|
+
return {
|
148
|
+
error: response.data.message || 'Failed to confirm order'
|
149
|
+
};
|
150
|
+
}
|
151
|
+
if (!response.data.data) {
|
152
|
+
return {
|
153
|
+
error: 'Order confirmation not confirmed, no data returned'
|
154
|
+
};
|
155
|
+
}
|
156
|
+
return {
|
157
|
+
data: response.data.data
|
158
|
+
};
|
159
|
+
} catch (error) {
|
160
|
+
console.error(`Error confirming order [${error.code}]: ${error.message}`);
|
161
|
+
return {
|
162
|
+
error: error.message || 'An unknown error occurred'
|
163
|
+
};
|
164
|
+
}
|
165
|
+
}
|
166
|
+
|
167
|
+
//# sourceMappingURL=orders.js.map
|