@porulle/adapter-woocommerce 0.74.4 → 0.75.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/dist/catalog.d.ts +3 -0
- package/dist/catalog.js +3 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/webhooks.js +6 -1
- package/package.json +4 -4
- package/src/catalog.ts +3 -0
- package/src/webhooks.ts +6 -1
package/dist/webhooks.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash, createHmac, timingSafeEqual } from "node:crypto";
|
|
2
|
-
import { Err, Ok } from "@porulle/core";
|
|
2
|
+
import { Err, Ok, toMinorUnits } from "@porulle/core";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { wooProductSchema, wooVariationSchema } from "./catalog.js";
|
|
5
5
|
import { available } from "./inventory.js";
|
|
@@ -93,6 +93,8 @@ const trackingItem = z.object({
|
|
|
93
93
|
});
|
|
94
94
|
const refundSchema = z.object({
|
|
95
95
|
id,
|
|
96
|
+
/** What the merchant refunded, positive, in the store's currency: part of a line is less than the line. */
|
|
97
|
+
amount: z.string().nullish(),
|
|
96
98
|
line_items: z.array(z.object({ product_id: id, variation_id: id, quantity: z.number() })).default([]),
|
|
97
99
|
});
|
|
98
100
|
function meta(entries, key) {
|
|
@@ -176,6 +178,8 @@ export async function orderEvents(client, remoteOrderId) {
|
|
|
176
178
|
const refund = await client.get(`/wc/v3/orders/${encodeURIComponent(order.id)}/refunds/${encodeURIComponent(summary.id)}`, refundSchema);
|
|
177
179
|
if (!refund.ok)
|
|
178
180
|
return refund;
|
|
181
|
+
const currency = order.currency ?? client.credentials.currency;
|
|
182
|
+
const amount = currency ? toMinorUnits(refund.value.data.amount, currency) : undefined;
|
|
179
183
|
events.push({
|
|
180
184
|
kind: "refund.created",
|
|
181
185
|
remoteOrderId: order.id,
|
|
@@ -184,6 +188,7 @@ export async function orderEvents(client, remoteOrderId) {
|
|
|
184
188
|
const quantity = Math.abs(line.quantity);
|
|
185
189
|
return quantity > 0 ? [{ externalVariantId: line.variation_id !== "0" ? line.variation_id : line.product_id, quantity }] : [];
|
|
186
190
|
}),
|
|
191
|
+
...(amount === undefined ? {} : { amount: Math.abs(amount) }),
|
|
187
192
|
});
|
|
188
193
|
}
|
|
189
194
|
return Ok(events);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@porulle/adapter-woocommerce",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.75.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"zod": "^4.1.11",
|
|
19
|
-
"@porulle/core": "0.
|
|
19
|
+
"@porulle/core": "0.75.0"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/node": "^24.5.2",
|
|
@@ -25,8 +25,8 @@
|
|
|
25
25
|
"vitest": "^3.2.4",
|
|
26
26
|
"esbuild": "0.25.12",
|
|
27
27
|
"miniflare": "4.20260722.1",
|
|
28
|
-
"@porulle/
|
|
29
|
-
"@porulle/
|
|
28
|
+
"@porulle/typescript-config": "0.1.0",
|
|
29
|
+
"@porulle/eslint-config": "0.1.0"
|
|
30
30
|
},
|
|
31
31
|
"publishConfig": {
|
|
32
32
|
"access": "public"
|
package/src/catalog.ts
CHANGED
|
@@ -38,6 +38,8 @@ export const wooProductSchema = z.object({
|
|
|
38
38
|
attributes: z.array(z.object({ name: z.string(), position: z.number().nullish(), variation: z.boolean().nullish(), options: z.array(z.string()).default([]) })).default([]),
|
|
39
39
|
tags: z.array(z.object({ slug: z.string().nullish() })).default([]),
|
|
40
40
|
categories: z.array(z.object({ slug: z.string().nullish() })).default([]),
|
|
41
|
+
/** Core since WooCommerce 9.6; absent on older stores. */
|
|
42
|
+
brands: z.array(z.object({ name: z.string() })).default([]),
|
|
41
43
|
variations: z.array(id).default([]),
|
|
42
44
|
manage_stock: z.boolean().nullish(),
|
|
43
45
|
stock_quantity: z.number().nullish(),
|
|
@@ -166,6 +168,7 @@ export function catalogItem(product: WooProduct, variations: WooVariation[], cur
|
|
|
166
168
|
...(options.length > 0 ? { options } : {}),
|
|
167
169
|
tags: product.tags.flatMap((tag) => (tag.slug ? [tag.slug] : [])),
|
|
168
170
|
categories: product.categories.flatMap((category) => (category.slug ? [category.slug] : [])),
|
|
171
|
+
...(product.brands[0] ? { brand: product.brands[0].name } : {}),
|
|
169
172
|
...(itemStatus ? { status: itemStatus } : {}),
|
|
170
173
|
...(product.permalink ? { storefrontUrl: product.permalink } : {}),
|
|
171
174
|
};
|
package/src/webhooks.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash, createHmac, timingSafeEqual } from "node:crypto";
|
|
2
|
-
import { Err, Ok } from "@porulle/core";
|
|
2
|
+
import { Err, Ok, toMinorUnits } from "@porulle/core";
|
|
3
3
|
import type { ChannelConnectorError, ChannelEvent, ChannelShipment, ChannelStore, ChannelWebhookEvent, ChannelWebhookHealth, Result } from "@porulle/core";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import { wooProductSchema, wooVariationSchema } from "./catalog.js";
|
|
@@ -94,6 +94,8 @@ const trackingItem = z.object({
|
|
|
94
94
|
});
|
|
95
95
|
const refundSchema = z.object({
|
|
96
96
|
id,
|
|
97
|
+
/** What the merchant refunded, positive, in the store's currency: part of a line is less than the line. */
|
|
98
|
+
amount: z.string().nullish(),
|
|
97
99
|
line_items: z.array(z.object({ product_id: id, variation_id: id, quantity: z.number() })).default([]),
|
|
98
100
|
});
|
|
99
101
|
|
|
@@ -171,6 +173,8 @@ export async function orderEvents(client: WooClient, remoteOrderId: string): Pro
|
|
|
171
173
|
for (const summary of order.refunds) {
|
|
172
174
|
const refund = await client.get(`/wc/v3/orders/${encodeURIComponent(order.id)}/refunds/${encodeURIComponent(summary.id)}`, refundSchema);
|
|
173
175
|
if (!refund.ok) return refund;
|
|
176
|
+
const currency = order.currency ?? client.credentials.currency;
|
|
177
|
+
const amount = currency ? toMinorUnits(refund.value.data.amount, currency) : undefined;
|
|
174
178
|
events.push({
|
|
175
179
|
kind: "refund.created",
|
|
176
180
|
remoteOrderId: order.id,
|
|
@@ -179,6 +183,7 @@ export async function orderEvents(client: WooClient, remoteOrderId: string): Pro
|
|
|
179
183
|
const quantity = Math.abs(line.quantity);
|
|
180
184
|
return quantity > 0 ? [{ externalVariantId: line.variation_id !== "0" ? line.variation_id : line.product_id, quantity }] : [];
|
|
181
185
|
}),
|
|
186
|
+
...(amount === undefined ? {} : { amount: Math.abs(amount) }),
|
|
182
187
|
});
|
|
183
188
|
}
|
|
184
189
|
return Ok(events);
|