@nextblock-cms/ecom 0.8.6 → 0.8.7
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/index.cjs.js +1 -1
- package/index.es.js +136 -533
- package/lib/CurrencyProvider.cjs.js +1 -0
- package/lib/CurrencyProvider.es.js +99 -0
- package/lib/cart-store.cjs.js +1 -0
- package/{cart-store.es.js → lib/cart-store.es.js} +13 -13
- package/lib/components/AccountNavigationMenu.cjs.js +1 -0
- package/lib/components/AccountNavigationMenu.es.js +44 -0
- package/lib/components/AddToCartButton.cjs.js +1 -0
- package/{AddToCartButton-ffE0DhHu.js → lib/components/AddToCartButton.es.js} +14 -13
- package/lib/components/Cart.cjs.js +1 -0
- package/lib/components/Cart.es.js +148 -0
- package/lib/components/CartDrawer.cjs.js +1 -0
- package/{components → lib/components}/CartDrawer.es.js +15 -14
- package/{components → lib/components}/CartIcon.cjs.js +1 -1
- package/{components → lib/components}/CartIcon.es.js +1 -0
- package/lib/components/Checkout.cjs.js +1 -0
- package/{components → lib/components}/Checkout.es.js +330 -363
- package/lib/components/CouponForm.cjs.js +1 -0
- package/lib/components/CouponForm.es.js +136 -0
- package/lib/components/CurrencySwitcher.cjs.js +1 -0
- package/{components → lib/components}/CurrencySwitcher.es.js +5 -4
- package/lib/components/CustomerProfileForm.cjs.js +1 -0
- package/lib/components/CustomerProfileForm.es.js +355 -0
- package/lib/components/FeaturedProduct.cjs.js +1 -0
- package/{components → lib/components}/FeaturedProduct.es.js +9 -8
- package/lib/components/InvoiceDocument.cjs.js +1 -0
- package/lib/components/InvoiceDocument.es.js +196 -0
- package/lib/components/InvoiceViewerShell.cjs.js +29 -0
- package/lib/components/InvoiceViewerShell.es.js +100 -0
- package/lib/components/ProductCard.cjs.js +1 -0
- package/lib/components/ProductCard.es.js +119 -0
- package/lib/components/ProductDetailsLayout.cjs.js +1 -0
- package/lib/components/ProductDetailsLayout.es.js +361 -0
- package/lib/components/ProductGallery.cjs.js +1 -0
- package/lib/components/ProductGallery.es.js +41 -0
- package/lib/components/ProductGrid.cjs.js +1 -0
- package/lib/components/ProductGrid.es.js +19 -0
- package/lib/components/ShippingEstimator.cjs.js +1 -0
- package/lib/components/ShippingEstimator.es.js +125 -0
- package/lib/components/SubscriptionSelector.cjs.js +1 -0
- package/lib/components/SubscriptionSelector.es.js +140 -0
- package/lib/countries.cjs.js +1 -0
- package/lib/countries.es.js +77 -0
- package/lib/coupon-server.cjs.js +1 -0
- package/{coupon-server-DUKVtyYs.js → lib/coupon-server.es.js} +68 -82
- package/lib/coupons.cjs.js +1 -0
- package/lib/coupons.es.js +17 -0
- package/lib/currency-store.cjs.js +1 -0
- package/lib/currency-store.es.js +27 -0
- package/lib/currency-sync.cjs.js +1 -0
- package/lib/currency-sync.es.js +180 -0
- package/lib/customer-addresses.cjs.js +1 -0
- package/lib/customer-addresses.es.js +116 -0
- package/lib/customer-orders.cjs.js +1 -0
- package/lib/customer-orders.es.js +45 -0
- package/lib/customer.cjs.js +1 -0
- package/{customer-C3xccjUg.js → lib/customer.es.js} +15 -14
- package/lib/export-helpers.cjs.js +1 -0
- package/lib/export-helpers.es.js +56 -0
- package/lib/factory.cjs.js +1 -0
- package/lib/factory.es.js +8 -0
- package/lib/freemius-coupons.cjs.js +1 -0
- package/lib/freemius-coupons.es.js +272 -0
- package/lib/freemius-order-sync.cjs.js +1 -0
- package/lib/freemius-order-sync.es.js +284 -0
- package/lib/inventory-settings.cjs.js +1 -0
- package/lib/inventory-settings.es.js +86 -0
- package/lib/invoice-server.cjs.js +33 -0
- package/lib/invoice-server.es.js +141 -0
- package/lib/invoice-ui.cjs.js +1 -0
- package/lib/invoice-ui.es.js +71 -0
- package/lib/invoice.cjs.js +1 -0
- package/lib/invoice.es.js +102 -0
- package/lib/order-inventory.cjs.js +61 -0
- package/lib/order-inventory.es.js +128 -0
- package/lib/order-tax-details.cjs.js +1 -0
- package/lib/order-tax-details.es.js +164 -0
- package/lib/pages/cms/coupons/CouponEditorForm.cjs.js +1 -0
- package/lib/pages/cms/coupons/CouponEditorForm.es.js +189 -0
- package/lib/pages/cms/coupons/CouponsPage.cjs.js +5 -0
- package/lib/pages/cms/coupons/CouponsPage.es.js +171 -0
- package/lib/pages/cms/coupons/CreateCouponDialog.cjs.js +1 -0
- package/lib/pages/cms/coupons/CreateCouponDialog.es.js +35 -0
- package/lib/pages/cms/coupons/EditCouponPage.cjs.js +1 -0
- package/lib/pages/cms/coupons/EditCouponPage.es.js +48 -0
- package/lib/pages/cms/coupons/ProductScopePicker.cjs.js +1 -0
- package/lib/pages/cms/coupons/ProductScopePicker.es.js +120 -0
- package/lib/pages/cms/coupons/actions.cjs.js +1 -0
- package/lib/pages/cms/coupons/actions.es.js +128 -0
- package/lib/pages/cms/coupons/product-options.cjs.js +1 -0
- package/lib/pages/cms/coupons/product-options.es.js +27 -0
- package/lib/pages/cms/orders/ExportReportsDialog.cjs.js +1 -0
- package/lib/pages/cms/orders/ExportReportsDialog.es.js +130 -0
- package/lib/pages/cms/orders/OrderDetailPage.cjs.js +1 -0
- package/lib/pages/cms/orders/OrderDetailPage.es.js +137 -0
- package/lib/pages/cms/orders/OrderPrintButton.cjs.js +1 -0
- package/lib/pages/cms/orders/OrderPrintButton.es.js +22 -0
- package/lib/pages/cms/orders/OrderStatusForm.cjs.js +1 -0
- package/lib/pages/cms/orders/OrderStatusForm.es.js +71 -0
- package/lib/pages/cms/orders/OrdersPage.cjs.js +1 -0
- package/lib/pages/cms/orders/OrdersPage.es.js +104 -0
- package/lib/pages/cms/orders/actions.cjs.js +7 -0
- package/lib/pages/cms/orders/actions.es.js +71 -0
- package/lib/pages/cms/orders/export-actions.cjs.js +1 -0
- package/lib/pages/cms/orders/export-actions.es.js +27 -0
- package/lib/pages/cms/orders/server-actions.cjs.js +1 -0
- package/lib/pages/cms/orders/server-actions.es.js +55 -0
- package/lib/pages/cms/payments/PaymentsClient.cjs.js +1 -0
- package/lib/pages/cms/payments/PaymentsClient.es.js +188 -0
- package/lib/pages/cms/payments/PaymentsPage.cjs.js +1 -0
- package/lib/pages/cms/payments/PaymentsPage.es.js +29 -0
- package/lib/pages/cms/payments/actions.cjs.js +1 -0
- package/lib/pages/cms/payments/actions.es.js +23 -0
- package/lib/pages/cms/payments/queries.cjs.js +1 -0
- package/lib/pages/cms/payments/queries.es.js +30 -0
- package/lib/pages/cms/products/ProductsPage.cjs.js +1 -0
- package/lib/pages/cms/products/ProductsPage.es.js +46 -0
- package/lib/pages/cms/products/_id_/edit/EditProductPage.cjs.js +1 -0
- package/lib/pages/cms/products/_id_/edit/EditProductPage.es.js +156 -0
- package/lib/pages/cms/products/actions.cjs.js +44 -0
- package/lib/pages/cms/products/actions.es.js +175 -0
- package/lib/pages/cms/products/attributes/AttributeManagementPage.cjs.js +1 -0
- package/lib/pages/cms/products/attributes/AttributeManagementPage.es.js +48 -0
- package/lib/pages/cms/products/attributes/components/AttributeManager.cjs.js +1 -0
- package/lib/pages/cms/products/attributes/components/AttributeManager.es.js +291 -0
- package/lib/pages/cms/products/categories/CategoryManagementPage.cjs.js +1 -0
- package/lib/pages/cms/products/categories/CategoryManagementPage.es.js +36 -0
- package/lib/pages/cms/products/categories/components/CategoryManager.cjs.js +1 -0
- package/lib/pages/cms/products/categories/components/CategoryManager.es.js +263 -0
- package/lib/pages/cms/products/components/CopyProductFromLanguage.cjs.js +1 -0
- package/lib/pages/cms/products/components/CopyProductFromLanguage.es.js +114 -0
- package/lib/pages/cms/products/components/CurrencyPriceFields.cjs.js +1 -0
- package/lib/pages/cms/products/components/CurrencyPriceFields.es.js +107 -0
- package/lib/pages/cms/products/components/DeleteProductButton.cjs.js +1 -0
- package/lib/pages/cms/products/components/DeleteProductButton.es.js +48 -0
- package/lib/pages/cms/products/components/FreemiusPricingDashboard.cjs.js +1 -0
- package/lib/pages/cms/products/components/FreemiusPricingDashboard.es.js +86 -0
- package/lib/pages/cms/products/components/ProductCategorySelector.cjs.js +1 -0
- package/lib/pages/cms/products/components/ProductCategorySelector.es.js +160 -0
- package/lib/pages/cms/products/components/ProductForm.cjs.js +1 -0
- package/lib/pages/cms/products/components/ProductForm.es.js +702 -0
- package/lib/pages/cms/products/components/ProductMediaManager.cjs.js +1 -0
- package/lib/pages/cms/products/components/ProductMediaManager.es.js +104 -0
- package/lib/pages/cms/products/components/ProductsBulkTable.cjs.js +1 -0
- package/lib/pages/cms/products/components/ProductsBulkTable.es.js +228 -0
- package/lib/pages/cms/products/components/SaleScheduleFields.cjs.js +1 -0
- package/lib/pages/cms/products/components/SaleScheduleFields.es.js +137 -0
- package/lib/pages/cms/products/components/SyncFreemiusButton.cjs.js +1 -0
- package/lib/pages/cms/products/components/SyncFreemiusButton.es.js +36 -0
- package/lib/pages/cms/products/components/SyncFreemiusPricingButton.cjs.js +1 -0
- package/lib/pages/cms/products/components/SyncFreemiusPricingButton.es.js +40 -0
- package/lib/pages/cms/products/components/VariationsEditor.cjs.js +1 -0
- package/lib/pages/cms/products/components/VariationsEditor.es.js +408 -0
- package/lib/pages/cms/products/inventory/InventoryPage.cjs.js +1 -0
- package/lib/pages/cms/products/inventory/InventoryPage.es.js +16 -0
- package/lib/pages/cms/products/inventory/InventoryTableClient.cjs.js +2 -0
- package/lib/pages/cms/products/inventory/InventoryTableClient.es.js +214 -0
- package/lib/pages/cms/products/inventory/actions.cjs.js +3 -0
- package/lib/pages/cms/products/inventory/actions.es.js +95 -0
- package/lib/pages/cms/products/new/NewProductPage.cjs.js +1 -0
- package/lib/pages/cms/products/new/NewProductPage.es.js +76 -0
- package/lib/pages/cms/products/product-price-sync.cjs.js +1 -0
- package/lib/pages/cms/products/product-price-sync.es.js +98 -0
- package/lib/pages/cms/products/server-actions.cjs.js +1 -0
- package/lib/pages/cms/products/server-actions.es.js +193 -0
- package/lib/pages/cms/shipping/ShippingPage.cjs.js +5 -0
- package/lib/pages/cms/shipping/ShippingPage.es.js +211 -0
- package/lib/pages/cms/shipping/components/RateForm.cjs.js +1 -0
- package/lib/pages/cms/shipping/components/RateForm.es.js +441 -0
- package/lib/pages/cms/shipping/components/ZoneForm.cjs.js +1 -0
- package/lib/pages/cms/shipping/components/ZoneForm.es.js +228 -0
- package/lib/pages/cms/shipping/server-actions.cjs.js +1 -0
- package/lib/pages/cms/shipping/server-actions.es.js +159 -0
- package/lib/pages/cms/taxes/TaxesPage.cjs.js +1 -0
- package/lib/pages/cms/taxes/TaxesPage.es.js +172 -0
- package/lib/pages/cms/taxes/actions.cjs.js +1 -0
- package/lib/pages/cms/taxes/actions.es.js +57 -0
- package/lib/pages/cms/taxes/components/TaxRateForm.cjs.js +1 -0
- package/lib/pages/cms/taxes/components/TaxRateForm.es.js +100 -0
- package/lib/product-actions.cjs.js +237 -0
- package/lib/product-actions.es.js +524 -0
- package/lib/product-context.cjs.js +1 -0
- package/lib/product-context.es.js +16 -0
- package/lib/product-schema.cjs.js +1 -0
- package/lib/product-schema.es.js +134 -0
- package/lib/providers/freemius.cjs.js +5 -0
- package/lib/providers/freemius.es.js +538 -0
- package/lib/providers/stripe.cjs.js +1 -0
- package/lib/providers/stripe.es.js +473 -0
- package/lib/server-actions/coupon-actions.cjs.js +1 -0
- package/lib/server-actions/coupon-actions.es.js +23 -0
- package/lib/server-actions/customer-actions.cjs.js +1 -0
- package/lib/server-actions/customer-actions.es.js +30 -0
- package/lib/server-actions/product-actions.cjs.js +1 -0
- package/{server-actions → lib/server-actions}/product-actions.es.js +5 -4
- package/lib/server-actions/shipping-actions.cjs.js +1 -0
- package/{shipping-actions-BnHjlo2q.js → lib/server-actions/shipping-actions.es.js} +9 -7
- package/lib/server-actions/tax-actions.cjs.js +1 -0
- package/lib/server-actions/tax-actions.es.js +40 -0
- package/lib/shared-inventory.cjs.js +15 -0
- package/lib/shared-inventory.es.js +171 -0
- package/lib/shipping/resolver.cjs.js +7 -0
- package/lib/shipping/resolver.es.js +62 -0
- package/lib/shipping-rate-currency.cjs.js +1 -0
- package/lib/shipping-rate-currency.es.js +72 -0
- package/lib/states.cjs.js +1 -0
- package/{states-DlHJezQ1.js → lib/states.es.js} +27 -100
- package/lib/stripe/checkout.cjs.js +1 -0
- package/lib/stripe/checkout.es.js +182 -0
- package/lib/stripe/client.cjs.js +1 -0
- package/lib/stripe/client.es.js +7 -0
- package/lib/stripe/order-sync.cjs.js +1 -0
- package/lib/stripe/order-sync.es.js +130 -0
- package/lib/stripe/webhooks.cjs.js +1 -0
- package/lib/stripe/webhooks.es.js +30 -0
- package/lib/tax-calculation.cjs.js +1 -0
- package/lib/tax-calculation.es.js +101 -0
- package/lib/trials.cjs.js +1 -0
- package/{trials-RDcRAZKx.js → lib/trials.es.js} +9 -9
- package/{use-cart.es.js → lib/use-cart.es.js} +1 -0
- package/lib/zod-config.cjs.js +1 -0
- package/lib/zod-config.es.js +6 -0
- package/package.json +4 -4
- package/server.cjs.js +1 -110
- package/server.es.js +178 -6052
- package/AddToCartButton-DsSEH9yp.cjs +0 -1
- package/CouponForm-BI_5SBHQ.js +0 -152
- package/CouponForm-D_uu2bLP.cjs +0 -1
- package/CurrencyProvider-Cg-Q6ucj.cjs +0 -1
- package/CurrencyProvider-OzlRN96V.js +0 -120
- package/CurrencyProvider.cjs.js +0 -1
- package/CurrencyProvider.es.js +0 -10
- package/ProductDetailsLayout-BxJH_BxR.cjs +0 -1
- package/ProductDetailsLayout-Dg8dRTYp.js +0 -530
- package/ProductGrid-BdL7iglO.cjs +0 -1
- package/ProductGrid-D3AWM8sr.js +0 -130
- package/actions-AHmBrS5e.cjs +0 -48
- package/actions-j5fuSZX-.js +0 -820
- package/cart-store.cjs.js +0 -1
- package/components/Cart.cjs.js +0 -1
- package/components/Cart.es.js +0 -259
- package/components/CartDrawer.cjs.js +0 -1
- package/components/Checkout.cjs.js +0 -1
- package/components/CurrencySwitcher.cjs.js +0 -1
- package/components/FeaturedProduct.cjs.js +0 -1
- package/components/ProductDetailsLayout.cjs.js +0 -1
- package/components/ProductDetailsLayout.es.js +0 -19
- package/components/ProductGrid.cjs.js +0 -1
- package/components/ProductGrid.es.js +0 -6
- package/coupon-server-C9ySm3I5.cjs +0 -1
- package/customer-C-UPvrYN.cjs +0 -1
- package/invoice-ui-CAnJPu6n.cjs +0 -29
- package/invoice-ui-DtpbTJE1.js +0 -2886
- package/product-actions-CONBF8i6.cjs +0 -251
- package/product-actions-DjlIWCMH.js +0 -691
- package/resolver-Fz_FKsfX.cjs +0 -7
- package/resolver-cfrCaHpE.js +0 -128
- package/server-actions/product-actions.cjs.js +0 -1
- package/shipping-actions-D6zt20gg.cjs +0 -1
- package/states-CWYRxV4B.cjs +0 -1
- package/tax-calculation-Dab89aHd.js +0 -181
- package/tax-calculation-MkDKOEkL.cjs +0 -1
- package/trials-DvZaOtNy.cjs +0 -1
- /package/{components → lib/components}/SimpleTiptapRenderer.cjs.js +0 -0
- /package/{components → lib/components}/SimpleTiptapRenderer.es.js +0 -0
- /package/{currency-constants.cjs.js → lib/currency-constants.cjs.js} +0 -0
- /package/{currency-constants.es.js → lib/currency-constants.es.js} +0 -0
- /package/{currency-rest-client-uolJxUkL.cjs → lib/currency-rest-client.cjs.js} +0 -0
- /package/{currency-rest-client-CwoqdgAP.js → lib/currency-rest-client.es.js} +0 -0
- /package/{currency.cjs.js → lib/currency.cjs.js} +0 -0
- /package/{currency.es.js → lib/currency.es.js} +0 -0
- /package/{types.cjs.js → lib/types.cjs.js} +0 -0
- /package/{types.es.js → lib/types.es.js} +0 -0
- /package/{use-cart.cjs.js → lib/use-cart.cjs.js} +0 -0
- /package/{variation-utils.cjs.js → lib/variation-utils.cjs.js} +0 -0
- /package/{variation-utils.es.js → lib/variation-utils.es.js} +0 -0
package/actions-AHmBrS5e.cjs
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";const P=require("@nextblock-cms/db/server"),G=require("./product-actions-CONBF8i6.cjs"),J=require("@supabase/supabase-js"),oe=require("crypto"),ye=require("@freemius/sdk"),Q=require("./customer-C-UPvrYN.cjs"),te=require("./coupon-server-C9ySm3I5.cjs"),V=require("./currency.cjs.js"),j=require("next/cache");function D(e){const r=e?.trim();return r||null}function ne(e){return e?Q.normalizeCustomerAddress({company_name:e.company_name,recipient_name:e.recipient_name,line1:e.line1,line2:e.line2,city:e.city,state:e.state,postal_code:e.postal_code,country_code:e.country_code}):null}function se(e,r){return e?.find(t=>t.address_type===r&&t.is_default)??e?.find(t=>t.address_type===r)??null}async function ie(e,r,t,n){const s=Q.normalizeCustomerAddress(n),{data:o,error:l}=await e.from("user_addresses").select("*").eq("user_id",r).eq("address_type",t).order("is_default",{ascending:!1}).order("updated_at",{ascending:!1});if(l)throw new Error(l.message);const c=o?.[0]??null,u=(o??[]).slice(1).map(a=>a.id);if(!s){if(o?.length){const a=o.map(m=>m.id),{error:d}=await e.from("user_addresses").delete().in("id",a);if(d)throw new Error(d.message)}return}const y={user_id:r,address_type:t,is_default:!0,company_name:s.company_name??null,recipient_name:s.recipient_name??null,line1:s.line1??null,line2:s.line2??null,city:s.city??null,state:s.state??null,postal_code:s.postal_code??null,country_code:s.country_code??null,updated_at:new Date().toISOString()};if(c){const{error:a}=await e.from("user_addresses").update(y).eq("id",c.id);if(a)throw new Error(a.message)}else{const{error:a}=await e.from("user_addresses").insert(y);if(a)throw new Error(a.message)}if(u.length){const{error:a}=await e.from("user_addresses").delete().in("id",u);if(a)throw new Error(a.message)}}async function Ee(e,r){const t=r??P.createClient(),{data:n,error:s}=await t.from("user_addresses").select("*").eq("user_id",e).in("address_type",["billing","shipping"]).order("is_default",{ascending:!1}).order("updated_at",{ascending:!1});if(s)throw new Error(s.message);const o=ne(se(n??[],"billing")),l=ne(se(n??[],"shipping"));return{billingAddress:o,shippingAddress:l}}async function ae(e){const r=e.client??P.createClient();await ie(r,e.userId,"billing",e.billingAddress??null),await ie(r,e.userId,"shipping",e.shippingAddress??null)}async function ce(e){const r=e.client??P.createClient(),t=D(e.fullName),n=D(e.phone);if(!t&&!n)return;const{data:s,error:o}=await r.from("profiles").select("full_name, phone").eq("id",e.userId).maybeSingle();if(o)throw new Error(o.message);if(!s)return;const l=D(s.full_name)||t,c=D(s.phone)||n;if(D(s.full_name)===l&&D(s.phone)===c)return;const{error:u}=await r.from("profiles").update({full_name:l,phone:c,updated_at:new Date().toISOString()}).eq("id",e.userId);if(u)throw new Error(u.message)}function p(e){const r=process.env[e];if(!r)return null;const t=r.trim();return t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")?t.slice(1,-1).trim():t}function he(e){const r=e?.trim();if(!r)return{firstName:null,lastName:null};const[t,...n]=r.split(/\s+/);return{firstName:t||null,lastName:n.length>0?n.join(" "):null}}function ue(e){if(e==null||e==="")return 0;const r=Number(e);return!Number.isFinite(r)||r<=0?0:Math.round(r)}function Se(e){return e===!0||e===1||e==="1"||e==="true"}function we(e,r){const t=e?.[r];return Array.isArray(t)?t:t&&typeof t=="object"?[t]:[]}function W(e,r){for(const t of r){const n=we(e,t);if(n.length>0)return n}return Array.isArray(e)?e:[]}function k(e){if(e==null||e==="")return null;const r=Number(e);return Number.isFinite(r)?r:null}function Pe(e){return e===null?0:e>5e3?(console.warn(`[Freemius Sync] Suspiciously high price detected: ${e}. Assuming it is already in cents.`),Math.round(e)):Math.round(e*100)}function Fe(e){const r=Number(e);return!Number.isFinite(r)||r<1?1:Math.round(r)}function le(){const e=p("FREEMIUS_CHECKOUT_PRODUCTS_JSON");if(!e)return null;try{const r=JSON.parse(e);return r&&typeof r=="object"?r:null}catch(r){return console.error("[Freemius Checkout] Failed to parse FREEMIUS_CHECKOUT_PRODUCTS_JSON:",r),null}}function de(e){const r=le(),t=String(e),n=r?.[t],s=p("FREEMIUS_PRODUCT_ID"),o=p("FREEMIUS_ECOMMERCE_SANDBOX_PUBLIC_KEY"),l=p("FREEMIUS_ECOMMERCE_SANDBOX_SECRET_KEY");return n?.publicKey?{publicKey:n.publicKey,secretKey:n.secretKey??null,apiKey:n.apiKey??null,source:"product-map"}:process.env.FREEMIUS_SANDBOX_ENABLED==="true"&&s&&s===t&&o?{publicKey:o,secretKey:l,apiKey:p("FREEMIUS_API_KEY"),source:"single-product-sandbox-env"}:s&&s===t&&p("FREEMIUS_PUBLIC_KEY")?{publicKey:p("FREEMIUS_PUBLIC_KEY"),secretKey:p("FREEMIUS_SECRET_KEY"),apiKey:p("FREEMIUS_API_KEY"),source:"single-product-env"}:{publicKey:p("FREEMIUS_PUBLIC_KEY"),secretKey:p("FREEMIUS_SECRET_KEY"),apiKey:p("FREEMIUS_API_KEY"),source:"legacy-env"}}async function Ce(e){if(!e.apiKey)throw new Error("Missing Freemius API key for SDK sandbox generation.");return new ye.Freemius({productId:Number(e.productId),apiKey:e.apiKey,secretKey:e.secretKey,publicKey:e.publicKey}).checkout.getSandboxParams()}class be{getProviderName(){return"Freemius"}async createCheckoutSession({items:r,customerEmail:t,customerPhone:n,userId:s,billingAddress:o,shippingAddress:l,currencyCode:c,couponCode:u,couponContextItems:y}){const a=process.env.NEXT_PUBLIC_SUPABASE_URL,d=process.env.SUPABASE_SERVICE_ROLE_KEY;if(!a||!d)return{error:"Missing Supabase credentials for checkout (Service Key required).",url:null};const m=J.createClient(a,d);if(!r||r.length===0)return{error:"Cart is empty",url:null};if(r.length!==1)return{error:"Freemius items must be checked out one at a time.",url:null};const{data:E,error:v}=await m.from("currencies").select("code, symbol, exchange_rate, is_default, is_active, auto_sync_product_prices, auto_update_exchange_rate, exchange_rate_source, exchange_rate_updated_at, rounding_mode, rounding_increment, rounding_charm_amount").eq("is_active",!0).order("code",{ascending:!0}),I=E??[];if(v||I.length===0)return{error:"Failed to resolve store currencies",url:null};const H=V.getDefaultCurrency(I),K=I.find(f=>f.code===(c||"").toUpperCase())??H,h=r[0],{data:_,error:$}=await m.from("products").select("id, title, price, prices, sale_price, sale_prices, sale_start_at, sale_end_at, scheduled_price, scheduled_prices, scheduled_price_at, freemius_plan_id, freemius_product_id, trial_period_days, trial_requires_payment_method").eq("id",h.product_id).single();if($||!_)return{error:"Product not found",url:null};const U=_.freemius_plan_id,F=_.freemius_product_id;if(!U||!F)return{error:"Product is not configured for Freemius checkout (missing Plan ID or Product ID)",url:null};const N=V.resolveEffectivePriceForCurrency({prices:_.prices||{},salePrices:_.sale_prices||{},fallbackPrice:_.price,fallbackSalePrice:_.sale_price,saleStartAt:_.sale_start_at,saleEndAt:_.sale_end_at,scheduledPrice:_.scheduled_price,scheduledPrices:_.scheduled_prices||{},scheduledPriceAt:_.scheduled_price_at,currencyCode:K.code,currencies:I}),O=N.sale_price??N.price,x=V.isSaleWindowActive({saleStartAt:_.sale_start_at,saleEndAt:_.sale_end_at}),S=O*h.quantity;let i=null,g=0;if(u){const f=await te.getCouponQuote({client:m,code:u,items:y&&y.length>0?y:r,currencyCode:K.code});if(!f.success)return{error:f.error,errorKey:f.errorKey,errorStatus:400,url:null};i=f.quote,g=Math.min(S,i.lineDiscounts.filter(A=>A.product_id===_.id).reduce((A,X)=>A+X.discount,0))}const C=ue(_.trial_period_days),R=C>0?h.trial_preference?h.trial_preference:_.trial_requires_payment_method?"paid":"free":null,B="pending",w=he(o?.recipient_name??null),{data:z,error:Z}=await m.from("orders").insert({status:B,total:Math.max(0,S-g),currency:K.code,exchange_rate_at_purchase:K.exchange_rate,subtotal:S,discount_total:g,coupon_id:i?.couponId??null,coupon_code:i?.code??null,discount_details:i?{code:i.code,discount_type:i.discountType,discount_amount:i.discountAmount,provider:"freemius",provider_discounts:i.providerDiscounts,line_discounts:i.lineDiscounts,final_amount_owned_by:"freemius"}:null,provider:"freemius",freemius_product_id:String(F),freemius_plan_id:String(U),user_id:s||null,customer_details:Q.normalizeOrderCustomerDetails({email:t,phone:n,name:o?.recipient_name,billing:o,shipping:l})}).select("id").single();if(Z||!z)return console.error("Failed to create pending order:",Z),{error:"Failed to initiate order",url:null};const{error:ee}=await m.from("order_items").insert([{order_id:z.id,product_id:_.id,quantity:h.quantity,price_at_purchase:O}]);if(ee&&console.error("Failed to insert order items:",ee),s)try{await ae({userId:s,billingAddress:o,shippingAddress:l,client:m}),await ce({userId:s,fullName:o?.recipient_name??l?.recipient_name??null,phone:n,client:m})}catch(f){console.error("Failed to sync checkout profile defaults before checkout:",f)}i&&await te.recordCouponRedemption({client:m,quote:i,orderId:z.id,provider:"freemius",discountTotal:g,userId:s,customerEmail:t,metadata:{currency:K.code,subtotal:S,final_amount_owned_by:"freemius"}});const T=process.env.FREEMIUS_SANDBOX_ENABLED==="true",M=de(F),q=M.publicKey,L=M.secretKey,re=M.apiKey;if(!q||T&&!L)return{error:"Missing FREEMIUS credentials (PUBLIC_KEY or SECRET_KEY) in environment variables.",url:null};if(T&&M.source==="legacy-env"){const f=p("FREEMIUS_PRODUCT_ID"),A=!!p("FREEMIUS_ECOMMERCE_SANDBOX_PUBLIC_KEY"),X=!!p("FREEMIUS_ECOMMERCE_SANDBOX_SECRET_KEY");console.warn(`[Freemius Checkout] Sandbox is enabled for product ${F}, but no product-scoped checkout credentials were selected. Falling back to legacy FREEMIUS_PUBLIC_KEY/FREEMIUS_SECRET_KEY may open live checkout instead of sandbox.`,{configuredProductId:f,productIdsMatch:f===String(F),hasSandboxOverridePublicKey:A,hasSandboxOverrideSecretKey:X,hasCheckoutProductsJson:!!p("FREEMIUS_CHECKOUT_PRODUCTS_JSON")})}let Y=!1;if(T&&L&&q)try{Y=await Ce({productId:F,publicKey:q,secretKey:L,apiKey:re})}catch(f){console.warn("Freemius Checkout - SDK sandbox generation failed. Falling back to manual token generation.",f,{credentialSource:M.source,hasApiKey:!!re});const A=Math.floor(Date.now()/1e3).toString(),X=`${A}${F}${L}${q}checkout`,ge=oe.createHash("md5").update(X).digest("hex");Y={ctx:A,token:ge}}const b=new URL(`https://checkout.freemius.com/app/${F}/plan/${U}/`);if(T&&L&&q?(b.searchParams.append("sandbox",Y.token),b.searchParams.append("s_ctx_ts",Y.ctx)):T&&b.searchParams.append("sandbox","true"),t&&b.searchParams.append("user_email",t),w.firstName&&b.searchParams.append("user_firstname",w.firstName),w.lastName&&b.searchParams.append("user_lastname",w.lastName),b.searchParams.append("currency",K.code.toLowerCase()),h.billing_cycle&&b.searchParams.append("billing_cycle",h.billing_cycle),R&&b.searchParams.append("trial",R),i)b.searchParams.append("coupon",i.code);else if(x){const{data:f}=await m.from("product_freemius_sale_coupons").select("freemius_coupon_code, is_active, starts_at, ends_at, sync_status").eq("product_id",_.id).maybeSingle();f?.is_active&&f.sync_status==="synced"&&f.freemius_coupon_code&&V.isSaleWindowActive({saleStartAt:f.starts_at,saleEndAt:f.ends_at})&&b.searchParams.append("coupon",f.freemius_coupon_code)}return{url:b.toString(),customProps:{provider:"freemius",plugin_id:F,plan_id:U,public_key:q,user_email:t,user_firstname:w.firstName,user_lastname:w.lastName,credential_source:M.source,sandbox:Y,billing_cycle:h.billing_cycle,trial:R,trial_period_days:C,trial_requires_payment_method:_.trial_requires_payment_method,initial_order_status:B,coupon:i?.code??null,order_id:z.id}}}}async function pe(e,r,t,n){const o=new Date().toUTCString().replace("GMT","+0000"),l=`GET
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
${o}
|
|
5
|
-
${e}`,c=oe.createHmac("sha256",n).update(l).digest("hex"),u=Buffer.from(c).toString("base64").replace(/\+/g,"-").replace(/\//g,"_").replace(/=/g,""),y=`FS ${r}:${t}:${u}`,a=await fetch(`https://api.freemius.com${e}`,{headers:{Authorization:y,Date:o,Accept:"application/json"}});if(!a.ok){const d=await a.text();throw console.error(`[Freemius API] [ERROR] ${e} returned ${a.status}: ${d}`),new Error(`Freemius API failed on ${e}: ${a.status} - ${d}`)}return a.json()}async function _e(){const e=p("FREEMIUS_DEVELOPER_ID"),r=p("FREEMIUS_PUBLIC_KEY"),t=p("FREEMIUS_SECRET_KEY"),n=process.env.NEXT_PUBLIC_SUPABASE_URL,s=process.env.SUPABASE_SERVICE_ROLE_KEY;if(!e||!r||!t||!n||!s)throw new Error("Missing necessary environment variables for Freemius Sync.");const o=J.createClient(n,s,{auth:{autoRefreshToken:!1,persistSession:!1}}),l=c=>pe(c,e,r,t);try{console.log(`[Freemius Sync] Fetching all plugins for developer ${e}...`);const c=await l(`/v1/developers/${e}/plugins.json`),u=W(c,["plugins","plugin"]);console.log(`[Freemius Sync] Found ${u.length} plugins. Syncing plans...`);let y=0;const{data:a}=await o.from("languages").select("id").eq("code","en").single(),d=a?.id;if(!d)throw new Error("English language not found in database. Cannot sync products.");for(const m of u){const E=m.id?.toString();if(!E){console.warn("[Freemius Sync] Skipping plugin without an id:",m);continue}const v=await fe(o,e,E,m.title||m.name||`Freemius Product ${E}`,l,d);y+=v}return{success:!0,count:y}}catch(c){throw console.error("[Freemius Sync] Global Error:",c),c}}async function me(e){const r=p("FREEMIUS_DEVELOPER_ID"),t=p("FREEMIUS_PUBLIC_KEY"),n=p("FREEMIUS_SECRET_KEY"),s=process.env.NEXT_PUBLIC_SUPABASE_URL,o=process.env.SUPABASE_SERVICE_ROLE_KEY;if(!r||!t||!n||!s||!o)throw new Error("Missing environment variables for Freemius Sync.");const l=J.createClient(s,o),c=E=>pe(E,r,t,n),{data:u}=await l.from("languages").select("id").eq("code","en").single(),y=u?.id;if(!y)throw new Error("English language not found in database. Cannot sync products.");const a=await c(`/v1/developers/${r}/plugins/${e}.json`),d=a.plugin??a;return{success:!0,count:await fe(l,r,e,d.title||d.name||`Freemius Product ${e}`,c,y)}}async function fe(e,r,t,n,s,o){console.log(`[Freemius Sync] Fetching plans for plugin: ${n} (${t})...`);let l=0;try{const c=`/v1/developers/${r}/plugins/${t}/plans.json`,u=await s(c),y=W(u,["plans","plan"]);console.log(`[Freemius Sync] Received ${y.length} plans for plugin ${t}.`);for(const a of y){const d=a.id?.toString();if(!d){console.warn("[Freemius Sync] Skipping plan without an id:",a);continue}const m=a.name||a.title||d,E=a.title||m;console.log(`[Freemius Sync] Processing plan: ${E} (${d})...`);let v=a;if(v.trial_period===void 0||v.is_require_subscription===void 0)try{const i=`/v1/developers/${r}/plugins/${t}/plans/${d}.json`,g=await s(i),C=g.plan??g;v={...v,...C}}catch(i){console.warn(`[Freemius Sync] Could not fetch trial details for plan ${d}:`,i instanceof Error?i.message:i)}const I=ue(v.trial_period),H=I>0&&Se(v.is_require_subscription);let K=0,h=[];try{const i=`/v1/developers/${r}/plugins/${t}/plans/${d}/pricing.json`,g=await s(i);if(h=W(g,["pricing","prices","pricings"]),h.length>0){const C=h[0],R=k(C.annual_price)??k(C.monthly_price)??k(C.lifetime_price);K=Pe(R)}console.log(`[Freemius Sync] Plan: ${E} -> Resolved Price (cents): ${K}`)}catch(i){console.warn(`[Freemius Sync] Could not fetch pricing for plan ${d}:`,i instanceof Error?i.message:i)}const _=`${n}-${E}`.toLowerCase().replace(/[^\w\s-]/g,"").replace(/[\s_]+/g,"-").replace(/^-+|-+$/g,""),$={title:`${n} - ${E}`,slug:_,short_description:a.description||"",price:K,product_type:"digital",payment_provider:"freemius",freemius_plan_id:d,freemius_product_id:t,trial_period_days:I,trial_requires_payment_method:H,status:"active",stock:999,sku:`FM-${t}-${d}`,language_id:o},{data:U,error:F}=await e.from("products").upsert($,{onConflict:"language_id, sku"}).select();if(F||!U||U.length===0){console.error(`[Freemius Sync] Error upserting product ${$.sku}:`,F);continue}const N=U[0].id,{data:O,error:x}=await e.from("freemius_plans").select("id").eq("product_id",N).eq("name",m).maybeSingle();x&&console.warn(`[Freemius Sync] Could not check existing local plan for ${$.sku}:`,x.message||x);let S="";if(O){S=O.id;const{error:i}=await e.from("freemius_plans").update({title:E,updated_at:new Date().toISOString()}).eq("id",S);i&&console.warn(`[Freemius Sync] Could not update local plan ${S}:`,i.message||i)}else{const{data:i,error:g}=await e.from("freemius_plans").insert({product_id:N,name:m,title:E}).select("id").single();g&&console.warn(`[Freemius Sync] Could not insert local plan for ${$.sku}:`,g.message||g),i&&(S=i.id)}if(S&&h.length>0)for(const i of h){const g=Fe(i.licenses??i.license_quota??i.quota),{data:C,error:R}=await e.from("freemius_pricing").select("id").eq("plan_id",S).eq("license_quota",g).maybeSingle();R&&console.warn(`[Freemius Sync] Could not check pricing for plan ${S}, quota ${g}:`,R.message||R);const B={api_monthly_price:k(i.monthly_price),api_annual_price:k(i.annual_price),api_lifetime_price:k(i.lifetime_price),updated_at:new Date().toISOString()};if(C){const{error:w}=await e.from("freemius_pricing").update(B).eq("id",C.id);w&&console.warn(`[Freemius Sync] Could not update pricing ${C.id}:`,w.message||w)}else{const{error:w}=await e.from("freemius_pricing").insert({plan_id:S,license_quota:g,...B});w&&console.warn(`[Freemius Sync] Could not insert pricing for plan ${S}, quota ${g}:`,w.message||w)}}console.log(`[Freemius Sync] Successfully fully synced product ${$.sku}.`),l++}}catch(c){console.error(`[Freemius Sync] Failed sync for plugin ${t}:`,c.message)}return l}async function ve(e){const r=P.createClient(),{data:t,count:n,error:s}=await await G.getProducts(r,e);if(s)throw new Error(s.message);return{data:t,count:n}}async function Ke(e){const r=P.createClient(),{data:t,error:n}=await G.getProduct(r,e);if(n)throw new Error(n.message);return t}async function Re(){try{const e=await _e();return j.revalidatePath("/cms/products","page"),{success:!0,data:e}}catch(e){return{error:e.message||"Failed to sync with Freemius"}}}async function Ue(e){try{const r=await me(e);return j.revalidatePath("/cms/products","page"),{success:!0,data:r}}catch(r){return{error:r.message||"Failed to sync product with Freemius"}}}async function Ae(e,r){try{const t=P.createClient();return await G.copyProductFromLanguage(t,e,r),j.revalidatePath("/cms/products"),j.revalidatePath(`/cms/products/${e}/edit`),{success:!0}}catch(t){return{success:!1,error:t.message||"Failed to copy product content"}}}async function Ie(e){const r=P.createClient(),{data:t,error:n}=await r.from("products").select("id, title, language_id, slug").eq("translation_group_id",e);if(n)throw new Error(n.message);return t}async function $e(){const e=P.getServiceRoleSupabaseClient(),{data:r,error:t}=await e.from("product_attributes").select(`
|
|
6
|
-
id,
|
|
7
|
-
name,
|
|
8
|
-
name_translations,
|
|
9
|
-
slug,
|
|
10
|
-
product_attribute_terms (
|
|
11
|
-
id,
|
|
12
|
-
attribute_id,
|
|
13
|
-
value,
|
|
14
|
-
slug,
|
|
15
|
-
sort_order,
|
|
16
|
-
value_translations
|
|
17
|
-
)
|
|
18
|
-
`);if(t)throw new Error(t.message);return(r||[]).map(n=>({...n,product_attribute_terms:(n.product_attribute_terms||[]).sort((s,o)=>(s.sort_order??Number.MAX_SAFE_INTEGER)-(o.sort_order??Number.MAX_SAFE_INTEGER)||s.value.localeCompare(o.value))})).sort((n,s)=>n.name.localeCompare(s.name))}async function Me(e){const r=P.createClient(),{data:t,error:n}=await r.from("freemius_plans").select(`
|
|
19
|
-
id,
|
|
20
|
-
name,
|
|
21
|
-
title,
|
|
22
|
-
freemius_pricing (
|
|
23
|
-
id,
|
|
24
|
-
license_quota,
|
|
25
|
-
api_monthly_price,
|
|
26
|
-
api_annual_price,
|
|
27
|
-
api_lifetime_price,
|
|
28
|
-
override_monthly_price,
|
|
29
|
-
override_annual_price,
|
|
30
|
-
override_lifetime_price,
|
|
31
|
-
is_active
|
|
32
|
-
)
|
|
33
|
-
`).eq("product_id",e);if(n)throw new Error(n.message);return t}async function qe(e,r){const t=P.createClient(),{error:n}=await t.from("freemius_pricing").update({...r,updated_at:new Date().toISOString()}).eq("id",e);return n?{success:!1,error:n.message}:(j.revalidatePath("/cms/products"),{success:!0})}async function De(e){const r=P.createClient(),{data:t}=await r.from("products").select("translation_group_id").eq("id",e).maybeSingle();let n=[e];if(t?.translation_group_id){const{data:c}=await r.from("products").select("id").eq("translation_group_id",t.translation_group_id);c&&c.length>0&&(n=c.map(u=>u.id))}const{data:s,error:o}=await r.from("freemius_plans").select(`
|
|
34
|
-
id,
|
|
35
|
-
name,
|
|
36
|
-
title,
|
|
37
|
-
freemius_pricing (
|
|
38
|
-
id,
|
|
39
|
-
license_quota,
|
|
40
|
-
api_monthly_price,
|
|
41
|
-
api_annual_price,
|
|
42
|
-
api_lifetime_price,
|
|
43
|
-
override_monthly_price,
|
|
44
|
-
override_annual_price,
|
|
45
|
-
override_lifetime_price,
|
|
46
|
-
is_active
|
|
47
|
-
)
|
|
48
|
-
`).in("product_id",n);if(o)throw new Error(o.message);return(s||[]).map(c=>({id:c.id,name:c.name,title:c.title,pricing:(c.freemius_pricing||[]).filter(u=>u.is_active!==!1).map(u=>({id:u.id,license_quota:u.license_quota,monthly_price:u.override_monthly_price??u.api_monthly_price,annual_price:u.override_annual_price??u.api_annual_price,lifetime_price:u.override_lifetime_price??u.api_lifetime_price,is_active:u.is_active}))}))}async function ke(){const e=P.createClient(),{data:r,error:t}=await e.from("categories").select("id, name, slug, description, created_at, name_translations, description_translations, product_categories(count)").order("name",{ascending:!0});if(t)throw new Error(t.message);return(r||[]).map(n=>{const s=n.product_categories?.[0]?.count??n.product_categories?.count??0;return{id:n.id,name:n.name,slug:n.slug,description:n.description??"",created_at:n.created_at,productCount:Number(s),name_translations:n.name_translations||{},description_translations:n.description_translations||{}}})}async function Ne(e){const r=P.createClient(),{data:t,error:n}=await r.from("categories").select("id, name, slug, description, created_at").eq("slug",e).maybeSingle();if(n)throw new Error(n.message);return t}async function Oe(e){const r=P.createClient(),{data:t,error:n}=await r.from("product_categories").select("category:categories(id, name, slug, description, name_translations, description_translations, created_at)").eq("product_id",e);if(n)throw new Error(n.message);return(t||[]).map(s=>s.category).filter(Boolean)}exports.FreemiusProvider=be;exports.copyProductFromLanguageAction=Ae;exports.fillMissingUserProfileCheckoutDetails=ce;exports.getCategoriesWithCount=ke;exports.getCategoryBySlug=Ne;exports.getDefaultUserAddresses=Ee;exports.getFreemiusPricingByProductId=Me;exports.getGlobalProductAttributes=$e;exports.getProduct=Ke;exports.getProductCategories=Oe;exports.getProductTranslations=Ie;exports.getProducts=ve;exports.getPublicFreemiusPricing=De;exports.parseFreemiusCheckoutCredentialsMap=le;exports.readFreemiusEnvValue=p;exports.resolveFreemiusCheckoutCredentials=de;exports.syncFreemiusProductsToSupabase=_e;exports.syncSingleFreemiusProduct=me;exports.triggerFreemiusSync=Re;exports.triggerSingleProductSync=Ue;exports.updateFreemiusOverride=qe;exports.upsertDefaultUserAddresses=ae;
|