@porulle/adapter-woocommerce 0.74.0 → 0.74.1
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/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/index.ts +16 -2
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { defineChannelConnector, Err, Ok } from "@porulle/core";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { catalogItems, importPage, storeProfile } from "./catalog.js";
|
|
4
4
|
import { pushCatalog, pushCaches } from "./catalog-push.js";
|
|
5
|
-
import { discoverStore, normalizeStoreDomain, wooClient, wooCredentialsSchema } from "./client.js";
|
|
5
|
+
import { discoverStore, normalizeStoreDomain, probeStore, refusedStoreUrl, wooClient, wooCredentialsSchema } from "./client.js";
|
|
6
6
|
import { inventoryFor, inventoryPage } from "./inventory.js";
|
|
7
7
|
import { cancelOrder, orderStatus, pushOrder } from "./orders.js";
|
|
8
8
|
import { decodeDelivery, orderEvents, registerWebhooks, unregisterWebhooks, verifyDelivery, webhookHealth, WOO_WEBHOOK_TOPICS } from "./webhooks.js";
|
|
@@ -35,6 +35,19 @@ export function wooConnector(options = {}) {
|
|
|
35
35
|
capabilities: { importCatalog: true, importInventory: true, pushOrder: true, pushCatalog: true, receiveWebhooks: true },
|
|
36
36
|
webhookTopics: WOO_WEBHOOK_TOPICS,
|
|
37
37
|
normalizeStoreDomain: (input) => normalizeStoreDomain(input, { allowPrivateHosts: transport.allowPrivateHosts }),
|
|
38
|
+
async probeStore(input) {
|
|
39
|
+
const storeDomain = normalizeStoreDomain(input, { allowPrivateHosts: transport.allowPrivateHosts });
|
|
40
|
+
if (!storeDomain) {
|
|
41
|
+
const why = transport.allowPrivateHosts ? undefined : refusedStoreUrl(input);
|
|
42
|
+
return refused(why === "http" ? "WOO_STORE_NOT_HTTPS" : "WOO_INVALID_STORE_DOMAIN", why === "http"
|
|
43
|
+
? "Your store must be served over https (with a valid certificate) to connect."
|
|
44
|
+
: why === "private_host" ? "That address is not a public website." : `"${input}" is not a store address. Enter it like https://shop.example.com.`);
|
|
45
|
+
}
|
|
46
|
+
const probe = await probeStore(transport, storeDomain);
|
|
47
|
+
if (!probe.ok)
|
|
48
|
+
return refused(`WOO_${probe.error.code.toUpperCase()}`, probe.error.message);
|
|
49
|
+
return Ok({ storeDomain, name: probe.value.name });
|
|
50
|
+
},
|
|
38
51
|
buildAuthUrl(params) {
|
|
39
52
|
const store = normalizeStoreDomain(params.storeDomain, { allowPrivateHosts: transport.allowPrivateHosts });
|
|
40
53
|
if (!store)
|
|
@@ -46,7 +59,9 @@ export function wooConnector(options = {}) {
|
|
|
46
59
|
catch {
|
|
47
60
|
return refused("WOO_INVALID_CALLBACK_URL", "WooCommerce needs an https callback address.");
|
|
48
61
|
}
|
|
49
|
-
|
|
62
|
+
// WooCommerce itself refuses an http callback ("needs to be over SSL"); only a stand-in on this machine takes one.
|
|
63
|
+
const localCallback = transport.allowPrivateHosts && ["127.0.0.1", "localhost"].includes(callback.hostname);
|
|
64
|
+
if (callback.protocol !== "https:" && !localCallback)
|
|
50
65
|
return refused("WOO_INVALID_CALLBACK_URL", "WooCommerce needs an https callback address.");
|
|
51
66
|
callback.searchParams.set("state", params.state);
|
|
52
67
|
const returnUrl = new URL(params.callbackUri);
|