@porulle/adapter-woocommerce 0.74.0 → 0.74.2
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/index.js +17 -2
- package/dist/orders.js +4 -3
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/index.ts +16 -2
- package/src/orders.ts +4 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@porulle/adapter-woocommerce",
|
|
3
|
-
"version": "0.74.
|
|
3
|
+
"version": "0.74.2",
|
|
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.74.
|
|
19
|
+
"@porulle/core": "0.74.2"
|
|
20
20
|
},
|
|
21
21
|
"devDependencies": {
|
|
22
22
|
"@types/node": "^24.5.2",
|
package/src/index.ts
CHANGED
|
@@ -3,7 +3,7 @@ import type { ChannelConnector, ChannelConnectorError, ChannelStore, Result } fr
|
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
import { catalogItems, importPage, storeProfile } from "./catalog.js";
|
|
5
5
|
import { pushCatalog, pushCaches } from "./catalog-push.js";
|
|
6
|
-
import { discoverStore, normalizeStoreDomain, wooClient, wooCredentialsSchema } from "./client.js";
|
|
6
|
+
import { discoverStore, normalizeStoreDomain, probeStore, refusedStoreUrl, wooClient, wooCredentialsSchema } from "./client.js";
|
|
7
7
|
import type { WooClient, WooTransportOptions } from "./client.js";
|
|
8
8
|
import { inventoryFor, inventoryPage } from "./inventory.js";
|
|
9
9
|
import { cancelOrder, orderStatus, pushOrder } from "./orders.js";
|
|
@@ -57,6 +57,18 @@ export function wooConnector(options: WooConnectorOptions = {}): ChannelConnecto
|
|
|
57
57
|
capabilities: { importCatalog: true, importInventory: true, pushOrder: true, pushCatalog: true, receiveWebhooks: true },
|
|
58
58
|
webhookTopics: WOO_WEBHOOK_TOPICS,
|
|
59
59
|
normalizeStoreDomain: (input) => normalizeStoreDomain(input, { allowPrivateHosts: transport.allowPrivateHosts }),
|
|
60
|
+
async probeStore(input) {
|
|
61
|
+
const storeDomain = normalizeStoreDomain(input, { allowPrivateHosts: transport.allowPrivateHosts });
|
|
62
|
+
if (!storeDomain) {
|
|
63
|
+
const why = refusedStoreUrl(input);
|
|
64
|
+
return refused(why === "http" ? "WOO_STORE_NOT_HTTPS" : "WOO_INVALID_STORE_DOMAIN", why === "http"
|
|
65
|
+
? "Your store must be served over https (with a valid certificate) to connect."
|
|
66
|
+
: why === "private_host" ? "That address is not a public website." : `"${input}" is not a store address. Enter it like https://shop.example.com.`);
|
|
67
|
+
}
|
|
68
|
+
const probe = await probeStore(transport, storeDomain);
|
|
69
|
+
if (!probe.ok) return refused(`WOO_${probe.error.code.toUpperCase()}`, probe.error.message);
|
|
70
|
+
return Ok({ storeDomain, name: probe.value.name });
|
|
71
|
+
},
|
|
60
72
|
buildAuthUrl(params) {
|
|
61
73
|
const store = normalizeStoreDomain(params.storeDomain, { allowPrivateHosts: transport.allowPrivateHosts });
|
|
62
74
|
if (!store) return refused("WOO_INVALID_STORE_DOMAIN", "A WooCommerce store is named by its https address.");
|
|
@@ -66,7 +78,9 @@ export function wooConnector(options: WooConnectorOptions = {}): ChannelConnecto
|
|
|
66
78
|
} catch {
|
|
67
79
|
return refused("WOO_INVALID_CALLBACK_URL", "WooCommerce needs an https callback address.");
|
|
68
80
|
}
|
|
69
|
-
|
|
81
|
+
// WooCommerce itself refuses an http callback ("needs to be over SSL"); only a stand-in on this machine takes one.
|
|
82
|
+
const localCallback = transport.allowPrivateHosts && ["127.0.0.1", "localhost"].includes(callback.hostname);
|
|
83
|
+
if (callback.protocol !== "https:" && !localCallback) return refused("WOO_INVALID_CALLBACK_URL", "WooCommerce needs an https callback address.");
|
|
70
84
|
callback.searchParams.set("state", params.state);
|
|
71
85
|
const returnUrl = new URL(params.callbackUri);
|
|
72
86
|
returnUrl.searchParams.set("state", params.state);
|
package/src/orders.ts
CHANGED
|
@@ -156,9 +156,10 @@ export async function pushOrder(client: WooClient, slice: ChannelOrderSlice, opt
|
|
|
156
156
|
const draftId = draft && typeof draft === "object" && "new_draft_order_id" in draft ? z.coerce.number().int().positive().safeParse(draft.new_draft_order_id) : undefined;
|
|
157
157
|
// A refusal can leave a checkout-draft behind; it is ours, so it goes.
|
|
158
158
|
if (draftId?.success) await client.send("DELETE", `/wc/v3/orders/${draftId.data}`, undefined, z.unknown(), { force: "true" });
|
|
159
|
-
// A 4xx is the store's answer. Anything else
|
|
160
|
-
// order: retriable, and the next
|
|
161
|
-
|
|
159
|
+
// A 4xx WooCommerce explained (its JSON error) is the store's answer. Anything else — a timeout,
|
|
160
|
+
// a 5xx, a firewall's page — may or may not have created the order: retriable, and the next
|
|
161
|
+
// attempt looks for it before creating anything.
|
|
162
|
+
const answered = error.status !== undefined && error.status >= 400 && error.status < 500 && error.body !== undefined;
|
|
162
163
|
return Err({ code: answered ? "WOO_ORDER_REJECTED" : error.code, message: answered ? `WooCommerce refused the order: ${error.message}` : `The store's answer to the order was lost (${error.message}); it is looked for before trying again.`, retriable: !answered });
|
|
163
164
|
}
|
|
164
165
|
const order = created.value;
|