@commercejs/nuxt 0.2.0 → 0.2.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.
Files changed (153) hide show
  1. package/LICENSE +21 -0
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +3 -50
  4. package/dist/runtime/composables/index.js +0 -15
  5. package/dist/runtime/composables/useCart.js +4 -4
  6. package/dist/runtime/composables/useCheckout.js +25 -10
  7. package/dist/runtime/composables/useCountries.js +5 -4
  8. package/dist/runtime/composables/useCustomer.js +37 -14
  9. package/dist/runtime/composables/useOrders.js +110 -0
  10. package/dist/runtime/composables/usePrice.js +42 -0
  11. package/dist/runtime/server/api/_commerce/auth/forgot-password.post.js +5 -0
  12. package/dist/runtime/server/api/_commerce/auth/login.post.js +5 -0
  13. package/dist/runtime/server/api/_commerce/auth/logout.post.js +3 -0
  14. package/dist/runtime/server/api/_commerce/auth/register.post.js +5 -0
  15. package/dist/runtime/server/api/_commerce/auth/reset-password.post.js +5 -0
  16. package/dist/runtime/server/api/_commerce/brands.get.js +3 -0
  17. package/dist/runtime/server/api/_commerce/cart/[id]/index.get.js +5 -0
  18. package/dist/runtime/server/api/_commerce/cart/[id]/items/[itemId].delete.js +6 -0
  19. package/dist/runtime/server/api/_commerce/cart/[id]/items/[itemId].put.js +7 -0
  20. package/dist/runtime/server/api/_commerce/cart/[id]/items/index.post.js +6 -0
  21. package/dist/runtime/server/api/_commerce/cart/index.post.js +3 -0
  22. package/dist/runtime/server/api/_commerce/categories.get.js +8 -0
  23. package/dist/runtime/server/api/_commerce/checkout/payment-methods/[cartId].get.js +5 -0
  24. package/dist/runtime/server/api/_commerce/checkout/place-order.post.js +5 -0
  25. package/dist/runtime/server/api/_commerce/checkout/set-billing-address.post.js +5 -0
  26. package/dist/runtime/server/api/_commerce/checkout/set-payment-method.post.js +5 -0
  27. package/dist/runtime/server/api/_commerce/checkout/set-shipping-address.post.js +5 -0
  28. package/dist/runtime/server/api/_commerce/checkout/set-shipping-method.post.js +5 -0
  29. package/dist/runtime/server/api/_commerce/checkout/shipping-methods/[cartId].get.js +5 -0
  30. package/dist/runtime/server/api/_commerce/cities.get.js +10 -0
  31. package/dist/runtime/server/api/_commerce/countries.get.js +12 -0
  32. package/dist/runtime/server/api/_commerce/customer/addresses/[addressId].delete.js +5 -0
  33. package/dist/runtime/server/api/_commerce/customer/addresses/[addressId].put.js +6 -0
  34. package/dist/runtime/server/api/_commerce/customer/addresses/index.get.js +3 -0
  35. package/dist/runtime/server/api/_commerce/customer/addresses/index.post.js +5 -0
  36. package/dist/runtime/server/api/_commerce/customer/index.get.js +3 -0
  37. package/dist/runtime/server/api/_commerce/customer/index.put.js +5 -0
  38. package/dist/runtime/server/api/_commerce/customer/orders/[orderId]/cancel.post.js +5 -0
  39. package/dist/runtime/server/api/_commerce/customer/orders/[orderId]/index.get.js +5 -0
  40. package/dist/runtime/server/api/_commerce/customer/orders/index.get.js +8 -0
  41. package/dist/runtime/server/api/_commerce/locations.get.js +3 -0
  42. package/dist/runtime/server/api/_commerce/products/[id].get.js +6 -0
  43. package/dist/runtime/server/api/{products.get.js → _commerce/products/index.get.js} +2 -4
  44. package/dist/runtime/server/api/_commerce/promotions/index.get.js +3 -0
  45. package/dist/runtime/server/api/_commerce/promotions/validate.post.js +5 -0
  46. package/dist/runtime/server/api/_commerce/returns/[returnId]/cancel.post.js +5 -0
  47. package/dist/runtime/server/api/_commerce/returns/[returnId]/index.get.d.ts +0 -0
  48. package/dist/runtime/server/api/_commerce/returns/[returnId]/index.get.js +5 -0
  49. package/dist/runtime/server/api/_commerce/returns/index.get.d.ts +0 -0
  50. package/dist/runtime/server/api/_commerce/returns/index.get.js +8 -0
  51. package/dist/runtime/server/api/_commerce/returns/index.post.d.ts +0 -0
  52. package/dist/runtime/server/api/_commerce/returns/index.post.js +5 -0
  53. package/dist/runtime/server/api/_commerce/reviews/[productId]/index.get.d.ts +0 -0
  54. package/dist/runtime/server/api/_commerce/reviews/[productId]/index.get.js +9 -0
  55. package/dist/runtime/server/api/_commerce/reviews/[productId]/summary.get.d.ts +0 -0
  56. package/dist/runtime/server/api/_commerce/reviews/[productId]/summary.get.js +5 -0
  57. package/dist/runtime/server/api/_commerce/reviews/index.post.d.ts +0 -0
  58. package/dist/runtime/server/api/_commerce/reviews/index.post.js +5 -0
  59. package/dist/runtime/server/api/_commerce/store.get.d.ts +0 -0
  60. package/dist/runtime/server/api/_commerce/store.get.js +3 -0
  61. package/dist/runtime/server/api/_commerce/wishlist/index.get.d.ts +0 -0
  62. package/dist/runtime/server/api/_commerce/wishlist/index.get.js +3 -0
  63. package/dist/runtime/server/api/_commerce/wishlist/items/[itemId].delete.d.ts +0 -0
  64. package/dist/runtime/server/api/_commerce/wishlist/items/[itemId].delete.js +5 -0
  65. package/dist/runtime/server/api/_commerce/wishlist/items/index.post.d.ts +0 -0
  66. package/dist/runtime/server/api/_commerce/wishlist/items/index.post.js +5 -0
  67. package/dist/runtime/server/data/cities.d.ts +0 -0
  68. package/dist/runtime/server/data/cities.js +100 -0
  69. package/dist/runtime/server/data/country-meta.d.ts +0 -0
  70. package/dist/runtime/server/data/country-meta.js +8 -0
  71. package/dist/runtime/server/plugins/commerce-adapter.js +37 -16
  72. package/dist/runtime/server/utils/context.d.ts +0 -0
  73. package/dist/runtime/server/utils/context.js +26 -0
  74. package/dist/runtime/server/utils/handler.d.ts +0 -0
  75. package/dist/runtime/server/utils/handler.js +42 -0
  76. package/dist/runtime/server/utils/schemas.d.ts +0 -0
  77. package/dist/runtime/server/utils/schemas.js +89 -0
  78. package/package.json +19 -12
  79. package/dist/runtime/server/api/auth.forgot-password.post.js +0 -8
  80. package/dist/runtime/server/api/auth.login.post.js +0 -7
  81. package/dist/runtime/server/api/auth.logout.post.js +0 -7
  82. package/dist/runtime/server/api/auth.register.post.js +0 -7
  83. package/dist/runtime/server/api/auth.reset-password.post.js +0 -8
  84. package/dist/runtime/server/api/brands.get.js +0 -6
  85. package/dist/runtime/server/api/cart.[id].get.js +0 -7
  86. package/dist/runtime/server/api/cart.[id].items.[itemId].delete.js +0 -8
  87. package/dist/runtime/server/api/cart.[id].items.[itemId].put.js +0 -9
  88. package/dist/runtime/server/api/cart.[id].items.post.js +0 -8
  89. package/dist/runtime/server/api/cart.post.js +0 -6
  90. package/dist/runtime/server/api/categories.get.js +0 -10
  91. package/dist/runtime/server/api/checkout.payment-methods.[cartId].get.js +0 -7
  92. package/dist/runtime/server/api/checkout.place-order.post.js +0 -7
  93. package/dist/runtime/server/api/checkout.shipping-methods.[cartId].get.js +0 -7
  94. package/dist/runtime/server/api/countries.get.js +0 -6
  95. package/dist/runtime/server/api/customer.addresses.[addressId].delete.js +0 -8
  96. package/dist/runtime/server/api/customer.addresses.[addressId].put.js +0 -8
  97. package/dist/runtime/server/api/customer.addresses.get.js +0 -6
  98. package/dist/runtime/server/api/customer.addresses.post.js +0 -7
  99. package/dist/runtime/server/api/customer.get.js +0 -6
  100. package/dist/runtime/server/api/customer.orders.get.js +0 -10
  101. package/dist/runtime/server/api/locations.get.js +0 -6
  102. package/dist/runtime/server/api/products.[id].get.js +0 -7
  103. package/dist/runtime/server/api/promotions.get.js +0 -6
  104. package/dist/runtime/server/api/promotions.validate.post.js +0 -7
  105. package/dist/runtime/server/api/returns.[returnId].cancel.post.js +0 -7
  106. package/dist/runtime/server/api/returns.[returnId].get.js +0 -7
  107. package/dist/runtime/server/api/returns.get.js +0 -10
  108. package/dist/runtime/server/api/returns.post.js +0 -7
  109. package/dist/runtime/server/api/reviews.[productId].get.js +0 -11
  110. package/dist/runtime/server/api/reviews.[productId].summary.get.js +0 -7
  111. package/dist/runtime/server/api/reviews.post.js +0 -7
  112. package/dist/runtime/server/api/store.get.js +0 -6
  113. package/dist/runtime/server/api/wishlist.get.js +0 -6
  114. package/dist/runtime/server/api/wishlist.items.[itemId].delete.js +0 -7
  115. package/dist/runtime/server/api/wishlist.items.post.js +0 -7
  116. /package/dist/runtime/{server/api/auth.forgot-password.post.d.ts → composables/useOrders.d.ts} +0 -0
  117. /package/dist/runtime/{server/api/auth.login.post.d.ts → composables/usePrice.d.ts} +0 -0
  118. /package/dist/runtime/server/api/{auth.logout.post.d.ts → _commerce/auth/forgot-password.post.d.ts} +0 -0
  119. /package/dist/runtime/server/api/{auth.register.post.d.ts → _commerce/auth/login.post.d.ts} +0 -0
  120. /package/dist/runtime/server/api/{auth.reset-password.post.d.ts → _commerce/auth/logout.post.d.ts} +0 -0
  121. /package/dist/runtime/server/api/{brands.get.d.ts → _commerce/auth/register.post.d.ts} +0 -0
  122. /package/dist/runtime/server/api/{cart.[id].get.d.ts → _commerce/auth/reset-password.post.d.ts} +0 -0
  123. /package/dist/runtime/server/api/{cart.[id].items.[itemId].delete.d.ts → _commerce/brands.get.d.ts} +0 -0
  124. /package/dist/runtime/server/api/{cart.[id].items.[itemId].put.d.ts → _commerce/cart/[id]/index.get.d.ts} +0 -0
  125. /package/dist/runtime/server/api/{cart.[id].items.post.d.ts → _commerce/cart/[id]/items/[itemId].delete.d.ts} +0 -0
  126. /package/dist/runtime/server/api/{cart.post.d.ts → _commerce/cart/[id]/items/[itemId].put.d.ts} +0 -0
  127. /package/dist/runtime/server/api/{categories.get.d.ts → _commerce/cart/[id]/items/index.post.d.ts} +0 -0
  128. /package/dist/runtime/server/api/{checkout.payment-methods.[cartId].get.d.ts → _commerce/cart/index.post.d.ts} +0 -0
  129. /package/dist/runtime/server/api/{checkout.place-order.post.d.ts → _commerce/categories.get.d.ts} +0 -0
  130. /package/dist/runtime/server/api/{checkout.shipping-methods.[cartId].get.d.ts → _commerce/checkout/payment-methods/[cartId].get.d.ts} +0 -0
  131. /package/dist/runtime/server/api/{countries.get.d.ts → _commerce/checkout/place-order.post.d.ts} +0 -0
  132. /package/dist/runtime/server/api/{customer.addresses.[addressId].delete.d.ts → _commerce/checkout/set-billing-address.post.d.ts} +0 -0
  133. /package/dist/runtime/server/api/{customer.addresses.[addressId].put.d.ts → _commerce/checkout/set-payment-method.post.d.ts} +0 -0
  134. /package/dist/runtime/server/api/{customer.addresses.get.d.ts → _commerce/checkout/set-shipping-address.post.d.ts} +0 -0
  135. /package/dist/runtime/server/api/{customer.addresses.post.d.ts → _commerce/checkout/set-shipping-method.post.d.ts} +0 -0
  136. /package/dist/runtime/server/api/{customer.get.d.ts → _commerce/checkout/shipping-methods/[cartId].get.d.ts} +0 -0
  137. /package/dist/runtime/server/api/{customer.orders.get.d.ts → _commerce/cities.get.d.ts} +0 -0
  138. /package/dist/runtime/server/api/{locations.get.d.ts → _commerce/countries.get.d.ts} +0 -0
  139. /package/dist/runtime/server/api/{products.[id].get.d.ts → _commerce/customer/addresses/[addressId].delete.d.ts} +0 -0
  140. /package/dist/runtime/server/api/{products.get.d.ts → _commerce/customer/addresses/[addressId].put.d.ts} +0 -0
  141. /package/dist/runtime/server/api/{promotions.get.d.ts → _commerce/customer/addresses/index.get.d.ts} +0 -0
  142. /package/dist/runtime/server/api/{promotions.validate.post.d.ts → _commerce/customer/addresses/index.post.d.ts} +0 -0
  143. /package/dist/runtime/server/api/{returns.[returnId].cancel.post.d.ts → _commerce/customer/index.get.d.ts} +0 -0
  144. /package/dist/runtime/server/api/{returns.[returnId].get.d.ts → _commerce/customer/index.put.d.ts} +0 -0
  145. /package/dist/runtime/server/api/{returns.get.d.ts → _commerce/customer/orders/[orderId]/cancel.post.d.ts} +0 -0
  146. /package/dist/runtime/server/api/{returns.post.d.ts → _commerce/customer/orders/[orderId]/index.get.d.ts} +0 -0
  147. /package/dist/runtime/server/api/{reviews.[productId].get.d.ts → _commerce/customer/orders/index.get.d.ts} +0 -0
  148. /package/dist/runtime/server/api/{reviews.[productId].summary.get.d.ts → _commerce/locations.get.d.ts} +0 -0
  149. /package/dist/runtime/server/api/{reviews.post.d.ts → _commerce/products/[id].get.d.ts} +0 -0
  150. /package/dist/runtime/server/api/{store.get.d.ts → _commerce/products/index.get.d.ts} +0 -0
  151. /package/dist/runtime/server/api/{wishlist.get.d.ts → _commerce/promotions/index.get.d.ts} +0 -0
  152. /package/dist/runtime/server/api/{wishlist.items.[itemId].delete.d.ts → _commerce/promotions/validate.post.d.ts} +0 -0
  153. /package/dist/runtime/server/api/{wishlist.items.post.d.ts → _commerce/returns/[returnId]/cancel.post.d.ts} +0 -0
@@ -0,0 +1,5 @@
1
+ import { readBody } from "h3";
2
+ export default defineCommerceHandler(async (event, adapter) => {
3
+ const { cartId, methodId } = setShippingMethodSchema.parse(await readBody(event));
4
+ return adapter.setShippingMethod(cartId, methodId);
5
+ });
@@ -0,0 +1,5 @@
1
+ import { getRouterParam } from "h3";
2
+ export default defineCommerceHandler(async (event, adapter) => {
3
+ const cartId = getRouterParam(event, "cartId");
4
+ return adapter.getShippingMethods(cartId);
5
+ });
@@ -0,0 +1,10 @@
1
+ import { defineEventHandler, getQuery } from "h3";
2
+ import { citiesByCountry } from "../../data/cities.js";
3
+ export default defineEventHandler((event) => {
4
+ const { country } = getQuery(event);
5
+ if (!country) {
6
+ return [];
7
+ }
8
+ const code = country.toUpperCase();
9
+ return citiesByCountry[code] ?? [];
10
+ });
@@ -0,0 +1,12 @@
1
+ import { countryMeta } from "../../data/country-meta.js";
2
+ export default defineCommerceHandler(async (_event, adapter) => {
3
+ const countries = await adapter.getCountries();
4
+ return countries.map((c) => {
5
+ const meta = countryMeta[c.code];
6
+ return {
7
+ ...c,
8
+ flag: c.flag || meta?.flag || null,
9
+ iso3: c.iso3 || meta?.iso3 || null
10
+ };
11
+ });
12
+ });
@@ -0,0 +1,5 @@
1
+ import { getRouterParam } from "h3";
2
+ export default defineCommerceHandler(async (event, adapter) => {
3
+ const addressId = getRouterParam(event, "addressId");
4
+ return adapter.deleteAddress(addressId);
5
+ });
@@ -0,0 +1,6 @@
1
+ import { getRouterParam, readBody } from "h3";
2
+ export default defineCommerceHandler(async (event, adapter) => {
3
+ const addressId = getRouterParam(event, "addressId");
4
+ const body = updateAddressSchema.parse(await readBody(event));
5
+ return adapter.updateAddress(addressId, body);
6
+ });
@@ -0,0 +1,3 @@
1
+ export default defineCommerceHandler(async (_event, adapter) => {
2
+ return adapter.getAddresses();
3
+ });
@@ -0,0 +1,5 @@
1
+ import { readBody } from "h3";
2
+ export default defineCommerceHandler(async (event, adapter) => {
3
+ const body = addAddressSchema.parse(await readBody(event));
4
+ return adapter.addAddress(body);
5
+ });
@@ -0,0 +1,3 @@
1
+ export default defineCommerceHandler(async (_event, adapter) => {
2
+ return adapter.getCustomer();
3
+ });
@@ -0,0 +1,5 @@
1
+ import { readBody } from "h3";
2
+ export default defineCommerceHandler(async (event, adapter) => {
3
+ const body = updateCustomerSchema.parse(await readBody(event));
4
+ return adapter.updateCustomer(body);
5
+ });
@@ -0,0 +1,5 @@
1
+ import { getRouterParam } from "h3";
2
+ export default defineCommerceHandler(async (event, adapter) => {
3
+ const orderId = getRouterParam(event, "orderId");
4
+ return adapter.cancelOrder(orderId);
5
+ });
@@ -0,0 +1,5 @@
1
+ import { getRouterParam } from "h3";
2
+ export default defineCommerceHandler(async (event, adapter) => {
3
+ const orderId = getRouterParam(event, "orderId");
4
+ return adapter.getOrder(orderId);
5
+ });
@@ -0,0 +1,8 @@
1
+ import { getQuery } from "h3";
2
+ export default defineCommerceHandler(async (event, adapter) => {
3
+ const query = getQuery(event);
4
+ return adapter.getCustomerOrders({
5
+ page: query.page ? Number(query.page) : void 0,
6
+ perPage: query.perPage ? Number(query.perPage) : void 0
7
+ });
8
+ });
@@ -0,0 +1,3 @@
1
+ export default defineCommerceHandler(async (_event, adapter) => {
2
+ return adapter.getStoreLocations();
3
+ });
@@ -0,0 +1,6 @@
1
+ import { getRouterParam } from "h3";
2
+ export default defineCommerceHandler(async (event, adapter) => {
3
+ const idOrSlug = getRouterParam(event, "id");
4
+ const isSlug = idOrSlug.includes("-") || !/^[a-f0-9]{16,}$/.test(idOrSlug);
5
+ return adapter.getProduct(isSlug ? { slug: idOrSlug } : { id: idOrSlug });
6
+ });
@@ -1,7 +1,5 @@
1
- import { defineEventHandler, getQuery } from "h3";
2
- import { useServerAdapter } from "../utils/adapter.js";
3
- export default defineEventHandler(async (event) => {
4
- const adapter = useServerAdapter(event);
1
+ import { getQuery } from "h3";
2
+ export default defineCommerceHandler(async (event, adapter) => {
5
3
  const query = getQuery(event);
6
4
  return adapter.getProducts({
7
5
  query: query.query,
@@ -0,0 +1,3 @@
1
+ export default defineCommerceHandler(async (_event, adapter) => {
2
+ return adapter.getActivePromotions();
3
+ });
@@ -0,0 +1,5 @@
1
+ import { readBody } from "h3";
2
+ export default defineCommerceHandler(async (event, adapter) => {
3
+ const { code } = validateCouponSchema.parse(await readBody(event));
4
+ return adapter.validateCoupon(code);
5
+ });
@@ -0,0 +1,5 @@
1
+ import { getRouterParam } from "h3";
2
+ export default defineCommerceHandler(async (event, adapter) => {
3
+ const returnId = getRouterParam(event, "returnId");
4
+ return adapter.cancelReturn(returnId);
5
+ });
@@ -0,0 +1,5 @@
1
+ import { getRouterParam } from "h3";
2
+ export default defineCommerceHandler(async (event, adapter) => {
3
+ const returnId = getRouterParam(event, "returnId");
4
+ return adapter.getReturn(returnId);
5
+ });
@@ -0,0 +1,8 @@
1
+ import { getQuery } from "h3";
2
+ export default defineCommerceHandler(async (event, adapter) => {
3
+ const query = getQuery(event);
4
+ return adapter.getReturns({
5
+ page: query.page ? Number(query.page) : void 0,
6
+ perPage: query.perPage ? Number(query.perPage) : void 0
7
+ });
8
+ });
@@ -0,0 +1,5 @@
1
+ import { readBody } from "h3";
2
+ export default defineCommerceHandler(async (event, adapter) => {
3
+ const body = createReturnSchema.parse(await readBody(event));
4
+ return adapter.createReturn(body);
5
+ });
@@ -0,0 +1,9 @@
1
+ import { getRouterParam, getQuery } from "h3";
2
+ export default defineCommerceHandler(async (event, adapter) => {
3
+ const productId = getRouterParam(event, "productId");
4
+ const query = getQuery(event);
5
+ return adapter.getProductReviews(productId, {
6
+ page: query.page ? Number(query.page) : void 0,
7
+ perPage: query.perPage ? Number(query.perPage) : void 0
8
+ });
9
+ });
@@ -0,0 +1,5 @@
1
+ import { getRouterParam } from "h3";
2
+ export default defineCommerceHandler(async (event, adapter) => {
3
+ const productId = getRouterParam(event, "productId");
4
+ return adapter.getReviewSummary(productId);
5
+ });
@@ -0,0 +1,5 @@
1
+ import { readBody } from "h3";
2
+ export default defineCommerceHandler(async (event, adapter) => {
3
+ const body = submitReviewSchema.parse(await readBody(event));
4
+ return adapter.submitReview(body);
5
+ });
@@ -0,0 +1,3 @@
1
+ export default defineCommerceHandler(async (_event, adapter) => {
2
+ return adapter.getStoreInfo();
3
+ });
@@ -0,0 +1,3 @@
1
+ export default defineCommerceHandler(async (_event, adapter) => {
2
+ return adapter.getWishlist();
3
+ });
@@ -0,0 +1,5 @@
1
+ import { getRouterParam } from "h3";
2
+ export default defineCommerceHandler(async (event, adapter) => {
3
+ const itemId = getRouterParam(event, "itemId");
4
+ return adapter.removeFromWishlist(itemId);
5
+ });
@@ -0,0 +1,5 @@
1
+ import { readBody } from "h3";
2
+ export default defineCommerceHandler(async (event, adapter) => {
3
+ const { productId, variantId } = addToWishlistSchema.parse(await readBody(event));
4
+ return adapter.addToWishlist(productId, variantId);
5
+ });
File without changes
@@ -0,0 +1,100 @@
1
+ export const citiesByCountry = {
2
+ BH: [
3
+ "Al Budayyi'",
4
+ "Al Hadd",
5
+ "Al Hamalah",
6
+ "Al Janabiyah",
7
+ "Al Markh",
8
+ "Al Muharraq",
9
+ "Bani Jamrah",
10
+ "Barbar",
11
+ "Jurdab",
12
+ "Madinat Isa",
13
+ "Madinat Hamad",
14
+ "Manama",
15
+ "Oil City",
16
+ "Sanabis",
17
+ "Sanad",
18
+ "Sitrah",
19
+ "Tubli"
20
+ ],
21
+ KW: [
22
+ "Abraq Khaytan",
23
+ "Ad Dasmah",
24
+ "Ad Dawhah",
25
+ "Al Ahmadi",
26
+ "Al Farwaniyah",
27
+ "Al Shamiya",
28
+ "Ar Rawdah",
29
+ "As Salimiyah",
30
+ "Ash Shuwaykh",
31
+ "Bayan",
32
+ "Hawalli",
33
+ "Janub as Surrah",
34
+ "Kayfan",
35
+ "Kuwait City",
36
+ "Salwa"
37
+ ],
38
+ OM: [
39
+ "Al Sohar",
40
+ "Muscat",
41
+ "Nizwa",
42
+ "Ruwi",
43
+ "Saham",
44
+ "Salalah",
45
+ "Samad"
46
+ ],
47
+ QA: [
48
+ "Ad Dawhah",
49
+ "Al Ghuwayriyah",
50
+ "Al Jumayliyah",
51
+ "Al Khawr",
52
+ "Al Wakrah",
53
+ "Ar Rayyan",
54
+ "Jarayan al Batinah",
55
+ "Madinat ash Shamal",
56
+ "Umm Said",
57
+ "Umm Salal"
58
+ ],
59
+ SA: [
60
+ "Abha",
61
+ "Abqaiq",
62
+ "Al Bahah",
63
+ "Al Hufuf",
64
+ "Al Qatif",
65
+ "Buraidah",
66
+ "Dammam",
67
+ "Dhahran",
68
+ "Hayil",
69
+ "Jeddah",
70
+ "Jizan",
71
+ "Jubail",
72
+ "Khamis Mushait",
73
+ "Khobar",
74
+ "Khulays",
75
+ "Mecca",
76
+ "Medina",
77
+ "Najran",
78
+ "Rabigh",
79
+ "Ras Tanura",
80
+ "Riyadh",
81
+ "Sabya",
82
+ "Safwa",
83
+ "Sakaka",
84
+ "Sayhat",
85
+ "Tabuk",
86
+ "Yanbu"
87
+ ],
88
+ AE: [
89
+ "Abu Dhabi",
90
+ "Al Ain",
91
+ "Al Khan",
92
+ "Ar Ruways",
93
+ "As Satwah",
94
+ "Dayrah",
95
+ "Dubai",
96
+ "Fujairah",
97
+ "Ras al-Khaimah",
98
+ "Sharjah"
99
+ ]
100
+ };
File without changes
@@ -0,0 +1,8 @@
1
+ export const countryMeta = {
2
+ BH: { flag: "https://upload.wikimedia.org/wikipedia/commons/2/2c/Flag_of_Bahrain.svg", iso3: "BHR" },
3
+ KW: { flag: "https://upload.wikimedia.org/wikipedia/commons/a/aa/Flag_of_Kuwait.svg", iso3: "KWT" },
4
+ OM: { flag: "https://upload.wikimedia.org/wikipedia/commons/d/dd/Flag_of_Oman.svg", iso3: "OMN" },
5
+ QA: { flag: "https://upload.wikimedia.org/wikipedia/commons/6/65/Flag_of_Qatar.svg", iso3: "QAT" },
6
+ SA: { flag: "https://upload.wikimedia.org/wikipedia/commons/0/0d/Flag_of_Saudi_Arabia.svg", iso3: "SAU" },
7
+ AE: { flag: "https://upload.wikimedia.org/wikipedia/commons/c/cb/Flag_of_the_United_Arab_Emirates.svg", iso3: "ARE" }
8
+ };
@@ -1,25 +1,46 @@
1
- import { SallaAdapter } from "@commercejs/adapter-salla";
2
1
  let _adapter = null;
3
- function getAdapter() {
2
+ let _initPromise = null;
3
+ async function initAdapter() {
4
4
  if (_adapter) return _adapter;
5
- const token = process.env.SALLA_TOKEN || process.env.NUXT_SALLA_TOKEN;
6
- if (!token) {
7
- throw new Error(
8
- "[@commercejs/nuxt] SALLA_TOKEN environment variable is required. Set it in your .env file or via NUXT_SALLA_TOKEN."
9
- );
5
+ const adapterName = process.env.COMMERCE_ADAPTER || process.env.NUXT_COMMERCE_ADAPTER || "salla";
6
+ if (adapterName === "platform") {
7
+ const platform = await import("@commercejs/platform");
8
+ const { initPrisma, migratePrisma, seedPrisma, createPlatformAdapter } = platform;
9
+ const dbPath = process.env.COMMERCE_DB_PATH || process.env.NUXT_COMMERCE_DB_PATH || "./store.db";
10
+ initPrisma(dbPath);
11
+ await migratePrisma();
12
+ try {
13
+ await seedPrisma();
14
+ } catch {
15
+ }
16
+ _adapter = createPlatformAdapter({
17
+ currency: process.env.COMMERCE_CURRENCY || "SAR"
18
+ });
19
+ } else {
20
+ const { SallaAdapter } = await import("@commercejs/adapter-salla");
21
+ const token = process.env.SALLA_TOKEN || process.env.NUXT_SALLA_TOKEN;
22
+ if (!token) {
23
+ throw new Error(
24
+ "[@commercejs/nuxt] SALLA_TOKEN environment variable is required. Set it in your .env file or via NUXT_SALLA_TOKEN."
25
+ );
26
+ }
27
+ _adapter = new SallaAdapter({
28
+ accessToken: token,
29
+ refreshToken: process.env.SALLA_REFRESH_TOKEN || process.env.NUXT_SALLA_REFRESH_TOKEN,
30
+ clientId: process.env.SALLA_CLIENT_ID || process.env.NUXT_SALLA_CLIENT_ID,
31
+ clientSecret: process.env.SALLA_SECRET || process.env.NUXT_SALLA_SECRET,
32
+ locale: process.env.SALLA_LOCALE || process.env.NUXT_SALLA_LOCALE || "ar"
33
+ });
10
34
  }
11
- _adapter = new SallaAdapter({
12
- accessToken: token,
13
- refreshToken: process.env.SALLA_REFRESH_TOKEN || process.env.NUXT_SALLA_REFRESH_TOKEN,
14
- clientId: process.env.SALLA_CLIENT_ID || process.env.NUXT_SALLA_CLIENT_ID,
15
- clientSecret: process.env.SALLA_SECRET || process.env.NUXT_SALLA_SECRET,
16
- locale: process.env.SALLA_LOCALE || process.env.NUXT_SALLA_LOCALE || "ar"
17
- });
18
35
  return _adapter;
19
36
  }
20
37
  export default defineNitroPlugin((nitroApp) => {
21
- nitroApp.hooks.hook("request", (event) => {
38
+ _initPromise = initAdapter();
39
+ nitroApp.hooks.hook("request", async (event) => {
40
+ if (!_adapter) {
41
+ await _initPromise;
42
+ }
22
43
  ;
23
- event.context._commerceAdapter = getAdapter();
44
+ event.context._commerceAdapter = _adapter;
24
45
  });
25
46
  });
File without changes
@@ -0,0 +1,26 @@
1
+ import { ulid } from "ulid";
2
+ const CONTEXT_KEY = "_commerceContext";
3
+ export function createCommerceContext(event) {
4
+ if (event.context[CONTEXT_KEY]) {
5
+ return event.context[CONTEXT_KEY];
6
+ }
7
+ const now = /* @__PURE__ */ new Date();
8
+ const locale = resolveLocale(event);
9
+ const ctx = {
10
+ requestId: ulid(now.getTime()),
11
+ timestamp: now.toISOString(),
12
+ locale,
13
+ generateId: () => ulid()
14
+ };
15
+ event.context[CONTEXT_KEY] = ctx;
16
+ return ctx;
17
+ }
18
+ export function useCommerceContext(event) {
19
+ return event.context[CONTEXT_KEY] ?? null;
20
+ }
21
+ function resolveLocale(event) {
22
+ const header = event.node.req.headers["accept-language"];
23
+ if (!header) return "en";
24
+ const primary = header.split(",")[0]?.split(";")[0]?.trim();
25
+ return primary || "en";
26
+ }
File without changes
@@ -0,0 +1,42 @@
1
+ import { defineEventHandler, createError } from "h3";
2
+ import { isCommerceError } from "@commercejs/types";
3
+ import { ZodError } from "zod";
4
+ import { useServerAdapter } from "./adapter.js";
5
+ import { createCommerceContext } from "./context.js";
6
+ export function defineCommerceHandler(handler) {
7
+ return defineEventHandler(async (event) => {
8
+ try {
9
+ const adapter = useServerAdapter(event);
10
+ const ctx = createCommerceContext(event);
11
+ return await handler(event, adapter, ctx);
12
+ } catch (err) {
13
+ if (err && typeof err === "object" && "statusCode" in err) {
14
+ throw err;
15
+ }
16
+ if (err instanceof ZodError) {
17
+ throw createError({
18
+ statusCode: 422,
19
+ message: "Validation failed",
20
+ data: {
21
+ code: "VALIDATION",
22
+ errors: err.errors.map((e) => ({
23
+ path: e.path.join("."),
24
+ message: e.message
25
+ }))
26
+ }
27
+ });
28
+ }
29
+ if (isCommerceError(err)) {
30
+ throw createError({
31
+ statusCode: err.statusCode ?? 500,
32
+ message: err.message,
33
+ data: { code: err.code }
34
+ });
35
+ }
36
+ throw createError({
37
+ statusCode: 500,
38
+ message: "Internal server error"
39
+ });
40
+ }
41
+ });
42
+ }
File without changes
@@ -0,0 +1,89 @@
1
+ import { z } from "zod";
2
+ export const loginSchema = z.object({
3
+ email: z.string().email("Invalid email address"),
4
+ password: z.string().min(1, "Password is required")
5
+ });
6
+ export const registerSchema = z.object({
7
+ firstName: z.string().min(1, "First name is required"),
8
+ lastName: z.string().min(1, "Last name is required"),
9
+ email: z.string().email("Invalid email address"),
10
+ password: z.string().min(6, "Password must be at least 6 characters"),
11
+ phone: z.string().optional()
12
+ });
13
+ export const forgotPasswordSchema = z.object({
14
+ email: z.string().email("Invalid email address")
15
+ });
16
+ export const resetPasswordSchema = z.object({
17
+ token: z.string().min(1, "Token is required"),
18
+ password: z.string().min(6, "Password must be at least 6 characters")
19
+ });
20
+ export const addToCartSchema = z.object({
21
+ productId: z.string().min(1, "Product ID is required"),
22
+ variantId: z.string().optional(),
23
+ quantity: z.number().int().positive("Quantity must be at least 1").default(1),
24
+ metadata: z.record(z.unknown()).optional()
25
+ });
26
+ export const updateCartItemSchema = z.object({
27
+ quantity: z.number().int().positive("Quantity must be at least 1")
28
+ });
29
+ const addressSchema = z.object({
30
+ firstName: z.string().optional(),
31
+ lastName: z.string().optional(),
32
+ line1: z.string().min(1, "Address line 1 is required"),
33
+ line2: z.string().optional(),
34
+ city: z.string().min(1, "City is required"),
35
+ state: z.string().optional(),
36
+ postalCode: z.string().optional(),
37
+ country: z.string().min(1, "Country is required"),
38
+ phone: z.string().optional()
39
+ });
40
+ export const setShippingAddressSchema = z.object({
41
+ cartId: z.string().min(1, "Cart ID is required"),
42
+ address: addressSchema
43
+ });
44
+ export const setBillingAddressSchema = z.object({
45
+ cartId: z.string().min(1, "Cart ID is required"),
46
+ address: addressSchema
47
+ });
48
+ export const setShippingMethodSchema = z.object({
49
+ cartId: z.string().min(1, "Cart ID is required"),
50
+ methodId: z.string().min(1, "Method ID is required")
51
+ });
52
+ export const setPaymentMethodSchema = z.object({
53
+ cartId: z.string().min(1, "Cart ID is required"),
54
+ methodId: z.string().min(1, "Method ID is required")
55
+ });
56
+ export const placeOrderSchema = z.object({
57
+ cartId: z.string().min(1, "Cart ID is required")
58
+ });
59
+ export const updateCustomerSchema = z.object({
60
+ firstName: z.string().optional(),
61
+ lastName: z.string().optional(),
62
+ email: z.string().email().optional(),
63
+ phone: z.string().optional()
64
+ }).refine((data) => Object.keys(data).length > 0, {
65
+ message: "At least one field must be provided for update"
66
+ });
67
+ export const addAddressSchema = addressSchema;
68
+ export const updateAddressSchema = addressSchema.partial();
69
+ export const validateCouponSchema = z.object({
70
+ code: z.string().min(1, "Coupon code is required")
71
+ });
72
+ export const submitReviewSchema = z.object({
73
+ productId: z.string().min(1, "Product ID is required"),
74
+ rating: z.number().int().min(1).max(5),
75
+ title: z.string().optional(),
76
+ body: z.string().min(1, "Review body is required")
77
+ });
78
+ export const createReturnSchema = z.object({
79
+ orderId: z.string().min(1, "Order ID is required"),
80
+ reason: z.string().min(1, "Reason is required"),
81
+ items: z.array(z.object({
82
+ orderItemId: z.string().min(1),
83
+ quantity: z.number().int().positive()
84
+ })).min(1, "At least one item is required")
85
+ });
86
+ export const addToWishlistSchema = z.object({
87
+ productId: z.string().min(1, "Product ID is required"),
88
+ variantId: z.string().optional()
89
+ });
package/package.json CHANGED
@@ -1,8 +1,12 @@
1
1
  {
2
2
  "name": "@commercejs/nuxt",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "CommerceJS Nuxt module — composables, plugin, and auto-generated REST API",
5
- "repository": { "type": "git", "url": "https://github.com/commerce-js/commerce.js.git", "directory": "packages/nuxt" },
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/commerce-js/commerce.js.git",
8
+ "directory": "packages/nuxt"
9
+ },
6
10
  "license": "MIT",
7
11
  "type": "module",
8
12
  "main": "./dist/module.mjs",
@@ -20,18 +24,15 @@
20
24
  "files": [
21
25
  "dist"
22
26
  ],
23
- "scripts": {
24
- "build": "nuxt-module-build build",
25
- "dev": "nuxi dev playground",
26
- "typecheck": "nuxt-module-build build",
27
- "clean": "rm -rf dist .nuxt"
28
- },
29
27
  "dependencies": {
30
- "@commercejs/adapter-salla": "workspace:*",
31
- "@commercejs/types": "workspace:*",
32
28
  "@vueuse/core": "^14.2.0",
33
29
  "consola": "^3.4.2",
34
- "h3": "^1.13.0"
30
+ "h3": "^1.13.0",
31
+ "ulid": "^3.0.2",
32
+ "zod": "^4.3.6",
33
+ "@commercejs/adapter-salla": "0.1.1",
34
+ "@commercejs/platform": "0.2.1",
35
+ "@commercejs/types": "0.2.0"
35
36
  },
36
37
  "devDependencies": {
37
38
  "@nuxt/kit": "^4.3.1",
@@ -39,5 +40,11 @@
39
40
  "@nuxt/schema": "^4.3.1",
40
41
  "nuxt": "^4.3.1",
41
42
  "typescript": "^5.7.0"
43
+ },
44
+ "scripts": {
45
+ "build": "nuxt-module-build build",
46
+ "dev": "nuxi dev playground",
47
+ "typecheck": "nuxt-module-build build",
48
+ "clean": "rm -rf dist .nuxt"
42
49
  }
43
- }
50
+ }