mashroo3 0.2.0 → 0.4.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/index.d.ts +6 -1
- package/index.js +21 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -4,7 +4,8 @@ export type QueryValue =
|
|
|
4
4
|
| boolean
|
|
5
5
|
| null
|
|
6
6
|
| undefined
|
|
7
|
-
|
|
|
7
|
+
| Record<string, unknown>
|
|
8
|
+
| Array<string | number | boolean | null | undefined | Record<string, unknown>>;
|
|
8
9
|
|
|
9
10
|
export type QueryParams = Record<string, QueryValue>;
|
|
10
11
|
|
|
@@ -40,12 +41,14 @@ export declare class Mashroo3 {
|
|
|
40
41
|
timeoutMs: number;
|
|
41
42
|
catalog: {
|
|
42
43
|
list: (query?: QueryParams) => Promise<any[]>;
|
|
44
|
+
search: (query?: QueryParams) => Promise<{ data: any[]; meta: any }>;
|
|
43
45
|
};
|
|
44
46
|
categories: {
|
|
45
47
|
list: (query?: QueryParams) => Promise<any[]>;
|
|
46
48
|
};
|
|
47
49
|
customers: {
|
|
48
50
|
list: (query?: QueryParams) => Promise<any[]>;
|
|
51
|
+
search: (query?: QueryParams) => Promise<{ data: any[]; meta: any }>;
|
|
49
52
|
create: (payload: unknown) => Promise<any>;
|
|
50
53
|
};
|
|
51
54
|
orders: {
|
|
@@ -58,8 +61,10 @@ export declare class Mashroo3 {
|
|
|
58
61
|
request(method: string, path: string, options?: RequestOptions): Promise<any>;
|
|
59
62
|
|
|
60
63
|
listCatalog(query?: QueryParams): Promise<any[]>;
|
|
64
|
+
searchCatalog(query?: QueryParams): Promise<{ data: any[]; meta: any }>;
|
|
61
65
|
listCategories(query?: QueryParams): Promise<any[]>;
|
|
62
66
|
listCustomers(query?: QueryParams): Promise<any[]>;
|
|
67
|
+
searchCustomers(query?: QueryParams): Promise<{ data: any[]; meta: any }>;
|
|
63
68
|
createCustomer(payload: unknown): Promise<any>;
|
|
64
69
|
listOrders(query?: QueryParams): Promise<any[]>;
|
|
65
70
|
getOrder(orderId: number): Promise<any>;
|
package/index.js
CHANGED
|
@@ -36,6 +36,7 @@ class Mashroo3 {
|
|
|
36
36
|
|
|
37
37
|
this.catalog = {
|
|
38
38
|
list: (query) => this.listCatalog(query),
|
|
39
|
+
search: (query) => this.searchCatalog(query),
|
|
39
40
|
};
|
|
40
41
|
|
|
41
42
|
this.categories = {
|
|
@@ -44,6 +45,7 @@ class Mashroo3 {
|
|
|
44
45
|
|
|
45
46
|
this.customers = {
|
|
46
47
|
list: (query) => this.listCustomers(query),
|
|
48
|
+
search: (query) => this.searchCustomers(query),
|
|
47
49
|
create: (payload) => this.createCustomer(payload),
|
|
48
50
|
};
|
|
49
51
|
|
|
@@ -65,6 +67,14 @@ class Mashroo3 {
|
|
|
65
67
|
return this._extractList(payload, ["products", "catalog", "items"]);
|
|
66
68
|
}
|
|
67
69
|
|
|
70
|
+
async searchCatalog(query = {}) {
|
|
71
|
+
const payload = await this._request("GET", "/api/catalog/search", { query });
|
|
72
|
+
return {
|
|
73
|
+
data: Array.isArray(payload.data) ? payload.data : [],
|
|
74
|
+
meta: payload.meta || {},
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
68
78
|
async listCategories(query = {}) {
|
|
69
79
|
const payload = await this._request("GET", "/api/categories", { query });
|
|
70
80
|
return this._extractList(payload, ["categories", "items"]);
|
|
@@ -75,6 +85,14 @@ class Mashroo3 {
|
|
|
75
85
|
return this._extractList(payload, ["customers", "items"]);
|
|
76
86
|
}
|
|
77
87
|
|
|
88
|
+
async searchCustomers(query = {}) {
|
|
89
|
+
const payload = await this._request("GET", "/api/customers/search", { query });
|
|
90
|
+
return {
|
|
91
|
+
data: Array.isArray(payload.data) ? payload.data : [],
|
|
92
|
+
meta: payload.meta || {},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
78
96
|
async createCustomer(payload) {
|
|
79
97
|
const response = await this._request("POST", "/api/customers", { body: payload });
|
|
80
98
|
const data = this._extractData(response);
|
|
@@ -132,8 +150,10 @@ class Mashroo3 {
|
|
|
132
150
|
if (Array.isArray(value)) {
|
|
133
151
|
for (const item of value) {
|
|
134
152
|
if (item === undefined || item === null) continue;
|
|
135
|
-
url.searchParams.append(key, String(item));
|
|
153
|
+
url.searchParams.append(key, typeof item === "object" ? JSON.stringify(item) : String(item));
|
|
136
154
|
}
|
|
155
|
+
} else if (typeof value === "object") {
|
|
156
|
+
url.searchParams.set(key, JSON.stringify(value));
|
|
137
157
|
} else {
|
|
138
158
|
url.searchParams.set(key, String(value));
|
|
139
159
|
}
|