@kizlo/woocommerce 0.3.0 → 0.5.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/test.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as kizlo18 from "kizlo";
1
+ import * as kizlo19 from "kizlo";
2
2
  import { DevPluginSource } from "kizlo/test";
3
3
 
4
4
  //#region src/test/index.d.ts
@@ -10,6 +10,6 @@ import { DevPluginSource } from "kizlo/test";
10
10
  */
11
11
  declare function woocommerce(opts?: {
12
12
  plugins?: DevPluginSource[];
13
- }): kizlo18.Fixture;
13
+ }): kizlo19.Fixture;
14
14
  //#endregion
15
15
  export { woocommerce };
package/dist/test.js CHANGED
@@ -62,6 +62,45 @@ async function upsertProduct(service, product) {
62
62
  if (created.error) throw created.error;
63
63
  return created.data.id;
64
64
  }
65
+ async function upsertVariableProduct(service) {
66
+ const slug = "test-product-variable";
67
+ let productId = (await service.get(`${WC_CORE_BASE}/products`, { searchParams: { slug } })).data?.[0]?.id;
68
+ if (!productId) {
69
+ const created = await service.post(`${WC_CORE_BASE}/products`, { body: {
70
+ name: "Test Product Variable",
71
+ slug,
72
+ type: "variable",
73
+ status: "publish",
74
+ attributes: [{
75
+ name: "Size",
76
+ visible: true,
77
+ variation: true,
78
+ options: ["Small", "Large"]
79
+ }]
80
+ } });
81
+ if (created.error) throw created.error;
82
+ productId = created.data.id;
83
+ }
84
+ const existingVariation = (await service.get(`${WC_CORE_BASE}/products/${productId}/variations`, { searchParams: { per_page: 100 } })).data?.find((variation) => variation.sku === "TEST-VARIATION-LARGE");
85
+ if (existingVariation) return {
86
+ productId,
87
+ variationId: existingVariation.id
88
+ };
89
+ const createdVariation = await service.post(`${WC_CORE_BASE}/products/${productId}/variations`, { body: {
90
+ regular_price: "15",
91
+ sku: "TEST-VARIATION-LARGE",
92
+ status: "publish",
93
+ attributes: [{
94
+ name: "Size",
95
+ option: "Large"
96
+ }]
97
+ } });
98
+ if (createdVariation.error) throw createdVariation.error;
99
+ return {
100
+ productId,
101
+ variationId: createdVariation.data.id
102
+ };
103
+ }
65
104
  async function upsertCoupon(service, coupon) {
66
105
  if ((await service.get(`${WC_CORE_BASE}/coupons`, { searchParams: { code: coupon.code } })).data?.[0]) return;
67
106
  const created = await service.post(`${WC_CORE_BASE}/coupons`, { body: coupon });
@@ -100,6 +139,29 @@ async function enableBankTransfer(service) {
100
139
  const updated = await service.put(`${WC_CORE_BASE}/payment_gateways/bacs`, { body: { enabled: true } });
101
140
  if (updated.error) throw updated.error;
102
141
  }
142
+ async function enableFlatRate(service) {
143
+ let zoneId = (await service.get(`${WC_CORE_BASE}/shipping/zones`, {})).data?.find((zone) => zone.name === "Kizlo Test Zone")?.id;
144
+ if (!zoneId) {
145
+ const created = await service.post(`${WC_CORE_BASE}/shipping/zones`, { body: {
146
+ name: "Kizlo Test Zone",
147
+ order: 0
148
+ } });
149
+ if (created.error) throw created.error;
150
+ zoneId = created.data.id;
151
+ }
152
+ const locations = await service.put(`${WC_CORE_BASE}/shipping/zones/${zoneId}/locations`, { body: [{
153
+ code: "US",
154
+ type: "country"
155
+ }] });
156
+ if (locations.error) throw locations.error;
157
+ if ((await service.get(`${WC_CORE_BASE}/shipping/zones/${zoneId}/methods`, {})).data?.some((method) => method.method_id === "flat_rate")) return;
158
+ const createdMethod = await service.post(`${WC_CORE_BASE}/shipping/zones/${zoneId}/methods`, { body: {
159
+ method_id: "flat_rate",
160
+ enabled: true,
161
+ settings: { cost: "5" }
162
+ } });
163
+ if (createdMethod.error) throw createdMethod.error;
164
+ }
103
165
  /**
104
166
  * WooCommerce bundles Action Scheduler, which keeps its actions in the posts table until it
105
167
  * migrates to its own tables, and registers two global post statuses (`in-progress`, `failed`)
@@ -140,8 +202,10 @@ function woocommerce(opts = {}) {
140
202
  }
141
203
  if (productIds[0]) await linkProductCategory(service, productIds[0]);
142
204
  await linkRecommendations(service, productIds);
205
+ await upsertVariableProduct(service);
143
206
  for (const coupon of COUPONS) await upsertCoupon(service, coupon);
144
207
  await enableBankTransfer(service);
208
+ await enableFlatRate(service);
145
209
  return { productId };
146
210
  },
147
211
  async cleanup({ service, userId }) {
@@ -159,7 +223,9 @@ async function deleteAllOrdersFor(service, customerId) {
159
223
  await Promise.all(orders.data.map((o) => service.delete(`${WC_CORE_BASE}/orders/${o.id}`, { searchParams: { force: true } })));
160
224
  }
161
225
  async function resetCart(service, customerId) {
162
- await service.delete(`${WC_STORE_BASE}/cart/items`, { headers: { "X-Kizlo-User-Id": String(customerId) } });
226
+ const email = (await service.get(`${WC_CORE_BASE}/customers/${customerId}`, {})).data?.email;
227
+ if (!email) return;
228
+ await service.delete(`${WC_STORE_BASE}/cart/items`, { headers: { "X-Kizlo-User-Email": email } });
163
229
  }
164
230
 
165
231
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kizlo/woocommerce",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "type": "module",
5
5
  "sideEffects": false,
6
6
  "description": "WooCommerce integration for Kizlo.",