Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions components/wildberries/actions/common/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
export default {
STICKERS_REQUEST_TYPE: [
"code128",
"qr",
],
ORDER_STATUSES: [
{
label: "New order",
value: "0",
},
{
label: "Accepted the order",
value: "1",
},
{
label: "Assembly task completed",
value: "2",
},
{
label: "Assembly order rejected",
value: "3",
},
{
label: "On delivery by courier",
value: "5",
},
{
label: "The client received the goods (courier delivery and pickup)",
value: "6",
},
{
label: "The client did not accept the goods (courier delivery and pickup)",
value: "7",
},
{
label: "Goods for pickup from the store accepted for work",
value: "8",
},
{
label: "Product for self-pickup from the store is ready for pickup",
value: "9",
},
],
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import app from "../../app/wildberries.app";
import constants from "../common/constants";
import { defineAction } from "@pipedream/types";

export default defineAction({
name: "List Order Stickers",
description: "List order stickers. [See docs here](https://suppliers-api.wildberries.ru/swagger/index.html#/Marketplace/post_api_v2_orders_stickers)",
key: "wildberries-list-order-stickers",
version: "0.0.1",
type: "action",
props: {
app,
orderIds: {
propDefinition: [
app,
"orderIds",
],
},
type: {
label: "Type",
type: "string",
description: "Sticker type, default: `code128`.",
default: "code128",
options: constants.STICKERS_REQUEST_TYPE,
},
asPdf: {
type: "boolean",
label: "List as PDF",
description: "Set true for use the PDF API [See docs here](https://suppliers-api.wildberries.ru/swagger/index.html#/Marketplace/post_api_v2_orders_stickers_pdf).",
default: false,
},
},
async run({ $ }) {
const params = {
orderIds: this.orderIds,
type: this.type,
};
const response = await this.app.listOrderStickers($, params, this.asPdf);
$.export("$summary", `Successfully listed stickers for ${this.orderIds.length} orders.`);
return response;
},
});
67 changes: 67 additions & 0 deletions components/wildberries/actions/list-orders/list-orders.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import app from "../../app/wildberries.app";
import { defineAction } from "@pipedream/types";

export default defineAction({
name: "List Orders",
description: "Returns a list of orders. [See docs here](https://suppliers-api.wildberries.ru/swagger/index.html#/Marketplace/get_api_v2_orders)",
key: "wildberries-list-orders",
version: "0.0.1",
type: "action",
props: {
app,
dateStart: {
type: "string",
label: "Starting date",
description: "Starting date for querying in [RFC3339](https://www.rfc-editor.org/rfc/rfc3339) format.",
},
dateEnd: {
type: "string",
label: "Ending date",
description: "Ending date for querying in [RFC3339](https://www.rfc-editor.org/rfc/rfc3339) format.",
optional: true,
},
status: {
propDefinition: [
app,
"status",
],
optional: true,
description: "Select by status",
},
take: {
type: "integer",
label: "Take",
description: "How many records to return at a time.",
default: 10,
},
skip: {
type: "integer",
label: "Skip",
description: "How many records to skip.",
default: 0,
},
orderId: {
propDefinition: [
app,
"orderId",
],
description: "Select by order id",
optional: true,
},
},
async run({ $ }) {
const params = {
date_start: this.dateStart,
date_end: this.dateEnd,
status: typeof (this.status) !== "undefined" ?
parseInt(this.status) :
null,
take: this.take,
skip: this.skip,
id: this.orderId,
};
const response = await this.app.listOrders($, params);
$.export("$summary", `Successfully fetched ${response.orders.length} orders`);
return response;
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import app from "../../app/wildberries.app";
import { defineAction } from "@pipedream/types";

export default defineAction({
name: "Update Order Status",
description: "Update a order status. [See docs here](https://suppliers-api.wildberries.ru/swagger/index.html#/Marketplace/put_api_v2_orders)",
key: "wildberries-update-order-status",
version: "0.0.1",
type: "action",
props: {
app,
orderId: {
propDefinition: [
app,
"orderId",
],
},
status: {
propDefinition: [
app,
"status",
],
},
sgtin: {
type: "any",
label: "SGTIN",
description: "Array required only for pharmaceutical products when they are transferred to status `Customer received the goods`.\n\n**Example:** `[{ code: string, numerator: integer, denominator: integer, sid: integer }]`\n\n[See docs here](https://suppliers-api.wildberries.ru/swagger/index.html#/Marketplace/put_api_v2_orders)",
optional: true,
},
},
async run({ $ }) {
const params = {
orderId: this.orderId,
status: parseInt(this.status),
sgtin: this.sgtin,
};
if (this.sgtin && !Array.isArray(this.sgtin)) {
params.sgtin = [
this.sgtin,
];
}
const response = await this.app.updateOrderStatus($, params);
$.export("$summary", `Successfully updated the status for order: ${this.orderId}`);
return response;
},
});
87 changes: 82 additions & 5 deletions components/wildberries/app/wildberries.app.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,90 @@
import { defineApp } from "@pipedream/types";
import { axios } from "@pipedream/platform";
import constants from "../actions/common/constants";

export default defineApp({
type: "app",
app: "wildberries",
propDefinitions: {},
propDefinitions: {
orderId: {
type: "integer",
label: "Order id",
description: "Set the Order Id.",
},
orderIds: {
type: "integer[]",
label: "Order ids",
description: "Array of order ids.\n\n**Example:**`[8423848, 6436344]`",
},
status: {
label: "Status",
type: "string",
description: "Set the new status of the order.",
options: constants.ORDER_STATUSES,
},
},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
_getBaseUrl() {
return "https://suppliers-api.wildberries.ru/api/v2";
},
_getHeaders() {
return {
"content-type": "application/json",
"Authorization": `Bearer ${this.$auth.api_key}`,
};
},
_getRequestParams(opts) {
return {
...opts,
url: this._getBaseUrl() + opts.path,
headers: this._getHeaders(),
};
},
async listOrders($ = this, params) {
const response = await axios($, this._getRequestParams({
method: "GET",
path: "/orders",
params: this.filterEmptyValues(params),
}));
return response;
},
async updateOrderStatus($ = this, params) {
const response = await axios($, this._getRequestParams({
method: "PUT",
path: "/orders",
data: [
this.filterEmptyValues(params),
],
}));
return response;
},
async listOrderStickers($ = this, params, asPdf) {
let path = "/orders/stickers";
if (asPdf) {
path += "/pdf";
}
const response = await axios($, this._getRequestParams({
method: "POST",
path,
data: this.filterEmptyValues(params),
}));
return response;
},
filterEmptyValues(obj) {
return Object.entries(obj)
.reduce((reduction,
[
key,
value,
]) => {
if (value === undefined || value === null) {
return reduction;
}
return {
...reduction,
[key]: value,
};
}, {});
},
},
});
});
9 changes: 7 additions & 2 deletions components/wildberries/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,16 @@
"pipedream",
"wildberries"
],
"files": ["dist"],
"files": [
"dist"
],
"homepage": "https://pipedream.com/apps/wildberries",
"author": "Pipedream <support@pipedream.com> (https://pipedream.com/)",
"license": "MIT",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^1.1.1"
}
}
}
21 changes: 21 additions & 0 deletions components/wildberries/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"compilerOptions": {
"lib": ["es2020"],
"module": "ES2020",
"target": "ES2020",
"moduleResolution": "node",
"listEmittedFiles": true, // Used as a part of the build task, since we need to pass emitted files to our post-build script
"composite": true,
"outDir": "dist",
"allowSyntheticDefaultImports": true,
},
"allowJs": true,
"include": [
"app",
"actions",
"sources"
],
"exclude": [
"dist",
]
}
5 changes: 4 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.