medusa-storefront-core 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ui-library.js +17 -17
- package/dist/ui-library.umd.cjs +1 -1
- package/package.json +3 -2
package/dist/ui-library.js
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
var g = Object.defineProperty;
|
|
2
2
|
var h = (e, t, r) => t in e ? g(e, t, { enumerable: !0, configurable: !0, writable: !0, value: r }) : e[t] = r;
|
|
3
|
-
var
|
|
3
|
+
var l = (e, t, r) => h(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
4
|
import { parseStoreErrorMessage as y } from "medusa-services";
|
|
5
5
|
import { jsx as f } from "react/jsx-runtime";
|
|
6
|
-
import { useMemo as U, useContext as S, createContext as C, useTransition as _, useState as
|
|
6
|
+
import { useMemo as U, useContext as S, createContext as C, useTransition as _, useState as p, useCallback as b, Component as N } from "react";
|
|
7
7
|
function L(e) {
|
|
8
8
|
return { ok: !0, data: e };
|
|
9
9
|
}
|
|
10
|
-
function
|
|
10
|
+
function k(e, t = "UNKNOWN") {
|
|
11
11
|
return { ok: !1, code: t, message: e };
|
|
12
12
|
}
|
|
13
|
-
function
|
|
13
|
+
function M(e, t = "Something went wrong") {
|
|
14
14
|
const r = e instanceof Error ? e.message : t;
|
|
15
|
-
return
|
|
15
|
+
return k(r);
|
|
16
16
|
}
|
|
17
17
|
async function P(e) {
|
|
18
18
|
return y(e);
|
|
@@ -53,21 +53,21 @@ function j() {
|
|
|
53
53
|
return S(d).company ?? m;
|
|
54
54
|
}
|
|
55
55
|
function F(e) {
|
|
56
|
-
const [t, r] = _(), [s, i] =
|
|
56
|
+
const [t, r] = _(), [s, i] = p(null), [a, u] = p(null);
|
|
57
57
|
return { run: b(
|
|
58
58
|
(...E) => (i(null), new Promise((c) => {
|
|
59
59
|
r(() => {
|
|
60
60
|
(async () => {
|
|
61
61
|
try {
|
|
62
|
-
const
|
|
63
|
-
if (
|
|
64
|
-
const
|
|
65
|
-
|
|
62
|
+
const o = await e(...E);
|
|
63
|
+
if (o && typeof o == "object" && "ok" in o) {
|
|
64
|
+
const n = o;
|
|
65
|
+
n.ok === !0 ? u(n.data) : n.ok === !1 && i(n.message), c(n);
|
|
66
66
|
} else
|
|
67
|
-
u(
|
|
68
|
-
} catch (
|
|
69
|
-
const
|
|
70
|
-
|
|
67
|
+
u(o), c({ ok: !0, data: o });
|
|
68
|
+
} catch (o) {
|
|
69
|
+
const n = M(o);
|
|
70
|
+
n.ok === !1 && i(n.message), c(n);
|
|
71
71
|
}
|
|
72
72
|
})();
|
|
73
73
|
});
|
|
@@ -115,7 +115,7 @@ function G(e, t) {
|
|
|
115
115
|
class O extends N {
|
|
116
116
|
constructor() {
|
|
117
117
|
super(...arguments);
|
|
118
|
-
|
|
118
|
+
l(this, "state", { error: null });
|
|
119
119
|
}
|
|
120
120
|
static getDerivedStateFromError(r) {
|
|
121
121
|
return { error: r };
|
|
@@ -133,8 +133,8 @@ export {
|
|
|
133
133
|
K as MedusaSiteProvider,
|
|
134
134
|
O as StorefrontErrorBoundary,
|
|
135
135
|
G as buildSiteMetadata,
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
k as err,
|
|
137
|
+
M as fromCaught,
|
|
138
138
|
B as getErrorMessage,
|
|
139
139
|
L as ok,
|
|
140
140
|
P as parseMedusaStoreError,
|
package/dist/ui-library.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(r,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("medusa-services"),require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","medusa-services","react/jsx-runtime","react"],o):(r=typeof globalThis<"u"?globalThis:r||self,o(r.MedusaStorefrontCore={},r.MedusaServices,r.jsxRuntime,r.React))})(this,function(r,o,d,i){"use strict";var A=Object.defineProperty;var P=(r,o,d)=>o in r?A(r,o,{enumerable:!0,configurable:!0,writable:!0,value:d}):r[o]=d;var g=(r,o,d)=>P(r,typeof o!="symbol"?o+"":o,d);function h(e){return{ok:!0,data:e}}function S(e,t="UNKNOWN"){return{ok:!1,code:t,message:e}}function y(e,t="Something went wrong"){const
|
|
1
|
+
(function(r,o){typeof exports=="object"&&typeof module<"u"?o(exports,require("medusa-services"),require("react/jsx-runtime"),require("react")):typeof define=="function"&&define.amd?define(["exports","medusa-services","react/jsx-runtime","react"],o):(r=typeof globalThis<"u"?globalThis:r||self,o(r.MedusaStorefrontCore={},r.MedusaServices,r.jsxRuntime,r.React))})(this,function(r,o,d,i){"use strict";var A=Object.defineProperty;var P=(r,o,d)=>o in r?A(r,o,{enumerable:!0,configurable:!0,writable:!0,value:d}):r[o]=d;var g=(r,o,d)=>P(r,typeof o!="symbol"?o+"":o,d);function h(e){return{ok:!0,data:e}}function S(e,t="UNKNOWN"){return{ok:!1,code:t,message:e}}function y(e,t="Something went wrong"){const s=e instanceof Error?e.message:t;return S(s)}async function M(e){return o.parseStoreErrorMessage(e)}function C(e,t="Something went wrong"){return e instanceof Error?e.message:typeof e=="string"?e:t}const m={name:"Store",brandName:"Store",customerLabel:"Customer"},l=i.createContext({company:m});function U({children:e,value:t,countryCode:s,regionId:n,company:c}){const f=i.useMemo(()=>({countryCode:(t==null?void 0:t.countryCode)??s,regionId:(t==null?void 0:t.regionId)??n,publishableKey:(t==null?void 0:t.publishableKey)??process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,backendUrl:(t==null?void 0:t.backendUrl)??process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL??process.env.MEDUSA_BACKEND_URL,company:(t==null?void 0:t.company)??c??m}),[t,s,n,c]);return d.jsx(l.Provider,{value:f,children:e})}function b(){return i.useContext(l)}function _(){return i.useContext(l).company??m}function k(e){const[t,s]=i.useTransition(),[n,c]=i.useState(null),[f,E]=i.useState(null);return{run:i.useCallback((...w)=>(c(null),new Promise(p=>{s(()=>{(async()=>{try{const u=await e(...w);if(u&&typeof u=="object"&&"ok"in u){const a=u;a.ok===!0?E(a.data):a.ok===!1&&c(a.message),p(a)}else E(u),p({ok:!0,data:u})}catch(u){const a=y(u);a.ok===!1&&c(a.message),p(a)}})()})})),[e]),isPending:t,error:n,data:f,clearError:()=>c(null)}}function N(e,t){const s=e.seo.openGraph??{},n=e.seo.twitter??{};return{metadataBase:t,title:{template:e.seo.titleTemplate,default:e.seo.defaultTitle},description:e.seo.description,openGraph:{title:s.title??e.seo.defaultTitle,description:s.description??e.seo.description,url:e.siteUrl,siteName:e.siteName,images:s.image?[{url:s.image,width:1200,height:630,alt:s.imageAlt??e.siteName}]:void 0,locale:s.locale??e.locale??"en_US",type:"website"},twitter:{card:"summary_large_image",title:n.title??e.seo.defaultTitle,description:n.description??e.seo.description,images:n.image?[n.image]:s.image?[s.image]:void 0},icons:e.icons,alternates:{canonical:e.siteUrl}}}class T extends i.Component{constructor(){super(...arguments);g(this,"state",{error:null})}static getDerivedStateFromError(s){return{error:s}}render(){const{error:s}=this.state;if(s){const{fallback:n}=this.props;return typeof n=="function"?n(s):n||d.jsx("div",{role:"alert",className:"p-4 text-sm text-red-700",children:s.message})}return this.props.children}}r.MedusaSiteProvider=U,r.StorefrontErrorBoundary=T,r.buildSiteMetadata=N,r.err=S,r.fromCaught=y,r.getErrorMessage=C,r.ok=h,r.parseMedusaStoreError=M,r.useMedusaSite=b,r.useSiteCompany=_,r.useStorefrontAction=k,Object.defineProperty(r,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "medusa-storefront-core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Core types, providers, and error handling for Medusa storefronts.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
"react": "^18.0.0 || ^19.0.0",
|
|
40
40
|
"react-dom": "^18.0.0 || ^19.0.0",
|
|
41
41
|
"next": ">=14.0.0",
|
|
42
|
-
"medusa-services": "^1.
|
|
42
|
+
"medusa-services": "^1.0.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependenciesMeta": {
|
|
45
45
|
"next": {
|
|
@@ -47,6 +47,7 @@
|
|
|
47
47
|
}
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
+
"next": "^15.0.0",
|
|
50
51
|
"@types/react": "^19.0.0",
|
|
51
52
|
"@types/react-dom": "^19.0.0",
|
|
52
53
|
"@vitejs/plugin-react": "^4.0.0",
|