@zerodot/woocommerce 1.0.0 → 1.1.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/README.md +1 -0
- package/dist/index.cjs +86 -24
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -25,6 +25,7 @@ Details:
|
|
|
25
25
|
- **Customer** create and update take billing and shipping addresses, names, and metadata. Create also takes a username and a password. **Get Many** filters by email and sorts.
|
|
26
26
|
- **Product** create and update take the price, stock, status, type, sale dates, SKU, slug, descriptions, and more. **Dimensions**, **Images**, and **Metadata** are separate fields. **Categories**, **Tags**, **Cross Sell IDs**, and **Upsell IDs** are IDs with commas between, such as `12,15`. **Get Many** has the filters of the products list (search, SKU, category, tag, price range, status, stock status, and more).
|
|
27
27
|
- **Order** create and update take **Billing**, **Shipping**, **Coupon Lines**, **Fee Lines**, **Line Items**, **Shipping Lines**, and **Metadata**. Create also has **Set Paid**. **Get Many** filters by customer, product, status, dates, and search.
|
|
28
|
+
- **Category** and **Tag** fields (Product create, update, and get many) load their options from the store (`GET /products/categories`, `GET /products/tags`). You can also type IDs. The old text fields in the collections still work.
|
|
28
29
|
- A date is ISO 8601, such as `2025-01-31T10:00:00`.
|
|
29
30
|
|
|
30
31
|
When WooCommerce gives an error, the node fails with the message and the code of WooCommerce.
|
package/dist/index.cjs
CHANGED
|
@@ -125,7 +125,7 @@ async function callWooList(access, call, limit, options) {
|
|
|
125
125
|
// src/icon.ts
|
|
126
126
|
const WOOCOMMERCE_ICON = (0, _zerodot_node_sdk.fileIcon)(require("url").pathToFileURL(__filename).href, "../woocommerce.svg");
|
|
127
127
|
// src/credential.ts
|
|
128
|
-
const TIMEOUT_MS$
|
|
128
|
+
const TIMEOUT_MS$2 = 1e4;
|
|
129
129
|
const woocommerceCredential = {
|
|
130
130
|
type: WOOCOMMERCE_CREDENTIAL,
|
|
131
131
|
label: "WooCommerce API",
|
|
@@ -162,8 +162,8 @@ const woocommerceCredential = {
|
|
|
162
162
|
path: "/products/categories",
|
|
163
163
|
query: { per_page: 1 }
|
|
164
164
|
}, {
|
|
165
|
-
signal: AbortSignal.timeout(TIMEOUT_MS$
|
|
166
|
-
timeoutMs: TIMEOUT_MS$
|
|
165
|
+
signal: AbortSignal.timeout(TIMEOUT_MS$2),
|
|
166
|
+
timeoutMs: TIMEOUT_MS$2
|
|
167
167
|
});
|
|
168
168
|
}
|
|
169
169
|
};
|
|
@@ -209,6 +209,13 @@ const on = (resources, operations) => ({ showWhen: {
|
|
|
209
209
|
} });
|
|
210
210
|
const ISO_HINT = "A date and time as ISO 8601, such as 2025-01-31T10:00:00";
|
|
211
211
|
const IDS_HINT = "IDs with commas between, such as 12,15";
|
|
212
|
+
/** The meta of a field that loads its options from the store, with a search in the store. */
|
|
213
|
+
const loads = (loadOptions) => ({
|
|
214
|
+
loadOptions,
|
|
215
|
+
searchable: true
|
|
216
|
+
});
|
|
217
|
+
/** A list of IDs from the store. Old workflows have text with commas, such as "12,15". */
|
|
218
|
+
const idList = zod.z.union([zod.z.array(zod.z.string()), zod.z.string()]);
|
|
212
219
|
const sortLabels = {
|
|
213
220
|
asc: "ASC",
|
|
214
221
|
desc: "DESC"
|
|
@@ -233,11 +240,17 @@ const customerAddress = zod.z.object({
|
|
|
233
240
|
phone: zod.z.string()
|
|
234
241
|
}).partial();
|
|
235
242
|
const customerUpdateFields = zod.z.object({
|
|
236
|
-
billing: customerAddress.meta({
|
|
243
|
+
billing: customerAddress.meta({
|
|
244
|
+
title: "Billing Address",
|
|
245
|
+
ui: "collection"
|
|
246
|
+
}),
|
|
237
247
|
first_name: zod.z.string(),
|
|
238
248
|
last_name: zod.z.string(),
|
|
239
249
|
meta_data: zod.z.array(metaPair).meta({ title: "Metadata" }),
|
|
240
|
-
shipping: customerAddress.meta({
|
|
250
|
+
shipping: customerAddress.meta({
|
|
251
|
+
title: "Shipping Address",
|
|
252
|
+
ui: "collection"
|
|
253
|
+
})
|
|
241
254
|
}).partial();
|
|
242
255
|
const customerCreateFields = customerUpdateFields.extend({
|
|
243
256
|
password: zod.z.string(),
|
|
@@ -268,9 +281,10 @@ const productFields = {
|
|
|
268
281
|
search: "Search",
|
|
269
282
|
hidden: "Hidden"
|
|
270
283
|
} }),
|
|
271
|
-
categories:
|
|
272
|
-
title: "Category IDs",
|
|
273
|
-
description:
|
|
284
|
+
categories: idList.meta({
|
|
285
|
+
title: "Category Names or IDs",
|
|
286
|
+
description: "The categories of the product",
|
|
287
|
+
...loads("categories")
|
|
274
288
|
}),
|
|
275
289
|
crossSellIds: zod.z.string().meta({
|
|
276
290
|
title: "Cross Sell IDs",
|
|
@@ -326,9 +340,10 @@ const productFields = {
|
|
|
326
340
|
},
|
|
327
341
|
description: "Controls the stock status of the product"
|
|
328
342
|
}),
|
|
329
|
-
tags:
|
|
330
|
-
title: "Tag IDs",
|
|
331
|
-
description:
|
|
343
|
+
tags: idList.meta({
|
|
344
|
+
title: "Tag Names or IDs",
|
|
345
|
+
description: "The tags of the product",
|
|
346
|
+
...loads("tags")
|
|
332
347
|
}),
|
|
333
348
|
taxClass: zod.z.string(),
|
|
334
349
|
taxStatus: zod.z.enum([
|
|
@@ -498,8 +513,9 @@ const productOptions = zod.z.object({
|
|
|
498
513
|
after: zod.z.string().meta({ description: `Only products published after this time. ${ISO_HINT}` }),
|
|
499
514
|
before: zod.z.string().meta({ description: `Only products published before this time. ${ISO_HINT}` }),
|
|
500
515
|
category: zod.z.string().meta({
|
|
501
|
-
title: "Category ID",
|
|
502
|
-
description: "Limit result set to products assigned a specific category ID"
|
|
516
|
+
title: "Category Name or ID",
|
|
517
|
+
description: "Limit result set to products assigned a specific category ID",
|
|
518
|
+
...loads("categories")
|
|
503
519
|
}),
|
|
504
520
|
context: zod.z.enum([
|
|
505
521
|
"view",
|
|
@@ -567,8 +583,9 @@ const productOptions = zod.z.object({
|
|
|
567
583
|
description: "Controls the stock status of the product"
|
|
568
584
|
}),
|
|
569
585
|
tag: zod.z.string().meta({
|
|
570
|
-
title: "Tag ID",
|
|
571
|
-
description: "Limit result set to products assigned a specific tag ID"
|
|
586
|
+
title: "Tag Name or ID",
|
|
587
|
+
description: "Limit result set to products assigned a specific tag ID",
|
|
588
|
+
...loads("tags")
|
|
572
589
|
}),
|
|
573
590
|
taxClass: zod.z.enum([
|
|
574
591
|
"standard",
|
|
@@ -680,15 +697,18 @@ const woocommerceConfig = zod.z.object({
|
|
|
680
697
|
}),
|
|
681
698
|
customerAdditionalFields: customerCreateFields.default({}).meta({
|
|
682
699
|
...on(["customer"], ["create"]),
|
|
683
|
-
title: "Additional Fields"
|
|
700
|
+
title: "Additional Fields",
|
|
701
|
+
ui: "collection"
|
|
684
702
|
}),
|
|
685
703
|
customerUpdateFields: customerUpdateFields.default({}).meta({
|
|
686
704
|
...on(["customer"], ["update"]),
|
|
687
|
-
title: "Update Fields"
|
|
705
|
+
title: "Update Fields",
|
|
706
|
+
ui: "collection"
|
|
688
707
|
}),
|
|
689
708
|
customerFilters: customerFilters.default({}).meta({
|
|
690
709
|
...on(["customer"], ["getAll"]),
|
|
691
|
-
title: "Filters"
|
|
710
|
+
title: "Filters",
|
|
711
|
+
ui: "collection"
|
|
692
712
|
}),
|
|
693
713
|
name: zod.z.string().optional().meta({
|
|
694
714
|
...on(["product"], ["create"]),
|
|
@@ -705,11 +725,13 @@ const woocommerceConfig = zod.z.object({
|
|
|
705
725
|
}),
|
|
706
726
|
productAdditionalFields: productCreateFields.default({}).meta({
|
|
707
727
|
...on(["product"], ["create"]),
|
|
708
|
-
title: "Additional Fields"
|
|
728
|
+
title: "Additional Fields",
|
|
729
|
+
ui: "collection"
|
|
709
730
|
}),
|
|
710
731
|
productUpdateFields: productUpdateFields.default({}).meta({
|
|
711
732
|
...on(["product"], ["update"]),
|
|
712
|
-
title: "Update Fields"
|
|
733
|
+
title: "Update Fields",
|
|
734
|
+
ui: "collection"
|
|
713
735
|
}),
|
|
714
736
|
dimensions: dimensions.optional().meta({
|
|
715
737
|
...productWrite,
|
|
@@ -721,7 +743,8 @@ const woocommerceConfig = zod.z.object({
|
|
|
721
743
|
}),
|
|
722
744
|
productOptions: productOptions.default({}).meta({
|
|
723
745
|
...on(["product"], ["getAll"]),
|
|
724
|
-
title: "Options"
|
|
746
|
+
title: "Options",
|
|
747
|
+
ui: "collection"
|
|
725
748
|
}),
|
|
726
749
|
orderId: zod.z.string().optional().meta({
|
|
727
750
|
...on(["order"], [
|
|
@@ -734,11 +757,13 @@ const woocommerceConfig = zod.z.object({
|
|
|
734
757
|
}),
|
|
735
758
|
orderAdditionalFields: orderCreateFields.default({}).meta({
|
|
736
759
|
...on(["order"], ["create"]),
|
|
737
|
-
title: "Additional Fields"
|
|
760
|
+
title: "Additional Fields",
|
|
761
|
+
ui: "collection"
|
|
738
762
|
}),
|
|
739
763
|
orderUpdateFields: orderUpdateFields.default({}).meta({
|
|
740
764
|
...on(["order"], ["update"]),
|
|
741
|
-
title: "Update Fields"
|
|
765
|
+
title: "Update Fields",
|
|
766
|
+
ui: "collection"
|
|
742
767
|
}),
|
|
743
768
|
billing: billingAddress.optional().meta({
|
|
744
769
|
...orderWrite,
|
|
@@ -777,7 +802,8 @@ const woocommerceConfig = zod.z.object({
|
|
|
777
802
|
}),
|
|
778
803
|
orderOptions: orderOptions.default({}).meta({
|
|
779
804
|
...on(["order"], ["getAll"]),
|
|
780
|
-
title: "Options"
|
|
805
|
+
title: "Options",
|
|
806
|
+
ui: "collection"
|
|
781
807
|
}),
|
|
782
808
|
returnAll: zod.z.boolean().default(false).meta({
|
|
783
809
|
...on(RESOURCES, ["getAll"]),
|
|
@@ -793,6 +819,41 @@ const woocommerceConfig = zod.z.object({
|
|
|
793
819
|
}),
|
|
794
820
|
timeoutMs: zod.z.number().int().min(1).max(3e5).default(3e4)
|
|
795
821
|
});
|
|
822
|
+
// src/loaders.ts
|
|
823
|
+
const TIMEOUT_MS$1 = 15e3;
|
|
824
|
+
/**
|
|
825
|
+
* The names and IDs of the items of a list of the store. The editor shows the name and keeps
|
|
826
|
+
* the ID. The cursor is the page number. WooCommerce searches with `search`.
|
|
827
|
+
*/
|
|
828
|
+
async function loadNamed(path, ctx) {
|
|
829
|
+
const access = wooAccess(ctx.credential);
|
|
830
|
+
const page = Number(ctx.cursor) > 0 ? Number(ctx.cursor) : 1;
|
|
831
|
+
const answer = await callWoo(access, {
|
|
832
|
+
method: "GET",
|
|
833
|
+
path,
|
|
834
|
+
query: {
|
|
835
|
+
per_page: 100,
|
|
836
|
+
page,
|
|
837
|
+
search: ctx.search?.trim() || void 0
|
|
838
|
+
}
|
|
839
|
+
}, {
|
|
840
|
+
signal: ctx.signal,
|
|
841
|
+
timeoutMs: TIMEOUT_MS$1
|
|
842
|
+
});
|
|
843
|
+
const items = Array.isArray(answer) ? answer : [];
|
|
844
|
+
return {
|
|
845
|
+
options: items.filter((item) => typeof item.id === "number").map((item) => ({
|
|
846
|
+
label: typeof item.name === "string" && item.name ? item.name : String(item.id),
|
|
847
|
+
value: String(item.id)
|
|
848
|
+
})),
|
|
849
|
+
nextCursor: items.length === 100 ? String(page + 1) : null
|
|
850
|
+
};
|
|
851
|
+
}
|
|
852
|
+
/** The loaders of the node. Both read the lists of the product catalog. */
|
|
853
|
+
const loaders = {
|
|
854
|
+
categories: (ctx) => loadNamed("/products/categories", ctx),
|
|
855
|
+
tags: (ctx) => loadNamed("/products/tags", ctx)
|
|
856
|
+
};
|
|
796
857
|
// src/request.ts
|
|
797
858
|
const need = (value, name, operation) => {
|
|
798
859
|
if (value === void 0 || typeof value === "string" && value.trim() === "") throw new Error(`WooCommerce ${operation} needs "${name}"`);
|
|
@@ -1145,6 +1206,7 @@ var node_default = (0, _zerodot_node_sdk.defineNode)({
|
|
|
1145
1206
|
icon: "ShoppingCart01Icon",
|
|
1146
1207
|
iconUrl: WOOCOMMERCE_ICON,
|
|
1147
1208
|
config: woocommerceConfig,
|
|
1209
|
+
loadOptions: loaders,
|
|
1148
1210
|
defaultConfig: {
|
|
1149
1211
|
resource: "product",
|
|
1150
1212
|
operation: "create",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zerodot/woocommerce",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Manage WooCommerce customers, orders, and products, and start a workflow when a coupon, customer, order, or product is created, updated, or deleted. Use it for store sync and order automation.",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"repository": {
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"woocommerce.svg"
|
|
22
22
|
],
|
|
23
23
|
"zerodot": {
|
|
24
|
-
"sdk": "^1.
|
|
24
|
+
"sdk": "^1.7",
|
|
25
25
|
"label": "WooCommerce",
|
|
26
26
|
"summary": "Customers, orders, products, and store events"
|
|
27
27
|
},
|
|
@@ -30,12 +30,12 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@zerodot/node-sdk": "^1.
|
|
33
|
+
"@zerodot/node-sdk": "^1.7.0",
|
|
34
34
|
"zod": "^4.0.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@types/node": "26.6.5",
|
|
38
|
-
"@zerodot/node-sdk": "^1.
|
|
38
|
+
"@zerodot/node-sdk": "^1.7.0",
|
|
39
39
|
"tsdown": "0.23.2",
|
|
40
40
|
"tsx": "4.23.15",
|
|
41
41
|
"typescript": "7.0.2",
|