@kizlo/woocommerce 0.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/LICENSE +21 -0
- package/README.md +47 -0
- package/dist/index.d.ts +2599 -0
- package/dist/index.js +1796 -0
- package/dist/test.d.ts +7 -0
- package/dist/test.js +89 -0
- package/package.json +58 -0
package/dist/test.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as kizlo_test0 from "kizlo/test";
|
|
2
|
+
|
|
3
|
+
//#region src/test/index.d.ts
|
|
4
|
+
/** WooCommerce test fixture: installs WooCommerce + the kizlo-woocommerce plugin, seeds products/coupons. */
|
|
5
|
+
declare function woocommerce(): kizlo_test0.Fixture;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { woocommerce };
|
package/dist/test.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { WC_CORE_BASE, WC_STORE_BASE } from "kizlo";
|
|
2
|
+
import { defineFixture, githubRelease } from "kizlo/test";
|
|
3
|
+
|
|
4
|
+
//#region src/test/index.ts
|
|
5
|
+
const PRODUCTS = [
|
|
6
|
+
{
|
|
7
|
+
slug: "test-product-1",
|
|
8
|
+
name: "Test Product 1",
|
|
9
|
+
regular_price: "10"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
slug: "test-product-2",
|
|
13
|
+
name: "Test Product 2",
|
|
14
|
+
regular_price: "20"
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
slug: "test-product-3",
|
|
18
|
+
name: "Test Product 3",
|
|
19
|
+
regular_price: "30"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
slug: "test-product-4",
|
|
23
|
+
name: "Test Product 4",
|
|
24
|
+
regular_price: "40"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
slug: "test-product-5",
|
|
28
|
+
name: "Test Product 5",
|
|
29
|
+
regular_price: "50"
|
|
30
|
+
}
|
|
31
|
+
];
|
|
32
|
+
const COUPONS = [{
|
|
33
|
+
code: "TEST10",
|
|
34
|
+
discount_type: "percent",
|
|
35
|
+
amount: "10"
|
|
36
|
+
}];
|
|
37
|
+
async function upsertProduct(service, product) {
|
|
38
|
+
const existing = await service.get(`${WC_CORE_BASE}/products`, { searchParams: { slug: product.slug } });
|
|
39
|
+
if (existing.data?.[0]) return existing.data[0].id;
|
|
40
|
+
const created = await service.post(`${WC_CORE_BASE}/products`, { body: {
|
|
41
|
+
...product,
|
|
42
|
+
type: "simple",
|
|
43
|
+
status: "publish"
|
|
44
|
+
} });
|
|
45
|
+
if (created.error) throw created.error;
|
|
46
|
+
return created.data.id;
|
|
47
|
+
}
|
|
48
|
+
async function upsertCoupon(service, coupon) {
|
|
49
|
+
if ((await service.get(`${WC_CORE_BASE}/coupons`, { searchParams: { code: coupon.code } })).data?.[0]) return;
|
|
50
|
+
const created = await service.post(`${WC_CORE_BASE}/coupons`, { body: coupon });
|
|
51
|
+
if (created.error) throw created.error;
|
|
52
|
+
}
|
|
53
|
+
/** WooCommerce test fixture: installs WooCommerce + the kizlo-woocommerce plugin, seeds products/coupons. */
|
|
54
|
+
function woocommerce() {
|
|
55
|
+
return defineFixture({
|
|
56
|
+
name: "woocommerce",
|
|
57
|
+
plugins: ["woocommerce", {
|
|
58
|
+
name: "kizlo-woocommerce",
|
|
59
|
+
source: githubRelease("kizlo-io/kizlo-wordpress", "kizlo-woocommerce-v1.0.0-beta.2")
|
|
60
|
+
}],
|
|
61
|
+
async seed({ service }) {
|
|
62
|
+
let productId = 0;
|
|
63
|
+
for (const product of PRODUCTS) {
|
|
64
|
+
const id = await upsertProduct(service, product);
|
|
65
|
+
if (!productId) productId = id;
|
|
66
|
+
}
|
|
67
|
+
for (const coupon of COUPONS) await upsertCoupon(service, coupon);
|
|
68
|
+
return { productId };
|
|
69
|
+
},
|
|
70
|
+
async cleanup({ service, userId }) {
|
|
71
|
+
await deleteAllOrdersFor(service, userId);
|
|
72
|
+
await resetCart(service, userId);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
async function deleteAllOrdersFor(service, customerId) {
|
|
77
|
+
const orders = await service.get(`${WC_CORE_BASE}/orders`, { searchParams: {
|
|
78
|
+
customer: customerId,
|
|
79
|
+
per_page: 100
|
|
80
|
+
} });
|
|
81
|
+
if (!orders.data) return;
|
|
82
|
+
await Promise.all(orders.data.map((o) => service.delete(`${WC_CORE_BASE}/orders/${o.id}`, { searchParams: { force: true } })));
|
|
83
|
+
}
|
|
84
|
+
async function resetCart(service, customerId) {
|
|
85
|
+
await service.delete(`${WC_STORE_BASE}/cart/items`, { headers: { "X-Kizlo-User-Id": String(customerId) } });
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
//#endregion
|
|
89
|
+
export { woocommerce };
|
package/package.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@kizlo/woocommerce",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "WooCommerce extension for Kizlo.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"wordpress",
|
|
8
|
+
"headless",
|
|
9
|
+
"woocommerce",
|
|
10
|
+
"ecommerce",
|
|
11
|
+
"store-api",
|
|
12
|
+
"kizlo"
|
|
13
|
+
],
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"author": "Kizlo",
|
|
16
|
+
"homepage": "https://github.com/kizlo-io/kizlo/tree/main/packages/woocommerce#readme",
|
|
17
|
+
"bugs": "https://github.com/kizlo-io/kizlo/issues",
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "git+https://github.com/kizlo-io/kizlo.git",
|
|
21
|
+
"directory": "packages/woocommerce"
|
|
22
|
+
},
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=22.14.0"
|
|
25
|
+
},
|
|
26
|
+
"main": "./dist/index.js",
|
|
27
|
+
"module": "./dist/index.js",
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
29
|
+
"exports": {
|
|
30
|
+
"./package.json": "./package.json",
|
|
31
|
+
".": {
|
|
32
|
+
"import": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"default": "./dist/index.js"
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
"./test": {
|
|
38
|
+
"import": {
|
|
39
|
+
"types": "./dist/test.d.ts",
|
|
40
|
+
"default": "./dist/test.js"
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
"files": [
|
|
45
|
+
"dist"
|
|
46
|
+
],
|
|
47
|
+
"publishConfig": {
|
|
48
|
+
"access": "public"
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@kizlo/shared": "0.1.0",
|
|
52
|
+
"jose": "6.1.0",
|
|
53
|
+
"zod": "^4.3.6"
|
|
54
|
+
},
|
|
55
|
+
"peerDependencies": {
|
|
56
|
+
"kizlo": ">=0.1.0"
|
|
57
|
+
}
|
|
58
|
+
}
|