@nextblock-cms/ecom 0.9.95 → 0.9.99
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/lib/cart-store.d.ts +3 -3
- package/lib/currency-rest-client.cjs.js +1 -1
- package/lib/currency-rest-client.es.js +7 -7
- package/lib/currency-sync.d.ts +3 -3
- package/lib/currency.d.ts +7 -7
- package/lib/freemius-order-sync.cjs.js +1 -1
- package/lib/freemius-order-sync.es.js +29 -29
- package/lib/pages/cms/orders/export-actions.d.ts +1 -1
- package/lib/pages/cms/orders/server-actions.cjs.js +1 -1
- package/lib/pages/cms/orders/server-actions.es.js +16 -16
- package/lib/pages/cms/products/actions.d.ts +205 -6
- package/lib/pages/cms/products/server-actions.d.ts +11 -11
- package/lib/pages/cms/shipping/server-actions.d.ts +6 -6
- package/lib/product-actions.d.ts +255 -4
- package/lib/product-schema.d.ts +1 -1
- package/lib/providers/freemius.cjs.js +2 -2
- package/lib/providers/freemius.es.js +159 -159
- package/lib/providers/stripe.cjs.js +1 -1
- package/lib/providers/stripe.es.js +51 -51
- package/lib/shipping-rate-currency.d.ts +5 -5
- package/lib/stripe/checkout.cjs.js +1 -1
- package/lib/stripe/checkout.es.js +25 -25
- package/lib/stripe/order-sync.cjs.js +1 -1
- package/lib/stripe/order-sync.d.ts +6 -6
- package/lib/stripe/order-sync.es.js +38 -38
- package/package.json +4 -4
package/lib/cart-store.d.ts
CHANGED
|
@@ -39,9 +39,9 @@ export declare function getCartItemActivePrice(item: CartItem, params: {
|
|
|
39
39
|
currencyCode: string;
|
|
40
40
|
currencies: ReturnType<typeof useCurrency>['currencies'];
|
|
41
41
|
}): {
|
|
42
|
-
currencyCode:
|
|
43
|
-
price:
|
|
44
|
-
sale_price:
|
|
42
|
+
currencyCode: string;
|
|
43
|
+
price: number;
|
|
44
|
+
sale_price: number | null;
|
|
45
45
|
};
|
|
46
46
|
export declare const useCartSubtotal: () => number;
|
|
47
47
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});async function c(){const
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});async function c(){const s=process.env.NEXT_PUBLIC_SUPABASE_URL||process.env.SUPABASE_URL,r=process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY||process.env.SUPABASE_ANON_KEY||process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY||process.env.SUPABASE_PUBLISHABLE_KEY;if(!s||!r)return[];const e=new URL("/rest/v1/currencies",s);e.searchParams.set("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"),e.searchParams.set("is_active","eq.true"),e.searchParams.set("order","code.asc");const t=await fetch(e.toString(),{headers:{apikey:r,Authorization:`Bearer ${r}`}});if(!t.ok)return[];const a=await t.json();return Array.isArray(a)?a:[]}exports.fetchActiveCurrenciesFromRest=c;
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
async function n() {
|
|
2
|
-
const
|
|
3
|
-
if (!
|
|
2
|
+
const s = process.env.NEXT_PUBLIC_SUPABASE_URL || process.env.SUPABASE_URL, r = process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY || process.env.SUPABASE_ANON_KEY || process.env.NEXT_PUBLIC_SUPABASE_PUBLISHABLE_KEY || process.env.SUPABASE_PUBLISHABLE_KEY;
|
|
3
|
+
if (!s || !r)
|
|
4
4
|
return [];
|
|
5
|
-
const e = new URL("/rest/v1/currencies",
|
|
5
|
+
const e = new URL("/rest/v1/currencies", s);
|
|
6
6
|
e.searchParams.set(
|
|
7
7
|
"select",
|
|
8
8
|
"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"
|
|
9
9
|
), e.searchParams.set("is_active", "eq.true"), e.searchParams.set("order", "code.asc");
|
|
10
|
-
const
|
|
10
|
+
const a = await fetch(e.toString(), {
|
|
11
11
|
headers: {
|
|
12
12
|
apikey: r,
|
|
13
13
|
Authorization: `Bearer ${r}`
|
|
14
14
|
}
|
|
15
15
|
});
|
|
16
|
-
if (!
|
|
16
|
+
if (!a.ok)
|
|
17
17
|
return [];
|
|
18
|
-
const
|
|
19
|
-
return Array.isArray(
|
|
18
|
+
const t = await a.json();
|
|
19
|
+
return Array.isArray(t) ? t : [];
|
|
20
20
|
}
|
|
21
21
|
export {
|
|
22
22
|
n as fetchActiveCurrenciesFromRest
|
package/lib/currency-sync.d.ts
CHANGED
|
@@ -3,11 +3,11 @@ export declare function rebaseStoreCurrencyExchangeRates(params: {
|
|
|
3
3
|
previousBaseRate: number;
|
|
4
4
|
}): Promise<{
|
|
5
5
|
rebasedAt: string;
|
|
6
|
-
newDefaultCurrencyCode:
|
|
6
|
+
newDefaultCurrencyCode: string;
|
|
7
7
|
updatedCurrencies: string[];
|
|
8
8
|
}>;
|
|
9
9
|
export declare function syncStoreCurrencyRates(): Promise<{
|
|
10
|
-
baseCurrencyCode:
|
|
10
|
+
baseCurrencyCode: string;
|
|
11
11
|
fetchedAt: string;
|
|
12
12
|
provider: string;
|
|
13
13
|
providerUrl: string;
|
|
@@ -15,5 +15,5 @@ export declare function syncStoreCurrencyRates(): Promise<{
|
|
|
15
15
|
updatedCurrencies: string[];
|
|
16
16
|
}>;
|
|
17
17
|
export declare function clearAutoSyncedCurrencyPriceOverrides(currencyCode: string): Promise<{
|
|
18
|
-
currencyCode:
|
|
18
|
+
currencyCode: string;
|
|
19
19
|
}>;
|
package/lib/currency.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export declare function convertMinorUnitAmount(params: {
|
|
|
29
29
|
toCurrencyCode?: string | null;
|
|
30
30
|
currencies: CurrencyRecord[];
|
|
31
31
|
applyRounding?: boolean;
|
|
32
|
-
}):
|
|
32
|
+
}): number;
|
|
33
33
|
export declare function applyCurrencyRounding(params: {
|
|
34
34
|
amount: number;
|
|
35
35
|
currencyCode?: string | null;
|
|
@@ -44,9 +44,9 @@ export declare function resolvePriceForCurrency(params: {
|
|
|
44
44
|
currencyCode?: string | null;
|
|
45
45
|
currencies: CurrencyRecord[];
|
|
46
46
|
}): {
|
|
47
|
-
currencyCode:
|
|
48
|
-
price:
|
|
49
|
-
sale_price:
|
|
47
|
+
currencyCode: string;
|
|
48
|
+
price: number;
|
|
49
|
+
sale_price: number | null;
|
|
50
50
|
};
|
|
51
51
|
/**
|
|
52
52
|
* Returns whether a scheduled sale window is active at `now` (defaults to the
|
|
@@ -89,9 +89,9 @@ export declare function resolveEffectivePriceForCurrency(params: {
|
|
|
89
89
|
currencies: CurrencyRecord[];
|
|
90
90
|
now?: Date;
|
|
91
91
|
}): {
|
|
92
|
-
currencyCode:
|
|
93
|
-
price:
|
|
94
|
-
sale_price:
|
|
92
|
+
currencyCode: string;
|
|
93
|
+
price: number;
|
|
94
|
+
sale_price: number | null;
|
|
95
95
|
};
|
|
96
96
|
export declare function resolvePriceRangeForCurrency(params: {
|
|
97
97
|
entries: Array<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("crypto"),C=require("@freemius/sdk"),O=require("@supabase/supabase-js"),R=require("./invoice-server.cjs.js"),
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const p=require("crypto"),C=require("@freemius/sdk"),O=require("@supabase/supabase-js"),R=require("./invoice-server.cjs.js"),A=require("./order-inventory.cjs.js"),d=require("./providers/freemius.cjs.js");function s(e){return e==null||e===""?null:String(e)}function a(e){const r=s(e);if(!r)return null;const t=r.includes("T")?r:r.replace(" ","T")+"Z",i=new Date(t);return Number.isNaN(i.getTime())?r:i.toISOString()}function K(e){if(e==null||e==="")return null;const r=Number(e);return Number.isFinite(r)?r:null}function m(...e){return e.some(r=>{const t=K(r);return t!==null&&t>0})}function l(e){return e==="pending"||e==="trial"}function y(e){return["license.cancelled","license.deleted","license.expired","subscription.cancelled","subscription.renewal.failed.last","trial.cancelled","trial.expired"].includes(e||"")}function j(e,r){return e==="license.extended"&&(r?.is_renewal===!0||r?.is_renewal===1||r?.is_renewal==="1"||r?.is_renewal==="true")}function x(e){const r=e.objects?.payment??e.data?.payment??e.data;return e.type==="payment.created"&&m(r?.gross,r?.total_gross,r?.amount,r?.initial_amount)}function b(e){const r=e?.purchase??null,t=e?.trial??null;return{freemius_product_id:s(r?.plugin_id)??s(r?.product_id)??s(r?.productId)??s(t?.plugin_id)??s(t?.product_id)??s(t?.productId),freemius_plan_id:s(r?.plan_id)??s(r?.planId),freemius_license_id:s(r?.license_id)??s(r?.licenseId)??s(t?.license_id)??s(t?.licenseId),freemius_subscription_id:s(r?.subscription_id)??s(r?.subscriptionId)??s(t?.subscription_id)??s(t?.subscriptionId),freemius_trial_id:s(t?.id),freemius_user_id:s(r?.user_id)??s(r?.userId)??s(t?.user_id)??s(t?.userId)??s(e?.user?.id),freemius_trial_ends_at:a(t?.trial_ends_at)??a(t?.trialEndsAt)??a(r?.trial_ends)??a(r?.trialEnds)}}function S(e,r="pending"){const t=e?.purchase??null,i=e?.trial??null;return r==="paid"?"paid":i&&(i.canceled_at||i.canceledAt)&&l(r)?"cancelled":i?"trial":t?(t.canceled_at||t.canceledAt)&&l(r)?"cancelled":m(t.initial_amount,t.initialAmount,t.gross,t.total_gross,t.totalGross)?"paid":t.trial_ends||t.trialEnds||t.subscription_id||t.subscriptionId?"trial":r:r}function f(e){const{event:r,currentStatus:t,purchaseData:i}=e;return t==="paid"&&y(r.type)?"paid":y(r.type)?l(t)?"cancelled":t:x(r)||j(r.type,r.data)||i&&m(i.initialAmount,i.initial_amount,i.gross,i.totalGross,i.total_gross)?"paid":i?.canceled===!0&&l(t)?"cancelled":(i?.subscriptionId||i?.subscription_id||r.type==="subscription.created"||r.type==="license.created")&&t==="pending"?"trial":t}function M(e,r){const t={freemius_last_event_type:r,freemius_last_synced_at:new Date().toISOString()};for(const[i,n]of Object.entries(e))n!=null&&n!==""&&(t[i]=n);return t}function E(){const e=process.env.NEXT_PUBLIC_SUPABASE_URL||process.env.SUPABASE_URL,r=process.env.SUPABASE_SERVICE_ROLE_KEY||process.env.SUPABASE_SECRET_KEY;if(!e||!r)throw new Error("Missing Supabase Service Role environment variables");return O.createClient(e,r,{auth:{autoRefreshToken:!1,persistSession:!1}})}async function N(e,r){const{data:t,error:i}=await e.from("orders").select("id, status, provider, freemius_product_id, freemius_plan_id, freemius_license_id, freemius_subscription_id, freemius_trial_id, freemius_user_id, freemius_trial_ends_at").eq("id",r).single();if(i||!t)throw new Error(i?.message||"Order not found");return t}async function P(e,r){const{data:t,error:i}=await e.from("orders").select("id, status, provider, freemius_product_id, freemius_plan_id, freemius_license_id, freemius_subscription_id, freemius_trial_id, freemius_user_id, freemius_trial_ends_at").eq("freemius_license_id",r).order("created_at",{ascending:!1}).limit(1).maybeSingle();if(i)throw new Error(i.message);return t??null}async function g(e){const r=M(e.metadata,e.eventType),t=e.order.status,i=t==="paid"&&e.nextStatus!=="paid"?"paid":e.nextStatus;i!==t&&(r.status=i);const{error:n}=await e.client.from("orders").update(r).eq("id",e.order.id);if(n)throw new Error(n.message);return i==="paid"&&t!=="paid"&&(await R.assignInvoiceMetadata({orderId:e.order.id,client:e.client}),await A.applyOrderInventoryDeduction(e.client,e.order.id)),i}async function T(e){const r=e.client??E(),t=await N(r,e.orderId);if(t.provider!=="freemius")return{success:!1,error:"Only Freemius orders can be synced from Freemius checkout"};const i=b(e.checkoutResponse);let n=null;if(i.freemius_license_id)try{n=await F(i.freemius_product_id??t.freemius_product_id,i.freemius_license_id)}catch(k){console.error("[Freemius Checkout Sync] Failed to retrieve purchase data:",k)}const u={type:"checkout.purchaseCompleted",data:{license_id:i.freemius_license_id},objects:{}},c={...i,...v(u,n)},o=S(e.checkoutResponse,t.status),_=n?f({event:u,currentStatus:t.status,purchaseData:n}):o==="paid"?t.status:o,w=await g({client:r,order:t,nextStatus:_,metadata:c,eventType:"checkout.purchaseCompleted"});return{success:!0,orderId:t.id,status:w,metadata:c}}function h(e){return s(e.data?.license_id)??s(e.objects?.license?.id)??s(e.objects?.subscription?.license_id)??s(e.objects?.payment?.license_id)??s(e.data?.payment?.license_id)}function v(e,r){const t=e.objects?.license,i=e.objects?.subscription,n=e.objects?.trial,u=e.objects?.payment??e.data?.payment;return{freemius_product_id:s(r?.productId)??s(r?.product_id)??s(t?.plugin_id)??s(i?.plugin_id)??s(u?.plugin_id),freemius_plan_id:s(r?.planId)??s(r?.plan_id)??s(t?.plan_id),freemius_license_id:s(r?.licenseId)??s(r?.license_id)??h(e),freemius_subscription_id:s(r?.subscriptionId)??s(r?.subscription_id)??s(i?.id)??s(e.data?.subscription_id),freemius_trial_id:s(n?.id)??s(e.data?.trial_id),freemius_user_id:s(r?.userId)??s(r?.user_id)??s(e.objects?.user?.id),freemius_trial_ends_at:a(n?.trial_ends_at)??a(n?.trial_ends)??a(t?.trial_ends)??a(r?.trialEndsAt)??a(r?.trial_ends_at)}}async function F(e,r){if(!e)return null;const t=d.resolveFreemiusCheckoutCredentials(e);return!t.apiKey||!t.secretKey||!t.publicKey?null:new C.Freemius({productId:Number(e),apiKey:t.apiKey,secretKey:t.secretKey,publicKey:t.publicKey}).purchase.retrievePurchaseData(r)}async function B(e){const r=e.client??E(),t=h(e.event);if(!t)return{success:!0,ignored:!0,reason:"missing_license_id",type:e.event.type};const i=await P(r,t);if(!i)return{success:!0,ignored:!0,reason:"unknown_license_id",licenseId:t,type:e.event.type};let n=null;try{n=await F(i.freemius_product_id??e.event.objects?.license?.plugin_id,t)}catch(_){console.error("[Freemius Sync] Failed to retrieve purchase data:",_)}const u=v(e.event,n),c=f({event:e.event,currentStatus:i.status,purchaseData:n}),o=await g({client:r,order:i,nextStatus:c,metadata:u,eventType:e.event.type??null});return{success:!0,orderId:i.id,status:o,type:e.event.type}}function I(){const e=[d.readFreemiusEnvValue("FREEMIUS_SECRET_KEY"),d.readFreemiusEnvValue("FREEMIUS_ECOMMERCE_SANDBOX_SECRET_KEY"),...Object.values(d.parseFreemiusCheckoutCredentialsMap()??{}).map(r=>r.secretKey??null)];return Array.from(new Set(e.filter(r=>!!r)))}function U(e,r){return r?I().some(t=>{const i=p.createHmac("sha256",t).update(e).digest("hex");try{return p.timingSafeEqual(Buffer.from(i,"hex"),Buffer.from(r,"hex"))}catch{return!1}}):!1}exports.extractFreemiusCheckoutMetadata=b;exports.getFreemiusWebhookSecretCandidates=I;exports.resolveFreemiusStatusFromCheckoutResponse=S;exports.resolveFreemiusStatusFromWebhookEvent=f;exports.syncFreemiusCheckoutOrder=T;exports.syncFreemiusOrderFromWebhookEvent=B;exports.verifyFreemiusWebhookSignature=U;
|
|
@@ -3,7 +3,7 @@ import { Freemius as v } from "@freemius/sdk";
|
|
|
3
3
|
import { createClient as F } from "@supabase/supabase-js";
|
|
4
4
|
import { assignInvoiceMetadata as C } from "./invoice-server.es.js";
|
|
5
5
|
import { applyOrderInventoryDeduction as k } from "./order-inventory.es.js";
|
|
6
|
-
import { readFreemiusEnvValue as m, parseFreemiusCheckoutCredentialsMap as O, resolveFreemiusCheckoutCredentials as
|
|
6
|
+
import { readFreemiusEnvValue as m, parseFreemiusCheckoutCredentialsMap as O, resolveFreemiusCheckoutCredentials as A } from "./providers/freemius.es.js";
|
|
7
7
|
function s(e) {
|
|
8
8
|
return e == null || e === "" ? null : String(e);
|
|
9
9
|
}
|
|
@@ -14,7 +14,7 @@ function a(e) {
|
|
|
14
14
|
const t = r.includes("T") ? r : r.replace(" ", "T") + "Z", i = new Date(t);
|
|
15
15
|
return Number.isNaN(i.getTime()) ? r : i.toISOString();
|
|
16
16
|
}
|
|
17
|
-
function
|
|
17
|
+
function R(e) {
|
|
18
18
|
if (e == null || e === "")
|
|
19
19
|
return null;
|
|
20
20
|
const r = Number(e);
|
|
@@ -22,7 +22,7 @@ function K(e) {
|
|
|
22
22
|
}
|
|
23
23
|
function _(...e) {
|
|
24
24
|
return e.some((r) => {
|
|
25
|
-
const t =
|
|
25
|
+
const t = R(r);
|
|
26
26
|
return t !== null && t > 0;
|
|
27
27
|
});
|
|
28
28
|
}
|
|
@@ -40,10 +40,10 @@ function p(e) {
|
|
|
40
40
|
"trial.expired"
|
|
41
41
|
].includes(e || "");
|
|
42
42
|
}
|
|
43
|
-
function
|
|
43
|
+
function K(e, r) {
|
|
44
44
|
return e === "license.extended" && (r?.is_renewal === !0 || r?.is_renewal === 1 || r?.is_renewal === "1" || r?.is_renewal === "true");
|
|
45
45
|
}
|
|
46
|
-
function
|
|
46
|
+
function j(e) {
|
|
47
47
|
const r = e.objects?.payment ?? e.data?.payment ?? e.data;
|
|
48
48
|
return e.type === "payment.created" && _(
|
|
49
49
|
r?.gross,
|
|
@@ -52,7 +52,7 @@ function x(e) {
|
|
|
52
52
|
r?.initial_amount
|
|
53
53
|
);
|
|
54
54
|
}
|
|
55
|
-
function
|
|
55
|
+
function x(e) {
|
|
56
56
|
const r = e?.purchase ?? null, t = e?.trial ?? null;
|
|
57
57
|
return {
|
|
58
58
|
freemius_product_id: s(r?.plugin_id) ?? s(r?.product_id) ?? s(r?.productId) ?? s(t?.plugin_id) ?? s(t?.product_id) ?? s(t?.productId),
|
|
@@ -76,7 +76,7 @@ function N(e, r = "pending") {
|
|
|
76
76
|
}
|
|
77
77
|
function y(e) {
|
|
78
78
|
const { event: r, currentStatus: t, purchaseData: i } = e;
|
|
79
|
-
return t === "paid" && p(r.type) ? "paid" : p(r.type) ? d(t) ? "cancelled" : t :
|
|
79
|
+
return t === "paid" && p(r.type) ? "paid" : p(r.type) ? d(t) ? "cancelled" : t : j(r) || K(r.type, r.data) || i && _(
|
|
80
80
|
i.initialAmount,
|
|
81
81
|
i.initial_amount,
|
|
82
82
|
i.gross,
|
|
@@ -84,7 +84,7 @@ function y(e) {
|
|
|
84
84
|
i.total_gross
|
|
85
85
|
) ? "paid" : i?.canceled === !0 && d(t) ? "cancelled" : (i?.subscriptionId || i?.subscription_id || r.type === "subscription.created" || r.type === "license.created") && t === "pending" ? "trial" : t;
|
|
86
86
|
}
|
|
87
|
-
function
|
|
87
|
+
function B(e, r) {
|
|
88
88
|
const t = {
|
|
89
89
|
freemius_last_event_type: r,
|
|
90
90
|
freemius_last_synced_at: (/* @__PURE__ */ new Date()).toISOString()
|
|
@@ -94,7 +94,7 @@ function M(e, r) {
|
|
|
94
94
|
return t;
|
|
95
95
|
}
|
|
96
96
|
function b() {
|
|
97
|
-
const e = process.env.NEXT_PUBLIC_SUPABASE_URL, r = process.env.SUPABASE_SERVICE_ROLE_KEY;
|
|
97
|
+
const e = process.env.NEXT_PUBLIC_SUPABASE_URL || process.env.SUPABASE_URL, r = process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.SUPABASE_SECRET_KEY;
|
|
98
98
|
if (!e || !r)
|
|
99
99
|
throw new Error("Missing Supabase Service Role environment variables");
|
|
100
100
|
return F(e, r, {
|
|
@@ -104,7 +104,7 @@ function b() {
|
|
|
104
104
|
}
|
|
105
105
|
});
|
|
106
106
|
}
|
|
107
|
-
async function
|
|
107
|
+
async function M(e, r) {
|
|
108
108
|
const { data: t, error: i } = await e.from("orders").select(
|
|
109
109
|
"id, status, provider, freemius_product_id, freemius_plan_id, freemius_license_id, freemius_subscription_id, freemius_trial_id, freemius_user_id, freemius_trial_ends_at"
|
|
110
110
|
).eq("id", r).single();
|
|
@@ -112,7 +112,7 @@ async function T(e, r) {
|
|
|
112
112
|
throw new Error(i?.message || "Order not found");
|
|
113
113
|
return t;
|
|
114
114
|
}
|
|
115
|
-
async function
|
|
115
|
+
async function P(e, r) {
|
|
116
116
|
const { data: t, error: i } = await e.from("orders").select(
|
|
117
117
|
"id, status, provider, freemius_product_id, freemius_plan_id, freemius_license_id, freemius_subscription_id, freemius_trial_id, freemius_user_id, freemius_trial_ends_at"
|
|
118
118
|
).eq("freemius_license_id", r).order("created_at", { ascending: !1 }).limit(1).maybeSingle();
|
|
@@ -120,8 +120,8 @@ async function B(e, r) {
|
|
|
120
120
|
throw new Error(i.message);
|
|
121
121
|
return t ?? null;
|
|
122
122
|
}
|
|
123
|
-
async function
|
|
124
|
-
const r =
|
|
123
|
+
async function S(e) {
|
|
124
|
+
const r = B(e.metadata, e.eventType), t = e.order.status, i = t === "paid" && e.nextStatus !== "paid" ? "paid" : e.nextStatus;
|
|
125
125
|
i !== t && (r.status = i);
|
|
126
126
|
const { error: n } = await e.client.from("orders").update(r).eq("id", e.order.id);
|
|
127
127
|
if (n)
|
|
@@ -132,13 +132,13 @@ async function g(e) {
|
|
|
132
132
|
}), await k(e.client, e.order.id)), i;
|
|
133
133
|
}
|
|
134
134
|
async function V(e) {
|
|
135
|
-
const r = e.client ?? b(), t = await
|
|
135
|
+
const r = e.client ?? b(), t = await M(r, e.orderId);
|
|
136
136
|
if (t.provider !== "freemius")
|
|
137
137
|
return {
|
|
138
138
|
success: !1,
|
|
139
139
|
error: "Only Freemius orders can be synced from Freemius checkout"
|
|
140
140
|
};
|
|
141
|
-
const i =
|
|
141
|
+
const i = x(e.checkoutResponse);
|
|
142
142
|
let n = null;
|
|
143
143
|
if (i.freemius_license_id)
|
|
144
144
|
try {
|
|
@@ -155,7 +155,7 @@ async function V(e) {
|
|
|
155
155
|
objects: {}
|
|
156
156
|
}, o = {
|
|
157
157
|
...i,
|
|
158
|
-
...
|
|
158
|
+
...g(c, n)
|
|
159
159
|
}, u = N(
|
|
160
160
|
e.checkoutResponse,
|
|
161
161
|
t.status
|
|
@@ -163,7 +163,7 @@ async function V(e) {
|
|
|
163
163
|
event: c,
|
|
164
164
|
currentStatus: t.status,
|
|
165
165
|
purchaseData: n
|
|
166
|
-
}) : u === "paid" ? t.status : u, I = await
|
|
166
|
+
}) : u === "paid" ? t.status : u, I = await S({
|
|
167
167
|
client: r,
|
|
168
168
|
order: t,
|
|
169
169
|
nextStatus: l,
|
|
@@ -177,15 +177,15 @@ async function V(e) {
|
|
|
177
177
|
metadata: o
|
|
178
178
|
};
|
|
179
179
|
}
|
|
180
|
-
function
|
|
180
|
+
function E(e) {
|
|
181
181
|
return s(e.data?.license_id) ?? s(e.objects?.license?.id) ?? s(e.objects?.subscription?.license_id) ?? s(e.objects?.payment?.license_id) ?? s(e.data?.payment?.license_id);
|
|
182
182
|
}
|
|
183
|
-
function
|
|
183
|
+
function g(e, r) {
|
|
184
184
|
const t = e.objects?.license, i = e.objects?.subscription, n = e.objects?.trial, c = e.objects?.payment ?? e.data?.payment;
|
|
185
185
|
return {
|
|
186
186
|
freemius_product_id: s(r?.productId) ?? s(r?.product_id) ?? s(t?.plugin_id) ?? s(i?.plugin_id) ?? s(c?.plugin_id),
|
|
187
187
|
freemius_plan_id: s(r?.planId) ?? s(r?.plan_id) ?? s(t?.plan_id),
|
|
188
|
-
freemius_license_id: s(r?.licenseId) ?? s(r?.license_id) ??
|
|
188
|
+
freemius_license_id: s(r?.licenseId) ?? s(r?.license_id) ?? E(e),
|
|
189
189
|
freemius_subscription_id: s(r?.subscriptionId) ?? s(r?.subscription_id) ?? s(i?.id) ?? s(e.data?.subscription_id),
|
|
190
190
|
freemius_trial_id: s(n?.id) ?? s(e.data?.trial_id),
|
|
191
191
|
freemius_user_id: s(r?.userId) ?? s(r?.user_id) ?? s(e.objects?.user?.id),
|
|
@@ -195,7 +195,7 @@ function E(e, r) {
|
|
|
195
195
|
async function h(e, r) {
|
|
196
196
|
if (!e)
|
|
197
197
|
return null;
|
|
198
|
-
const t =
|
|
198
|
+
const t = A(e);
|
|
199
199
|
return !t.apiKey || !t.secretKey || !t.publicKey ? null : new v({
|
|
200
200
|
productId: Number(e),
|
|
201
201
|
apiKey: t.apiKey,
|
|
@@ -204,7 +204,7 @@ async function h(e, r) {
|
|
|
204
204
|
}).purchase.retrievePurchaseData(r);
|
|
205
205
|
}
|
|
206
206
|
async function X(e) {
|
|
207
|
-
const r = e.client ?? b(), t =
|
|
207
|
+
const r = e.client ?? b(), t = E(e.event);
|
|
208
208
|
if (!t)
|
|
209
209
|
return {
|
|
210
210
|
success: !0,
|
|
@@ -212,7 +212,7 @@ async function X(e) {
|
|
|
212
212
|
reason: "missing_license_id",
|
|
213
213
|
type: e.event.type
|
|
214
214
|
};
|
|
215
|
-
const i = await
|
|
215
|
+
const i = await P(r, t);
|
|
216
216
|
if (!i)
|
|
217
217
|
return {
|
|
218
218
|
success: !0,
|
|
@@ -230,11 +230,11 @@ async function X(e) {
|
|
|
230
230
|
} catch (l) {
|
|
231
231
|
console.error("[Freemius Sync] Failed to retrieve purchase data:", l);
|
|
232
232
|
}
|
|
233
|
-
const c =
|
|
233
|
+
const c = g(e.event, n), o = y({
|
|
234
234
|
event: e.event,
|
|
235
235
|
currentStatus: i.status,
|
|
236
236
|
purchaseData: n
|
|
237
|
-
}), u = await
|
|
237
|
+
}), u = await S({
|
|
238
238
|
client: r,
|
|
239
239
|
order: i,
|
|
240
240
|
nextStatus: o,
|
|
@@ -248,7 +248,7 @@ async function X(e) {
|
|
|
248
248
|
type: e.event.type
|
|
249
249
|
};
|
|
250
250
|
}
|
|
251
|
-
function
|
|
251
|
+
function T() {
|
|
252
252
|
const e = [
|
|
253
253
|
m("FREEMIUS_SECRET_KEY"),
|
|
254
254
|
m("FREEMIUS_ECOMMERCE_SANDBOX_SECRET_KEY"),
|
|
@@ -261,7 +261,7 @@ function P() {
|
|
|
261
261
|
);
|
|
262
262
|
}
|
|
263
263
|
function z(e, r) {
|
|
264
|
-
return r ?
|
|
264
|
+
return r ? T().some((t) => {
|
|
265
265
|
const i = f.createHmac("sha256", t).update(e).digest("hex");
|
|
266
266
|
try {
|
|
267
267
|
return f.timingSafeEqual(
|
|
@@ -274,8 +274,8 @@ function z(e, r) {
|
|
|
274
274
|
}) : !1;
|
|
275
275
|
}
|
|
276
276
|
export {
|
|
277
|
-
|
|
278
|
-
|
|
277
|
+
x as extractFreemiusCheckoutMetadata,
|
|
278
|
+
T as getFreemiusWebhookSecretCandidates,
|
|
279
279
|
N as resolveFreemiusStatusFromCheckoutResponse,
|
|
280
280
|
y as resolveFreemiusStatusFromWebhookEvent,
|
|
281
281
|
V as syncFreemiusCheckoutOrder,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export type ReportType = 'general_ledger' | 'tax_liability' | 'currency_summary';
|
|
2
|
-
export declare function fetchOrderReportData(startDate: string, endDate: string): Promise<any>;
|
|
2
|
+
export declare function fetchOrderReportData(startDate: string, endDate: string): Promise<any[]>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@nextblock-cms/db/server"),u=require("@supabase/supabase-js"),c=require("../../../order-inventory.cjs.js"),d=require("../../../invoice-server.cjs.js"),l=["pending","trial","paid","shipped","cancelled","refunded"];async function f(){const r=i.createClient(),{data:{user:e},error:t}=await r.auth.getUser();if(t||!e)return{error:"Unauthorized"};const{data:s,error:a}=await r.from("profiles").select("role").eq("id",e.id).single();return a||!s||!["ADMIN","WRITER"].includes(s.role)?{error:"Forbidden"}:{supabase:r,user:e}}function p(){const r=process.env.SUPABASE_SERVICE_ROLE_KEY,e=process.env.NEXT_PUBLIC_SUPABASE_URL;if(!r||!e)throw new Error("Server configuration error");return u.createClient(e,r,{auth:{autoRefreshToken:!1,persistSession:!1}})}async function E(r,e){const t=await f();if("error"in t)return{success:!1,error:t.error};if(!l.includes(e))return{success:!1,error:"Invalid order status"};let s;try{s=p()}catch(n){return{success:!1,error:n instanceof Error?n.message:"Server configuration error"}}const{data:a,error:o}=await s.from("orders").update({status:e}).eq("id",r).select();return o?(console.error("Order status update error:",o),{success:!1,error:o.message}):!a||a.length===0?{success:!1,error:"Order not found or update failed."}:(e==="paid"&&(await d.assignInvoiceMetadata({orderId:r,client:s}),await c.applyOrderInventoryDeduction(s,r)),{success:!0})}exports.updateOrderStatus=E;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("@nextblock-cms/db/server"),u=require("@supabase/supabase-js"),c=require("../../../order-inventory.cjs.js"),d=require("../../../invoice-server.cjs.js"),l=["pending","trial","paid","shipped","cancelled","refunded"];async function f(){const r=i.createClient(),{data:{user:e},error:t}=await r.auth.getUser();if(t||!e)return{error:"Unauthorized"};const{data:s,error:a}=await r.from("profiles").select("role").eq("id",e.id).single();return a||!s||!["ADMIN","WRITER"].includes(s.role)?{error:"Forbidden"}:{supabase:r,user:e}}function p(){const r=process.env.SUPABASE_SERVICE_ROLE_KEY||process.env.SUPABASE_SECRET_KEY,e=process.env.NEXT_PUBLIC_SUPABASE_URL||process.env.SUPABASE_URL;if(!r||!e)throw new Error("Server configuration error");return u.createClient(e,r,{auth:{autoRefreshToken:!1,persistSession:!1}})}async function E(r,e){const t=await f();if("error"in t)return{success:!1,error:t.error};if(!l.includes(e))return{success:!1,error:"Invalid order status"};let s;try{s=p()}catch(n){return{success:!1,error:n instanceof Error?n.message:"Server configuration error"}}const{data:a,error:o}=await s.from("orders").update({status:e}).eq("id",r).select();return o?(console.error("Order status update error:",o),{success:!1,error:o.message}):!a||a.length===0?{success:!1,error:"Order not found or update failed."}:(e==="paid"&&(await d.assignInvoiceMetadata({orderId:r,client:s}),await c.applyOrderInventoryDeduction(s,r)),{success:!0})}exports.updateOrderStatus=E;
|
|
@@ -12,14 +12,14 @@ const f = [
|
|
|
12
12
|
"refunded"
|
|
13
13
|
];
|
|
14
14
|
async function l() {
|
|
15
|
-
const r = i(), { data: { user: e }, error:
|
|
16
|
-
if (
|
|
15
|
+
const r = i(), { data: { user: e }, error: t } = await r.auth.getUser();
|
|
16
|
+
if (t || !e)
|
|
17
17
|
return { error: "Unauthorized" };
|
|
18
|
-
const { data:
|
|
19
|
-
return
|
|
18
|
+
const { data: s, error: a } = await r.from("profiles").select("role").eq("id", e.id).single();
|
|
19
|
+
return a || !s || !["ADMIN", "WRITER"].includes(s.role) ? { error: "Forbidden" } : { supabase: r, user: e };
|
|
20
20
|
}
|
|
21
21
|
function p() {
|
|
22
|
-
const r = process.env.SUPABASE_SERVICE_ROLE_KEY, e = process.env.NEXT_PUBLIC_SUPABASE_URL;
|
|
22
|
+
const r = process.env.SUPABASE_SERVICE_ROLE_KEY || process.env.SUPABASE_SECRET_KEY, e = process.env.NEXT_PUBLIC_SUPABASE_URL || process.env.SUPABASE_URL;
|
|
23
23
|
if (!r || !e)
|
|
24
24
|
throw new Error("Server configuration error");
|
|
25
25
|
return c(e, r, {
|
|
@@ -29,27 +29,27 @@ function p() {
|
|
|
29
29
|
}
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
|
-
async function
|
|
33
|
-
const
|
|
34
|
-
if ("error" in
|
|
35
|
-
return { success: !1, error:
|
|
32
|
+
async function R(r, e) {
|
|
33
|
+
const t = await l();
|
|
34
|
+
if ("error" in t)
|
|
35
|
+
return { success: !1, error: t.error };
|
|
36
36
|
if (!f.includes(e))
|
|
37
37
|
return { success: !1, error: "Invalid order status" };
|
|
38
|
-
let
|
|
38
|
+
let s;
|
|
39
39
|
try {
|
|
40
|
-
|
|
40
|
+
s = p();
|
|
41
41
|
} catch (n) {
|
|
42
42
|
return {
|
|
43
43
|
success: !1,
|
|
44
44
|
error: n instanceof Error ? n.message : "Server configuration error"
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
|
-
const { data:
|
|
48
|
-
return o ? (console.error("Order status update error:", o), { success: !1, error: o.message }) : !
|
|
47
|
+
const { data: a, error: o } = await s.from("orders").update({ status: e }).eq("id", r).select();
|
|
48
|
+
return o ? (console.error("Order status update error:", o), { success: !1, error: o.message }) : !a || a.length === 0 ? { success: !1, error: "Order not found or update failed." } : (e === "paid" && (await d({
|
|
49
49
|
orderId: r,
|
|
50
|
-
client:
|
|
51
|
-
}), await u(
|
|
50
|
+
client: s
|
|
51
|
+
}), await u(s, r)), { success: !0 });
|
|
52
52
|
}
|
|
53
53
|
export {
|
|
54
|
-
|
|
54
|
+
R as updateOrderStatus
|
|
55
55
|
};
|