qarpeo 0.2.1 → 0.3.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.
Files changed (260) hide show
  1. package/dist/chunks/tools.mjs +993 -31
  2. package/dist/cli/index.mjs +1071 -31
  3. package/dist/fate/index.d.ts +9 -1
  4. package/dist/fate/index.mjs +20 -3
  5. package/dist/module.mjs +292 -748
  6. package/dist/runtime/browser.mjs +2 -2
  7. package/dist/runtime/comments-server.d.ts +3 -0
  8. package/dist/runtime/comments-server.mjs +2 -0
  9. package/dist/runtime/comments.d.ts +0 -2
  10. package/dist/runtime/comments.mjs +0 -2
  11. package/dist/runtime/db.d.ts +10 -9
  12. package/dist/runtime/db.mjs +79 -8
  13. package/dist/runtime/drizzle.mjs +21 -6
  14. package/dist/runtime/index.d.ts +4 -0
  15. package/dist/runtime/realtime-server.d.ts +4 -0
  16. package/dist/runtime/realtime-server.mjs +13 -0
  17. package/dist/runtime/realtime.d.ts +1 -4
  18. package/dist/runtime/realtime.mjs +0 -13
  19. package/dist/runtime/replica.d.ts +27 -0
  20. package/dist/runtime/replica.mjs +229 -0
  21. package/dist/runtime/server/durable-objects/agent.mjs +14 -2
  22. package/dist/runtime/server/durable-objects/room.d.ts +10 -0
  23. package/dist/runtime/server/durable-objects/room.mjs +119 -28
  24. package/dist/runtime/server/middleware/devtools.mjs +1 -1
  25. package/dist/runtime/server/middleware/tenancy.mjs +7 -4
  26. package/dist/runtime/server/plugins/store.mjs +1 -1
  27. package/dist/runtime/server/routes/__qarpeo/mail/track/click/[id].get.mjs +57 -17
  28. package/dist/runtime/server/routes/agents/[agent]/chat.post.mjs +19 -12
  29. package/dist/runtime/server/routes/agents/[agent]/clear.post.mjs +8 -9
  30. package/dist/runtime/server/routes/agents/[agent]/history.get.mjs +8 -9
  31. package/dist/runtime/server/routes/analytics/events.get.mjs +12 -2
  32. package/dist/runtime/server/routes/analytics/pageviews.get.mjs +10 -1
  33. package/dist/runtime/server/routes/analytics/summary.get.mjs +10 -1
  34. package/dist/runtime/server/routes/auth/2fa/disable.post.mjs +11 -2
  35. package/dist/runtime/server/routes/auth/2fa/setup.post.mjs +7 -0
  36. package/dist/runtime/server/routes/auth/2fa/verify.post.mjs +11 -2
  37. package/dist/runtime/server/routes/auth/account.delete.mjs +7 -0
  38. package/dist/runtime/server/routes/auth/magic-link/verify.get.mjs +5 -3
  39. package/dist/runtime/server/routes/auth/organization/sso/index.post.mjs +10 -0
  40. package/dist/runtime/server/routes/auth/otp/verify.post.mjs +5 -3
  41. package/dist/runtime/server/routes/auth/sso/saml/acs.post.mjs +18 -0
  42. package/dist/runtime/server/routes/auth/webauthn/login/options.post.d.ts +1 -1
  43. package/dist/runtime/server/routes/auth/webauthn/login/options.post.mjs +11 -2
  44. package/dist/runtime/server/routes/auth/webauthn/login/verify.post.mjs +10 -1
  45. package/dist/runtime/server/routes/auth/webauthn/register/options.post.d.ts +1 -1
  46. package/dist/runtime/server/routes/auth/webauthn/register/options.post.mjs +10 -1
  47. package/dist/runtime/server/routes/auth/webauthn/register/verify.post.mjs +10 -1
  48. package/dist/runtime/server/routes/browser/crawl.post.mjs +13 -0
  49. package/dist/runtime/server/routes/browser/invoice.post.mjs +15 -1
  50. package/dist/runtime/server/routes/browser/og-image.post.mjs +13 -0
  51. package/dist/runtime/server/routes/browser/pdf.post.mjs +15 -1
  52. package/dist/runtime/server/routes/browser/screenshot.post.mjs +13 -0
  53. package/dist/runtime/server/routes/cms/[collection]/[id]/preview-token.post.mjs +23 -8
  54. package/dist/runtime/server/routes/cms/[collection]/[id]/publish.post.mjs +2 -1
  55. package/dist/runtime/server/routes/cms/[collection]/[id]/review.post.mjs +2 -1
  56. package/dist/runtime/server/routes/cms/[collection]/[id]/revisions/[revId]/restore.post.mjs +2 -1
  57. package/dist/runtime/server/routes/cms/[collection]/[id].delete.mjs +2 -1
  58. package/dist/runtime/server/routes/cms/[collection]/[id].put.mjs +2 -1
  59. package/dist/runtime/server/routes/cms/[collection]/index.post.mjs +2 -1
  60. package/dist/runtime/server/routes/cms/categories/[id].delete.mjs +2 -1
  61. package/dist/runtime/server/routes/cms/categories/[id].put.mjs +2 -1
  62. package/dist/runtime/server/routes/cms/categories.post.mjs +2 -1
  63. package/dist/runtime/server/routes/cms/collections/[id].delete.mjs +2 -1
  64. package/dist/runtime/server/routes/cms/collections/[id].put.mjs +2 -1
  65. package/dist/runtime/server/routes/cms/collections/index.post.mjs +2 -1
  66. package/dist/runtime/server/routes/cms/export.post.mjs +1 -1
  67. package/dist/runtime/server/routes/cms/subscribers/[id].delete.mjs +2 -1
  68. package/dist/runtime/server/routes/cms/subscribers/[id].patch.mjs +2 -1
  69. package/dist/runtime/server/routes/cms/tags/[id].delete.mjs +2 -1
  70. package/dist/runtime/server/routes/cms/tags.post.mjs +2 -1
  71. package/dist/runtime/server/routes/comments/[id]/react.post.mjs +7 -3
  72. package/dist/runtime/server/routes/comments/[id]/report.post.mjs +3 -0
  73. package/dist/runtime/server/routes/comments/[id].delete.mjs +1 -1
  74. package/dist/runtime/server/routes/comments/[id].get.mjs +13 -0
  75. package/dist/runtime/server/routes/comments/[id].patch.mjs +1 -1
  76. package/dist/runtime/server/routes/fate.d.ts +6 -0
  77. package/dist/runtime/server/routes/fate.mjs +32 -3
  78. package/dist/runtime/server/routes/mail/bounce.post.mjs +14 -2
  79. package/dist/runtime/server/routes/mail/unsubscribe.mjs +2 -1
  80. package/dist/runtime/server/routes/mail/webhooks.post.mjs +18 -4
  81. package/dist/runtime/server/routes/notifications/[id].get.mjs +3 -4
  82. package/dist/runtime/server/routes/notifications/index.get.mjs +4 -2
  83. package/dist/runtime/server/routes/notifications/push/subscribe.post.mjs +3 -1
  84. package/dist/runtime/server/routes/notifications/push/unsubscribe.post.mjs +5 -3
  85. package/dist/runtime/server/routes/notifications/read-all.post.mjs +6 -2
  86. package/dist/runtime/server/routes/notifications/send.post.mjs +13 -2
  87. package/dist/runtime/server/routes/payments/cancel.post.mjs +1 -1
  88. package/dist/runtime/server/routes/payments/change-plan.post.mjs +1 -1
  89. package/dist/runtime/server/routes/payments/checkout.post.mjs +1 -1
  90. package/dist/runtime/server/routes/payments/pause.post.mjs +1 -1
  91. package/dist/runtime/server/routes/payments/portal.post.mjs +1 -1
  92. package/dist/runtime/server/routes/payments/subscription.get.mjs +1 -1
  93. package/dist/runtime/server/routes/payments/usage.get.mjs +1 -1
  94. package/dist/runtime/server/routes/payments/usage.post.mjs +1 -1
  95. package/dist/runtime/server/routes/payments/webhook.post.mjs +8 -1
  96. package/dist/runtime/server/routes/realtime/broadcast.post.mjs +3 -2
  97. package/dist/runtime/server/routes/realtime/history.delete.mjs +2 -2
  98. package/dist/runtime/server/routes/realtime/history.get.mjs +2 -2
  99. package/dist/runtime/server/routes/realtime/presence.get.mjs +3 -3
  100. package/dist/runtime/server/routes/realtime/state.get.mjs +3 -3
  101. package/dist/runtime/server/routes/realtime/state.post.mjs +13 -4
  102. package/dist/runtime/server/routes/realtime/ws.get.mjs +2 -2
  103. package/dist/runtime/server/routes/storage/file/[...key].delete.mjs +1 -1
  104. package/dist/runtime/server/routes/storage/file/[...key].get.mjs +7 -0
  105. package/dist/runtime/server/routes/storage/files.get.d.ts +1 -1
  106. package/dist/runtime/server/routes/storage/files.get.mjs +24 -4
  107. package/dist/runtime/server/routes/storage/multipart/abort.post.mjs +16 -1
  108. package/dist/runtime/server/routes/storage/multipart/complete.post.d.ts +1 -1
  109. package/dist/runtime/server/routes/storage/multipart/complete.post.mjs +15 -1
  110. package/dist/runtime/server/routes/storage/multipart/create.post.mjs +7 -0
  111. package/dist/runtime/server/routes/storage/multipart/part.put.mjs +15 -1
  112. package/dist/runtime/server/routes/storage/presigned-r2.post.mjs +8 -1
  113. package/dist/runtime/server/routes/storage/presigned.post.d.ts +1 -1
  114. package/dist/runtime/server/routes/storage/presigned.post.mjs +8 -1
  115. package/dist/runtime/server/routes/storage/sign.post.mjs +7 -0
  116. package/dist/runtime/server/routes/storage/upload.post.d.ts +2 -2
  117. package/dist/runtime/server/routes/store/cart/index.delete.mjs +3 -4
  118. package/dist/runtime/server/routes/store/cart/index.get.mjs +3 -10
  119. package/dist/runtime/server/routes/store/cart/items/[id].delete.mjs +6 -4
  120. package/dist/runtime/server/routes/store/cart/items/[id].patch.mjs +12 -4
  121. package/dist/runtime/server/routes/store/cart/items.post.mjs +9 -10
  122. package/dist/runtime/server/routes/store/categories/index.get.mjs +4 -2
  123. package/dist/runtime/server/routes/store/checkout.post.mjs +13 -3
  124. package/dist/runtime/server/routes/store/coupons/apply.post.mjs +6 -5
  125. package/dist/runtime/server/routes/store/orders/[id].get.mjs +2 -2
  126. package/dist/runtime/server/routes/store/orders/download/[token].get.mjs +6 -3
  127. package/dist/runtime/server/routes/store/orders/index.get.mjs +1 -1
  128. package/dist/runtime/server/routes/store/products/[slug].get.mjs +2 -2
  129. package/dist/runtime/server/routes/store/products/index.get.mjs +1 -1
  130. package/dist/runtime/server/routes/store/tax/calculate.post.mjs +10 -0
  131. package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/index.delete.mjs +26 -25
  132. package/dist/runtime/server/routes/tenants/[tenant]/domains/[domain]/verify.post.mjs +26 -25
  133. package/dist/runtime/server/utils/ai.d.ts +6 -0
  134. package/dist/runtime/server/utils/ai.mjs +12 -2
  135. package/dist/runtime/server/utils/analytics-query.mjs +8 -4
  136. package/dist/runtime/server/utils/browser-utils.d.ts +9 -0
  137. package/dist/runtime/server/utils/browser-utils.mjs +135 -0
  138. package/dist/runtime/server/utils/cms/cache.d.ts +13 -0
  139. package/dist/runtime/server/utils/cms/cache.mjs +95 -0
  140. package/dist/runtime/server/utils/cms/common.mjs +1 -1
  141. package/dist/runtime/server/utils/cms/markdown.mjs +38 -8
  142. package/dist/runtime/server/utils/cms/mutations.d.ts +26 -0
  143. package/dist/runtime/server/utils/cms/mutations.mjs +569 -0
  144. package/dist/runtime/server/utils/cms/path.d.ts +8 -0
  145. package/dist/runtime/server/utils/cms/path.mjs +23 -0
  146. package/dist/runtime/server/utils/cms/queries.d.ts +27 -0
  147. package/dist/runtime/server/utils/cms/queries.mjs +366 -0
  148. package/dist/runtime/server/utils/cms/references.d.ts +48 -0
  149. package/dist/runtime/server/utils/cms/references.mjs +309 -0
  150. package/dist/runtime/server/utils/cms/revisions.d.ts +7 -0
  151. package/dist/runtime/server/utils/cms/revisions.mjs +60 -0
  152. package/dist/runtime/server/utils/cms/sync.mjs +3 -3
  153. package/dist/runtime/server/utils/cms.d.ts +5 -82
  154. package/dist/runtime/server/utils/cms.mjs +28 -1367
  155. package/dist/runtime/server/utils/comments.d.ts +11 -0
  156. package/dist/runtime/server/utils/comments.mjs +65 -17
  157. package/dist/runtime/server/utils/crypto.mjs +1 -1
  158. package/dist/runtime/server/utils/domains.mjs +9 -0
  159. package/dist/runtime/server/utils/drizzle.d.ts +26 -1
  160. package/dist/runtime/server/utils/drizzle.mjs +78 -19
  161. package/dist/runtime/server/utils/email-inbound.mjs +9 -1
  162. package/dist/runtime/server/utils/impersonation.mjs +58 -1
  163. package/dist/runtime/server/utils/lock.d.ts +11 -0
  164. package/dist/runtime/server/utils/lock.mjs +4 -0
  165. package/dist/runtime/server/utils/mail-suppression.mjs +48 -13
  166. package/dist/runtime/server/utils/mail.d.ts +2 -1
  167. package/dist/runtime/server/utils/mail.mjs +17 -11
  168. package/dist/runtime/server/utils/notifications.d.ts +13 -4
  169. package/dist/runtime/server/utils/notifications.mjs +20 -4
  170. package/dist/runtime/server/utils/organization.mjs +36 -1
  171. package/dist/runtime/server/utils/passwordless.mjs +8 -0
  172. package/dist/runtime/server/utils/payments/checkout.d.ts +34 -0
  173. package/dist/runtime/server/utils/payments/checkout.mjs +158 -0
  174. package/dist/runtime/server/utils/payments/common.d.ts +45 -0
  175. package/dist/runtime/server/utils/payments/common.mjs +234 -0
  176. package/dist/runtime/server/utils/payments/index.d.ts +9 -0
  177. package/dist/runtime/server/utils/payments/index.mjs +21 -0
  178. package/dist/runtime/server/utils/payments/lemonsqueezy.d.ts +7 -0
  179. package/dist/runtime/server/utils/payments/lemonsqueezy.mjs +55 -0
  180. package/dist/runtime/server/utils/payments/paddle.d.ts +7 -0
  181. package/dist/runtime/server/utils/payments/paddle.mjs +92 -0
  182. package/dist/runtime/server/utils/payments/polar.d.ts +11 -0
  183. package/dist/runtime/server/utils/payments/polar.mjs +66 -0
  184. package/dist/runtime/server/utils/payments/stripe.d.ts +7 -0
  185. package/dist/runtime/server/utils/payments/stripe.mjs +159 -0
  186. package/dist/runtime/server/utils/payments/subscriptions.d.ts +89 -0
  187. package/dist/runtime/server/utils/payments/subscriptions.mjs +236 -0
  188. package/dist/runtime/server/utils/payments/usage.d.ts +12 -0
  189. package/dist/runtime/server/utils/payments/usage.mjs +143 -0
  190. package/dist/runtime/server/utils/payments/webhooks.d.ts +10 -0
  191. package/dist/runtime/server/utils/payments/webhooks.mjs +200 -0
  192. package/dist/runtime/server/utils/payments.d.ts +1 -158
  193. package/dist/runtime/server/utils/payments.mjs +1 -1289
  194. package/dist/runtime/server/utils/queue.d.ts +2 -0
  195. package/dist/runtime/server/utils/queue.mjs +34 -21
  196. package/dist/runtime/server/utils/rag.mjs +30 -17
  197. package/dist/runtime/server/utils/realtime.d.ts +5 -1
  198. package/dist/runtime/server/utils/realtime.mjs +43 -7
  199. package/dist/runtime/server/utils/session.mjs +16 -3
  200. package/dist/runtime/server/utils/sso.d.ts +3 -0
  201. package/dist/runtime/server/utils/sso.mjs +43 -0
  202. package/dist/runtime/server/utils/storage.mjs +12 -1
  203. package/dist/runtime/server/utils/store/cart.d.ts +63 -0
  204. package/dist/runtime/server/utils/store/cart.mjs +542 -0
  205. package/dist/runtime/server/utils/store/checkout.d.ts +14 -0
  206. package/dist/runtime/server/utils/store/checkout.mjs +118 -0
  207. package/dist/runtime/server/utils/store/common.d.ts +29 -0
  208. package/dist/runtime/server/utils/store/common.mjs +479 -0
  209. package/dist/runtime/server/utils/store/index.d.ts +7 -0
  210. package/dist/runtime/server/utils/store/index.mjs +30 -0
  211. package/dist/runtime/server/utils/store/inventory.d.ts +25 -0
  212. package/dist/runtime/server/utils/store/inventory.mjs +190 -0
  213. package/dist/runtime/server/utils/store/orders.d.ts +60 -0
  214. package/dist/runtime/server/utils/store/orders.mjs +590 -0
  215. package/dist/runtime/server/utils/store/products.d.ts +35 -0
  216. package/dist/runtime/server/utils/store/products.mjs +461 -0
  217. package/dist/runtime/server/utils/store/vendor.d.ts +18 -0
  218. package/dist/runtime/server/utils/store/vendor.mjs +68 -0
  219. package/dist/runtime/server/utils/store.d.ts +1 -207
  220. package/dist/runtime/server/utils/store.mjs +1 -2227
  221. package/dist/runtime/server/utils/string.d.ts +1 -1
  222. package/dist/runtime/server/utils/string.mjs +12 -4
  223. package/dist/runtime/server/utils/tenant.mjs +19 -5
  224. package/dist/runtime/server/utils/tracker.mjs +2 -0
  225. package/dist/runtime/server.d.ts +3 -3
  226. package/dist/runtime/server.mjs +4 -4
  227. package/dist/runtime/storage-server.d.ts +2 -0
  228. package/dist/runtime/storage-server.mjs +1 -0
  229. package/dist/runtime/storage.d.ts +1 -1
  230. package/dist/runtime/storage.mjs +0 -1
  231. package/dist/runtime/store.d.ts +0 -1
  232. package/dist/runtime/store.mjs +0 -1
  233. package/dist/runtime/test-utils.d.ts +4 -0
  234. package/dist/runtime/test-utils.mjs +54 -0
  235. package/dist/runtime/types/d1.d.ts +43 -0
  236. package/dist/runtime/types/drizzle.d.ts +6 -0
  237. package/dist/runtime/types/store.d.ts +1 -1
  238. package/dist/types/analytics.d.ts +80 -0
  239. package/dist/types/auth.d.ts +282 -0
  240. package/dist/types/cache.d.ts +55 -0
  241. package/dist/types/comments.d.ts +130 -0
  242. package/dist/types/db.d.ts +29 -0
  243. package/dist/types/email.d.ts +182 -0
  244. package/dist/types/index.d.ts +22 -0
  245. package/dist/types/jobs.d.ts +58 -0
  246. package/dist/types/notifications.d.ts +77 -0
  247. package/dist/types/options.d.ts +363 -0
  248. package/dist/types/payments.d.ts +145 -0
  249. package/dist/types/ratelimit.d.ts +71 -0
  250. package/dist/types/realtime.d.ts +136 -0
  251. package/dist/types/site.d.ts +121 -0
  252. package/dist/types/storage.d.ts +164 -0
  253. package/dist/types/store-options.d.ts +199 -0
  254. package/dist/types/tenant.d.ts +100 -0
  255. package/dist/types.d.ts +1 -2174
  256. package/dist/utils/migration-lock.d.ts +139 -0
  257. package/dist/utils/pkg.d.ts +14 -1
  258. package/dist/utils/schema-diff.d.ts +39 -0
  259. package/package.json +55 -17
  260. package/dist/chunks/auth-schema.mjs +0 -364
@@ -0,0 +1,590 @@
1
+ import { createError } from "nuxt/server";
2
+ import { getAuthContext } from "../context.mjs";
3
+ import { nanoid, signHmacSha256 } from "../crypto.mjs";
4
+ import { getPaymentsConfig } from "../payments/index.mjs";
5
+ import { registerPaymentWebhookListener } from "../payments/common.mjs";
6
+ import {
7
+ getD1,
8
+ getStoreConfig,
9
+ storeProductTbl,
10
+ storeInventoryTbl,
11
+ storeOrderTbl,
12
+ storeOrderItemTbl,
13
+ storeDiscountTbl,
14
+ storeAddressTbl,
15
+ rowToOrderItem,
16
+ rowToOrder,
17
+ rowToAddress
18
+ } from "./common.mjs";
19
+ import { getStoreCart, clearStoreCart, calculateStoreCartTotals } from "./cart.mjs";
20
+ import { commitStoreStock, releaseStoreOrderStock, reserveStoreStock } from "./inventory.mjs";
21
+ function generateOrderNumber() {
22
+ const datePart = (/* @__PURE__ */ new Date()).toISOString().slice(2, 10).replace(/-/g, "");
23
+ const randPart = nanoid(5).toUpperCase();
24
+ return `ORD-${datePart}-${randPart}`;
25
+ }
26
+ export async function createStoreOrder(input, event) {
27
+ const db = getD1(event);
28
+ const ord = storeOrderTbl(event);
29
+ const ordItem = storeOrderItemTbl(event);
30
+ const disc = storeDiscountTbl(event);
31
+ const cart = await getStoreCart(input.cartId, event);
32
+ if (!cart || cart.items.length === 0) {
33
+ throw createError({ statusCode: 400, statusMessage: "Cannot create order from an empty cart." });
34
+ }
35
+ const totals = await calculateStoreCartTotals(cart.id, event);
36
+ const orderId = nanoid();
37
+ const orderNumber = generateOrderNumber();
38
+ const now = Date.now();
39
+ const auth = event ? await getAuthContext(event).catch(() => null) : null;
40
+ const userId = cart.userId ?? auth?.user?.id ?? null;
41
+ const orderItemInserts = cart.items.map((item) => {
42
+ const unitPrice = item.variant?.priceOverride != null ? item.variant.priceOverride : item.product?.basePrice ?? 0;
43
+ const totalPrice = unitPrice * item.quantity;
44
+ const isDigital = item.product?.type === "digital";
45
+ const downloadKey = isDigital ? nanoid(32) : null;
46
+ return db.prepare(
47
+ `INSERT INTO ${ordItem} (
48
+ id, order_id, product_id, variant_id, vendor_id, sku, title,
49
+ unit_price, quantity, total_price, is_digital, download_key,
50
+ metadata_json, created_at
51
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
52
+ ).bind(
53
+ nanoid(),
54
+ orderId,
55
+ item.productId,
56
+ item.variantId,
57
+ item.product?.vendorId ?? null,
58
+ item.variant?.sku || "SKU",
59
+ `${item.product?.title || "Item"} - ${item.variant?.title || ""}`,
60
+ unitPrice,
61
+ item.quantity,
62
+ totalPrice,
63
+ isDigital ? 1 : 0,
64
+ downloadKey,
65
+ JSON.stringify(item.customAttributes || {}),
66
+ now
67
+ );
68
+ });
69
+ const batchStatements = [
70
+ db.prepare(
71
+ `INSERT INTO ${ord} (
72
+ id, tenant_id, order_number, user_id, customer_email, customer_name,
73
+ status, currency, subtotal, tax_total, shipping_total, discount_total,
74
+ total, payment_provider, payment_intent_id,
75
+ shipping_address_json, billing_address_json, metadata_json,
76
+ created_at, updated_at
77
+ ) VALUES (?, ?, ?, ?, ?, ?, 'pending', ?, ?, ?, ?, ?, ?, NULL, NULL, ?, ?, ?, ?, ?)`
78
+ ).bind(
79
+ orderId,
80
+ cart.tenantId ?? null,
81
+ orderNumber,
82
+ userId,
83
+ input.customerEmail,
84
+ input.customerName ?? null,
85
+ totals.currency,
86
+ totals.subtotal,
87
+ totals.taxTotal,
88
+ totals.shippingTotal,
89
+ totals.discountTotal,
90
+ totals.total,
91
+ JSON.stringify(input.shippingAddress || {}),
92
+ JSON.stringify(input.billingAddress || {}),
93
+ JSON.stringify(input.metadata || {}),
94
+ now,
95
+ now
96
+ ),
97
+ ...orderItemInserts
98
+ ];
99
+ if (cart.couponCode) {
100
+ const res = await db.prepare(
101
+ `UPDATE ${disc} SET used_count = used_count + 1, updated_at = ? WHERE UPPER(code) = ? AND (max_uses IS NULL OR used_count < max_uses)`
102
+ ).bind(now, cart.couponCode.toUpperCase()).run();
103
+ const changes = res?.meta?.changes ?? res?.changes ?? 0;
104
+ if (changes === 0) {
105
+ throw createError({
106
+ statusCode: 409,
107
+ statusMessage: "Coupon usage limit has been reached."
108
+ });
109
+ }
110
+ }
111
+ try {
112
+ await db.batch(batchStatements);
113
+ } catch (err) {
114
+ if (cart.couponCode) {
115
+ await db.prepare(
116
+ `UPDATE ${disc} SET used_count = MAX(0, used_count - 1), updated_at = ? WHERE UPPER(code) = ?`
117
+ ).bind(now, cart.couponCode.toUpperCase()).run().catch(() => {
118
+ });
119
+ }
120
+ throw err;
121
+ }
122
+ await reserveStoreStock(cart.id, event).catch(() => {
123
+ });
124
+ await clearStoreCart(cart.id, event).catch(() => {
125
+ });
126
+ return await getStoreOrder(orderId, event);
127
+ }
128
+ export async function getStoreOrder(idOrNumber, event, opts = {}) {
129
+ const db = getD1(event);
130
+ const ord = storeOrderTbl(event);
131
+ const ordItem = storeOrderItemTbl(event);
132
+ let sql = `SELECT * FROM ${ord} WHERE (id = ? OR order_number = ?)`;
133
+ const params = [idOrNumber, idOrNumber];
134
+ if (opts.tenantId !== void 0) {
135
+ sql += " AND tenant_id = ?";
136
+ params.push(opts.tenantId);
137
+ }
138
+ sql += " LIMIT 1";
139
+ const row = await db.prepare(sql).bind(...params).first();
140
+ if (!row) return null;
141
+ const itemRows = await db.prepare(`SELECT * FROM ${ordItem} WHERE order_id = ? ORDER BY created_at ASC`).bind(row.id).all();
142
+ const items = (itemRows.results ?? []).map(rowToOrderItem);
143
+ return rowToOrder(row, items);
144
+ }
145
+ export async function queryStoreOrders(opts = {}, event) {
146
+ const db = getD1(event);
147
+ const ord = storeOrderTbl(event);
148
+ const ordItem = storeOrderItemTbl(event);
149
+ const whereClauses = [];
150
+ const params = [];
151
+ if (opts.tenantId !== void 0) {
152
+ whereClauses.push("tenant_id = ?");
153
+ params.push(opts.tenantId);
154
+ }
155
+ if (opts.userId) {
156
+ whereClauses.push("user_id = ?");
157
+ params.push(opts.userId);
158
+ }
159
+ if (opts.customerEmail) {
160
+ whereClauses.push("customer_email = ?");
161
+ params.push(opts.customerEmail);
162
+ }
163
+ if (opts.status) {
164
+ whereClauses.push("status = ?");
165
+ params.push(opts.status);
166
+ }
167
+ if (opts.vendorId) {
168
+ whereClauses.push(`id IN (SELECT DISTINCT order_id FROM ${ordItem} WHERE vendor_id = ?)`);
169
+ params.push(opts.vendorId);
170
+ }
171
+ const whereSql = whereClauses.length > 0 ? `WHERE ${whereClauses.join(" AND ")}` : "";
172
+ const limit = Math.min(opts.limit ?? 20, 100);
173
+ const offset = opts.offset ?? 0;
174
+ const countResult = await db.prepare(`SELECT COUNT(*) as cnt FROM ${ord} ${whereSql}`).bind(...params).first();
175
+ const total = countResult?.cnt ?? 0;
176
+ if (total === 0) return { orders: [], total: 0 };
177
+ const rows = await db.prepare(`SELECT * FROM ${ord} ${whereSql} ORDER BY created_at DESC LIMIT ? OFFSET ?`).bind(...params, limit, offset).all();
178
+ const orders = (rows.results ?? []).map((r) => rowToOrder(r, []));
179
+ return { orders, total };
180
+ }
181
+ export async function updateStoreOrderStatus(id, status, optsOrEvent, maybeEvent) {
182
+ const isEvent = optsOrEvent && typeof optsOrEvent === "object" && ("node" in optsOrEvent || "req" in optsOrEvent || "context" in optsOrEvent);
183
+ const event = isEvent ? optsOrEvent : maybeEvent || optsOrEvent?.event;
184
+ const opts = !isEvent && typeof optsOrEvent === "object" ? optsOrEvent : void 0;
185
+ const db = getD1(event);
186
+ const ord = storeOrderTbl(event);
187
+ const now = Date.now();
188
+ const updates = ["status = ?", "updated_at = ?"];
189
+ const params = [status, now];
190
+ if (status === "paid") {
191
+ updates.push("paid_at = ?");
192
+ params.push(now);
193
+ } else if (status === "shipped") {
194
+ updates.push("shipped_at = ?");
195
+ params.push(now);
196
+ } else if (status === "delivered") {
197
+ updates.push("delivered_at = ?");
198
+ params.push(now);
199
+ } else if (status === "cancelled") {
200
+ updates.push("cancelled_at = ?");
201
+ params.push(now);
202
+ } else if (status === "refunded") {
203
+ updates.push("refunded_at = ?");
204
+ params.push(now);
205
+ }
206
+ if (opts?.paymentProvider) {
207
+ updates.push("payment_provider = ?");
208
+ params.push(opts.paymentProvider);
209
+ }
210
+ if (opts?.paymentIntentId) {
211
+ updates.push("payment_intent_id = ?");
212
+ params.push(opts.paymentIntentId);
213
+ }
214
+ params.push(id);
215
+ await db.prepare(`UPDATE ${ord} SET ${updates.join(", ")} WHERE id = ?`).bind(...params).run();
216
+ if (status === "paid") {
217
+ await commitStoreStock(id, event).catch(() => {
218
+ });
219
+ } else if (status === "cancelled") {
220
+ await releaseStoreOrderStock(id, event).catch(() => {
221
+ });
222
+ }
223
+ const updatedOrder = await getStoreOrder(id, event);
224
+ if (status === "paid" && updatedOrder) {
225
+ try {
226
+ const nitroApp = globalThis.useNitroApp?.();
227
+ await nitroApp?.hooks?.callHook("qarpeo:store:order-paid", {
228
+ order: updatedOrder,
229
+ event
230
+ });
231
+ } catch {
232
+ }
233
+ }
234
+ return updatedOrder;
235
+ }
236
+ export async function refundStoreOrder(orderId, opts = {}, event) {
237
+ const order = await getStoreOrder(orderId, event);
238
+ if (!order) {
239
+ throw createError({ statusCode: 404, statusMessage: "Order not found" });
240
+ }
241
+ const paymentsConfig = getPaymentsConfig(event);
242
+ if (order.paymentProvider === "stripe" && order.paymentIntentId && paymentsConfig.provider === "stripe" && paymentsConfig.secretKey) {
243
+ try {
244
+ const refundParams = new URLSearchParams();
245
+ refundParams.set("payment_intent", order.paymentIntentId);
246
+ if (opts.amount) {
247
+ refundParams.set("amount", String(opts.amount));
248
+ }
249
+ if (opts.reason) {
250
+ refundParams.set("metadata[reason]", opts.reason);
251
+ }
252
+ await fetch("https://api.stripe.com/v1/refunds", {
253
+ method: "POST",
254
+ headers: {
255
+ Authorization: `Bearer ${paymentsConfig.secretKey}`,
256
+ "Content-Type": "application/x-www-form-urlencoded",
257
+ "Stripe-Version": "2024-06-20"
258
+ },
259
+ body: refundParams.toString()
260
+ });
261
+ } catch (err) {
262
+ console.warn("[qarpeo:store] Stripe refund call failed:", err?.message || err);
263
+ }
264
+ }
265
+ const updated = await updateStoreOrderStatus(orderId, "refunded", event);
266
+ if (opts.restock !== false) {
267
+ await releaseStoreOrderStock(orderId, event).catch(() => {
268
+ });
269
+ }
270
+ if (updated) {
271
+ try {
272
+ const nitroApp = globalThis.useNitroApp?.();
273
+ await nitroApp?.hooks?.callHook("qarpeo:store:order-refunded", {
274
+ order: updated,
275
+ reason: opts.reason,
276
+ amount: opts.amount,
277
+ event
278
+ });
279
+ } catch {
280
+ }
281
+ }
282
+ return updated;
283
+ }
284
+ export async function fulfillStoreOrder(orderId, opts = {}, event) {
285
+ const order = await getStoreOrder(orderId, event);
286
+ if (!order) {
287
+ throw createError({ statusCode: 404, statusMessage: "Order not found" });
288
+ }
289
+ const db = getD1(event);
290
+ const ord = storeOrderTbl(event);
291
+ const now = Date.now();
292
+ const metadata = {
293
+ ...order.metadata,
294
+ shippingTracking: {
295
+ trackingNumber: opts.trackingNumber,
296
+ carrier: opts.carrier,
297
+ trackingUrl: opts.trackingUrl,
298
+ shippedAt: now
299
+ }
300
+ };
301
+ await db.prepare(
302
+ `UPDATE ${ord}
303
+ SET status = 'shipped', shipped_at = ?, metadata_json = ?, updated_at = ?
304
+ WHERE id = ?`
305
+ ).bind(now, JSON.stringify(metadata), now, orderId).run();
306
+ const updated = await getStoreOrder(orderId, event);
307
+ if (updated) {
308
+ try {
309
+ const nitroApp = globalThis.useNitroApp?.();
310
+ await nitroApp?.hooks?.callHook("qarpeo:store:order-fulfilled", {
311
+ order: updated,
312
+ tracking: opts,
313
+ event
314
+ });
315
+ } catch {
316
+ }
317
+ }
318
+ return updated;
319
+ }
320
+ export async function cancelStoreOrder(orderId, opts = {}, event) {
321
+ const order = await getStoreOrder(orderId, event);
322
+ if (!order) {
323
+ throw createError({ statusCode: 404, statusMessage: "Order not found" });
324
+ }
325
+ if (opts.reason) {
326
+ const db = getD1(event);
327
+ const ord = storeOrderTbl(event);
328
+ const metadata = { ...order.metadata, cancellationReason: opts.reason };
329
+ await db.prepare(`UPDATE ${ord} SET metadata_json = ? WHERE id = ?`).bind(JSON.stringify(metadata), orderId).run();
330
+ }
331
+ const updated = await updateStoreOrderStatus(orderId, "cancelled", event);
332
+ if (opts.restock !== false) {
333
+ await releaseStoreOrderStock(orderId, event).catch(() => {
334
+ });
335
+ }
336
+ if (updated) {
337
+ try {
338
+ const nitroApp = globalThis.useNitroApp?.();
339
+ await nitroApp?.hooks?.callHook("qarpeo:store:order-cancelled", {
340
+ order: updated,
341
+ reason: opts.reason,
342
+ event
343
+ });
344
+ } catch {
345
+ }
346
+ }
347
+ return updated;
348
+ }
349
+ export async function deleteStoreOrder(orderId, event) {
350
+ const db = getD1(event);
351
+ const ord = storeOrderTbl(event);
352
+ const ordItem = storeOrderItemTbl(event);
353
+ await db.batch([
354
+ db.prepare(`DELETE FROM ${ordItem} WHERE order_id = ?`).bind(orderId),
355
+ db.prepare(`DELETE FROM ${ord} WHERE id = ?`).bind(orderId)
356
+ ]);
357
+ return true;
358
+ }
359
+ export async function generateDownloadUrl(orderItemId, event) {
360
+ const db = getD1(event);
361
+ const ordItem = storeOrderItemTbl(event);
362
+ const item = await db.prepare(`SELECT * FROM ${ordItem} WHERE id = ? AND is_digital = 1`).bind(orderItemId).first();
363
+ if (!item || !item.download_key) {
364
+ throw createError({ statusCode: 404, statusMessage: "Digital download not found." });
365
+ }
366
+ const cfg = getStoreConfig(event);
367
+ const expirySec = (cfg.downloads?.expiresInHours ?? 24) * 3600;
368
+ const expiresAt = Date.now() + expirySec * 1e3;
369
+ const sig = await signHmacSha256(`${item.download_key}:${expiresAt}`, event);
370
+ const downloadUrl = `/api/store/orders/download/${item.download_key}?expires=${expiresAt}&sig=${sig}`;
371
+ return { downloadUrl, expiresAt };
372
+ }
373
+ export async function getStoreAddresses(userId, event) {
374
+ const db = getD1(event);
375
+ const addr = storeAddressTbl(event);
376
+ const rows = await db.prepare(`SELECT * FROM ${addr} WHERE user_id = ? ORDER BY is_default DESC, created_at DESC`).bind(userId).all();
377
+ return (rows.results ?? []).map(rowToAddress);
378
+ }
379
+ export async function saveStoreAddress(address, event) {
380
+ const db = getD1(event);
381
+ const addr = storeAddressTbl(event);
382
+ const now = Date.now();
383
+ if (address.isDefault) {
384
+ await db.prepare(`UPDATE ${addr} SET is_default = 0 WHERE user_id = ? AND type = ?`).bind(address.userId, address.type || "shipping").run();
385
+ }
386
+ if (address.id) {
387
+ await db.prepare(
388
+ `UPDATE ${addr}
389
+ SET name = ?, company = ?, line1 = ?, line2 = ?, city = ?, state = ?,
390
+ postal_code = ?, country = ?, phone = ?, is_default = ?, updated_at = ?
391
+ WHERE id = ? AND user_id = ?`
392
+ ).bind(
393
+ address.name || "",
394
+ address.company ?? null,
395
+ address.line1,
396
+ address.line2 ?? null,
397
+ address.city,
398
+ address.state ?? null,
399
+ address.postalCode,
400
+ address.country,
401
+ address.phone ?? null,
402
+ address.isDefault ? 1 : 0,
403
+ now,
404
+ address.id,
405
+ address.userId
406
+ ).run();
407
+ const updated = await db.prepare(`SELECT * FROM ${addr} WHERE id = ?`).bind(address.id).first();
408
+ return rowToAddress(updated);
409
+ }
410
+ const id = nanoid();
411
+ await db.prepare(
412
+ `INSERT INTO ${addr} (
413
+ id, user_id, type, name, company, line1, line2, city, state,
414
+ postal_code, country, phone, is_default, created_at, updated_at
415
+ ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
416
+ ).bind(
417
+ id,
418
+ address.userId,
419
+ address.type || "shipping",
420
+ address.name || "",
421
+ address.company ?? null,
422
+ address.line1,
423
+ address.line2 ?? null,
424
+ address.city,
425
+ address.state ?? null,
426
+ address.postalCode,
427
+ address.country,
428
+ address.phone ?? null,
429
+ address.isDefault ? 1 : 0,
430
+ now,
431
+ now
432
+ ).run();
433
+ const inserted = await db.prepare(`SELECT * FROM ${addr} WHERE id = ?`).bind(id).first();
434
+ return rowToAddress(inserted);
435
+ }
436
+ export async function deleteStoreAddress(id, userId, event) {
437
+ const db = getD1(event);
438
+ const addr = storeAddressTbl(event);
439
+ const res = await db.prepare(`DELETE FROM ${addr} WHERE id = ? AND user_id = ?`).bind(id, userId).run();
440
+ return Boolean(res?.meta?.changes);
441
+ }
442
+ export async function setDefaultStoreAddress(id, userId, type, event) {
443
+ const db = getD1(event);
444
+ const addr = storeAddressTbl(event);
445
+ const now = Date.now();
446
+ await db.batch([
447
+ db.prepare(`UPDATE ${addr} SET is_default = 0, updated_at = ? WHERE user_id = ? AND type = ?`).bind(now, userId, type),
448
+ db.prepare(`UPDATE ${addr} SET is_default = 1, updated_at = ? WHERE id = ? AND user_id = ?`).bind(now, id, userId)
449
+ ]);
450
+ return true;
451
+ }
452
+ export async function getStoreDefaultAddress(userId, type, event) {
453
+ const db = getD1(event);
454
+ const addr = storeAddressTbl(event);
455
+ const row = await db.prepare(
456
+ `SELECT * FROM ${addr} WHERE user_id = ? AND type = ? ORDER BY is_default DESC, updated_at DESC LIMIT 1`
457
+ ).bind(userId, type).first();
458
+ return row ? rowToAddress(row) : null;
459
+ }
460
+ export async function getStoreMetrics(opts = {}, event) {
461
+ const db = getD1(event);
462
+ const ord = storeOrderTbl(event);
463
+ const p = storeProductTbl(event);
464
+ const inv = storeInventoryTbl(event);
465
+ const whereClauses = [];
466
+ const params = [];
467
+ if (opts.tenantId !== void 0) {
468
+ whereClauses.push("tenant_id = ?");
469
+ params.push(opts.tenantId);
470
+ }
471
+ if (opts.startDate !== void 0) {
472
+ whereClauses.push("created_at >= ?");
473
+ params.push(opts.startDate);
474
+ }
475
+ if (opts.endDate !== void 0) {
476
+ whereClauses.push("created_at <= ?");
477
+ params.push(opts.endDate);
478
+ }
479
+ const whereSql = whereClauses.length > 0 ? `WHERE ${whereClauses.join(" AND ")}` : "";
480
+ const orderStats = await db.prepare(
481
+ `SELECT
482
+ COUNT(*) as total_orders,
483
+ COALESCE(SUM(CASE WHEN status = 'paid' THEN total ELSE 0 END), 0) as total_revenue,
484
+ COALESCE(SUM(CASE WHEN status = 'paid' THEN 1 ELSE 0 END), 0) as paid_orders,
485
+ COALESCE(SUM(CASE WHEN status = 'pending' THEN 1 ELSE 0 END), 0) as pending_orders,
486
+ COALESCE(SUM(CASE WHEN status = 'refunded' THEN 1 ELSE 0 END), 0) as refunded_orders,
487
+ COALESCE(SUM(CASE WHEN status = 'cancelled' THEN 1 ELSE 0 END), 0) as cancelled_orders
488
+ FROM ${ord}
489
+ ${whereSql}`
490
+ ).bind(...params).first();
491
+ const productWhere = opts.tenantId ? `WHERE tenant_id = ?` : "";
492
+ const productParams = opts.tenantId ? [opts.tenantId] : [];
493
+ const prodCount = await db.prepare(`SELECT COUNT(*) as cnt FROM ${p} ${productWhere}`).bind(...productParams).first();
494
+ const lowStockCount = await db.prepare(
495
+ `SELECT COUNT(*) as cnt
496
+ FROM ${inv}
497
+ WHERE (stock_quantity - reserved_quantity) <= COALESCE(low_stock_threshold, 5) AND allow_backorder = 0`
498
+ ).first();
499
+ const totalRevenue = orderStats?.total_revenue ?? 0;
500
+ const orderCount = orderStats?.total_orders ?? 0;
501
+ const paidOrderCount = orderStats?.paid_orders ?? 0;
502
+ const pendingOrderCount = orderStats?.pending_orders ?? 0;
503
+ const refundedOrderCount = orderStats?.refunded_orders ?? 0;
504
+ const cancelledOrderCount = orderStats?.cancelled_orders ?? 0;
505
+ const averageOrderValue = paidOrderCount > 0 ? Math.round(totalRevenue / paidOrderCount) : 0;
506
+ const totalProducts = prodCount?.cnt ?? 0;
507
+ return {
508
+ totalRevenue,
509
+ orderCount,
510
+ paidOrderCount,
511
+ pendingOrderCount,
512
+ refundedOrderCount,
513
+ cancelledOrderCount,
514
+ averageOrderValue,
515
+ totalProducts,
516
+ lowStockCount: lowStockCount?.cnt ?? 0
517
+ };
518
+ }
519
+ export async function reconcileStoreOrderFromWebhook({
520
+ event,
521
+ provider,
522
+ type,
523
+ data,
524
+ payload
525
+ }) {
526
+ if (provider === "stripe") {
527
+ const obj = data || {};
528
+ if (type === "checkout.session.completed") {
529
+ if (obj.metadata?.type === "store_order" || obj.metadata?.orderId) {
530
+ const orderId = obj.metadata.orderId;
531
+ if (orderId) {
532
+ const paymentIntentId = obj.payment_intent || obj.id;
533
+ await updateStoreOrderStatus(
534
+ orderId,
535
+ "paid",
536
+ { paymentProvider: "stripe", paymentIntentId, event }
537
+ ).catch((err) => {
538
+ console.warn("[qarpeo:store] Webhook failed to update order to paid:", err?.message || err);
539
+ });
540
+ }
541
+ }
542
+ } else if (type === "payment_intent.succeeded") {
543
+ const orderId = obj.metadata?.orderId;
544
+ if (orderId && (obj.metadata?.type === "store_order" || obj.metadata?.type === "store")) {
545
+ await updateStoreOrderStatus(
546
+ orderId,
547
+ "paid",
548
+ { paymentProvider: "stripe", paymentIntentId: obj.id, event }
549
+ ).catch((err) => {
550
+ console.warn("[qarpeo:store] payment_intent.succeeded failed to update order:", err?.message || err);
551
+ });
552
+ }
553
+ } else if (type === "payment_intent.payment_failed") {
554
+ const orderId = obj.metadata?.orderId;
555
+ if (orderId && (obj.metadata?.type === "store_order" || obj.metadata?.type === "store")) {
556
+ await updateStoreOrderStatus(orderId, "cancelled", { event }).catch(() => {
557
+ });
558
+ }
559
+ } else if (type === "charge.refunded") {
560
+ const orderId = obj.metadata?.orderId;
561
+ if (orderId) {
562
+ await updateStoreOrderStatus(orderId, "refunded", { event }).catch(() => {
563
+ });
564
+ }
565
+ }
566
+ } else if (provider === "lemonsqueezy" && type === "order_created") {
567
+ const customData = payload?.meta?.custom_data || {};
568
+ const orderId = customData.orderId || customData.order_id;
569
+ if (orderId && (customData.type === "store_order" || customData.type === "store")) {
570
+ await updateStoreOrderStatus(
571
+ orderId,
572
+ "paid",
573
+ { paymentProvider: "lemonsqueezy", paymentIntentId: String(data?.id), event }
574
+ ).catch(() => {
575
+ });
576
+ }
577
+ } else if (provider === "polar" && (type === "order.created" || type === "payment.succeeded")) {
578
+ const meta = data?.metadata || {};
579
+ const orderId = meta.orderId || meta.order_id;
580
+ if (orderId && (meta.type === "store_order" || meta.type === "store")) {
581
+ await updateStoreOrderStatus(
582
+ orderId,
583
+ "paid",
584
+ { paymentProvider: "polar", paymentIntentId: String(data?.id), event }
585
+ ).catch(() => {
586
+ });
587
+ }
588
+ }
589
+ }
590
+ registerPaymentWebhookListener(reconcileStoreOrderFromWebhook);
@@ -0,0 +1,35 @@
1
+ import type { RequestEvent } from "nuxt/server";
2
+ import type { StoreProduct, StoreProductVariant, StoreCategory, StoreQueryProductsOptions } from "../../../types/store";
3
+ export declare function queryStoreProducts(opts?: StoreQueryProductsOptions, event?: RequestEvent): Promise<{
4
+ products: StoreProduct[];
5
+ total: number;
6
+ }>;
7
+ export declare function getStoreProduct(idOrSlug: string, event?: RequestEvent, opts?: {
8
+ tenantId?: string;
9
+ }): Promise<StoreProduct | null>;
10
+ export declare function createStoreProduct(data: Partial<StoreProduct> & {
11
+ title: string;
12
+ basePrice: number;
13
+ slug?: string;
14
+ }, event?: RequestEvent): Promise<StoreProduct>;
15
+ export declare function updateStoreProduct(id: string, data: Partial<StoreProduct>, event?: RequestEvent): Promise<StoreProduct | null>;
16
+ export declare function deleteStoreProduct(id: string, event?: RequestEvent): Promise<boolean>;
17
+ export declare function createStoreVariant(productId: string, data: Partial<StoreProductVariant> & {
18
+ sku: string;
19
+ title: string;
20
+ }, event?: RequestEvent): Promise<StoreProductVariant>;
21
+ export declare function updateStoreVariant(id: string, data: Partial<StoreProductVariant>, event?: RequestEvent): Promise<StoreProductVariant | null>;
22
+ export declare function deleteStoreVariant(id: string, event?: RequestEvent): Promise<boolean>;
23
+ export declare function queryStoreCategories(opts?: {
24
+ parentId?: string | null;
25
+ tenantId?: string;
26
+ }, event?: RequestEvent): Promise<StoreCategory[]>;
27
+ export declare function getStoreCategory(idOrSlug: string, event?: RequestEvent, opts?: {
28
+ tenantId?: string;
29
+ }): Promise<StoreCategory | null>;
30
+ export declare function createStoreCategory(data: Partial<StoreCategory> & {
31
+ name: string;
32
+ slug?: string;
33
+ }, event?: RequestEvent): Promise<StoreCategory>;
34
+ export declare function updateStoreCategory(id: string, data: Partial<StoreCategory>, event?: RequestEvent): Promise<StoreCategory | null>;
35
+ export declare function deleteStoreCategory(id: string, event?: RequestEvent): Promise<boolean>;