medusa-storefront-core 1.2.2 → 1.2.3
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/edge.d.ts +2 -0
- package/dist/error-boundary.d.ts +15 -0
- package/dist/errors.d.ts +2 -0
- package/dist/index.d.ts +6 -0
- package/dist/provider.d.ts +21 -0
- package/dist/site-config.d.ts +63 -0
- package/dist/types.d.ts +12 -0
- package/dist/ui-library.js +144 -0
- package/dist/ui-library.umd.cjs +1 -0
- package/dist/use-storefront-action.d.ts +9 -0
- package/package.json +1 -1
package/dist/edge.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { default as React, Component, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
type Props = {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
fallback?: ReactNode | ((error: Error) => ReactNode);
|
|
6
|
+
};
|
|
7
|
+
type State = {
|
|
8
|
+
error: Error | null;
|
|
9
|
+
};
|
|
10
|
+
export declare class StorefrontErrorBoundary extends Component<Props, State> {
|
|
11
|
+
state: State;
|
|
12
|
+
static getDerivedStateFromError(error: Error): State;
|
|
13
|
+
render(): string | number | bigint | boolean | Iterable<React.ReactNode> | Promise<React.AwaitedReactNode> | import("react/jsx-runtime").JSX.Element | null | undefined;
|
|
14
|
+
}
|
|
15
|
+
export {};
|
package/dist/errors.d.ts
ADDED
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { StorefrontCompanyConfig } from './site-config';
|
|
3
|
+
|
|
4
|
+
export type MedusaSiteContextValue = {
|
|
5
|
+
countryCode?: string;
|
|
6
|
+
regionId?: string;
|
|
7
|
+
publishableKey?: string;
|
|
8
|
+
backendUrl?: string;
|
|
9
|
+
company?: StorefrontCompanyConfig;
|
|
10
|
+
};
|
|
11
|
+
export type MedusaSiteProviderProps = {
|
|
12
|
+
children: React.ReactNode;
|
|
13
|
+
value?: MedusaSiteContextValue;
|
|
14
|
+
countryCode?: string;
|
|
15
|
+
regionId?: string;
|
|
16
|
+
company?: StorefrontCompanyConfig;
|
|
17
|
+
};
|
|
18
|
+
export declare function MedusaSiteProvider({ children, value, countryCode, regionId, company, }: MedusaSiteProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
19
|
+
export declare function useMedusaSite(): MedusaSiteContextValue;
|
|
20
|
+
/** Shorthand for company details from site config. */
|
|
21
|
+
export declare function useSiteCompany(): StorefrontCompanyConfig;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Metadata } from 'next';
|
|
2
|
+
|
|
3
|
+
/** Footer / share social icon link */
|
|
4
|
+
export type StorefrontSocialLink = {
|
|
5
|
+
name: string;
|
|
6
|
+
url: string;
|
|
7
|
+
icon?: string;
|
|
8
|
+
};
|
|
9
|
+
/** Company / brand details passed from each storefront — never hardcode in libraries. */
|
|
10
|
+
export type StorefrontCompanyConfig = {
|
|
11
|
+
name: string;
|
|
12
|
+
brandName?: string;
|
|
13
|
+
customerLabel?: string;
|
|
14
|
+
contactEmail?: string;
|
|
15
|
+
phone?: string;
|
|
16
|
+
description?: string;
|
|
17
|
+
helpTagline?: string;
|
|
18
|
+
mapTitle?: string;
|
|
19
|
+
whyChooseUsTitle?: string;
|
|
20
|
+
termsSubtitle?: string;
|
|
21
|
+
privacySubtitle?: string;
|
|
22
|
+
/**
|
|
23
|
+
* Fallback footer social links when Medusa admin has no `social-links` config.
|
|
24
|
+
* Overrides library defaults; set in each storefront's `site.config.ts`.
|
|
25
|
+
*/
|
|
26
|
+
defaultSocialLinks?: StorefrontSocialLink[];
|
|
27
|
+
};
|
|
28
|
+
/** Site-specific values passed from each storefront project. */
|
|
29
|
+
export type StorefrontSiteConfig = {
|
|
30
|
+
siteName: string;
|
|
31
|
+
siteUrl: string;
|
|
32
|
+
company?: StorefrontCompanyConfig;
|
|
33
|
+
gtmId?: string;
|
|
34
|
+
locale?: string;
|
|
35
|
+
htmlLang?: string;
|
|
36
|
+
icons?: {
|
|
37
|
+
icon?: string;
|
|
38
|
+
apple?: string;
|
|
39
|
+
};
|
|
40
|
+
seo: {
|
|
41
|
+
titleTemplate: string;
|
|
42
|
+
defaultTitle: string;
|
|
43
|
+
description: string;
|
|
44
|
+
openGraph?: {
|
|
45
|
+
title?: string;
|
|
46
|
+
description?: string;
|
|
47
|
+
image?: string;
|
|
48
|
+
imageAlt?: string;
|
|
49
|
+
locale?: string;
|
|
50
|
+
};
|
|
51
|
+
twitter?: {
|
|
52
|
+
title?: string;
|
|
53
|
+
description?: string;
|
|
54
|
+
image?: string;
|
|
55
|
+
};
|
|
56
|
+
};
|
|
57
|
+
features?: {
|
|
58
|
+
cookieConsent?: boolean;
|
|
59
|
+
metaPixelGuard?: boolean;
|
|
60
|
+
gtm?: boolean;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
export declare function buildSiteMetadata(config: StorefrontSiteConfig, metadataBase: URL): Metadata;
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export type StorefrontErrorCode = "UNKNOWN" | "NETWORK" | "UNAUTHORIZED" | "NOT_FOUND" | "VALIDATION" | "CONFIG";
|
|
2
|
+
export type StorefrontResult<T> = {
|
|
3
|
+
ok: true;
|
|
4
|
+
data: T;
|
|
5
|
+
} | {
|
|
6
|
+
ok: false;
|
|
7
|
+
code: StorefrontErrorCode;
|
|
8
|
+
message: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function ok<T>(data: T): StorefrontResult<T>;
|
|
11
|
+
export declare function err<T = never>(message: string, code?: StorefrontErrorCode): StorefrontResult<T>;
|
|
12
|
+
export declare function fromCaught(error: unknown, fallback?: string): StorefrontResult<never>;
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
var g = Object.defineProperty;
|
|
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 l = (e, t, r) => h(e, typeof t != "symbol" ? t + "" : t, r);
|
|
4
|
+
import { parseStoreErrorMessage as y } from "medusa-services";
|
|
5
|
+
import { jsx as f } from "react/jsx-runtime";
|
|
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
|
+
function L(e) {
|
|
8
|
+
return { ok: !0, data: e };
|
|
9
|
+
}
|
|
10
|
+
function k(e, t = "UNKNOWN") {
|
|
11
|
+
return { ok: !1, code: t, message: e };
|
|
12
|
+
}
|
|
13
|
+
function M(e, t = "Something went wrong") {
|
|
14
|
+
const r = e instanceof Error ? e.message : t;
|
|
15
|
+
return k(r);
|
|
16
|
+
}
|
|
17
|
+
async function P(e) {
|
|
18
|
+
return y(e);
|
|
19
|
+
}
|
|
20
|
+
function B(e, t = "Something went wrong") {
|
|
21
|
+
return e instanceof Error ? e.message : typeof e == "string" ? e : t;
|
|
22
|
+
}
|
|
23
|
+
const m = {
|
|
24
|
+
name: "Store",
|
|
25
|
+
brandName: "Store",
|
|
26
|
+
customerLabel: "Customer"
|
|
27
|
+
}, d = C({
|
|
28
|
+
company: m
|
|
29
|
+
});
|
|
30
|
+
function K({
|
|
31
|
+
children: e,
|
|
32
|
+
value: t,
|
|
33
|
+
countryCode: r,
|
|
34
|
+
regionId: s,
|
|
35
|
+
company: i
|
|
36
|
+
}) {
|
|
37
|
+
const a = U(
|
|
38
|
+
() => ({
|
|
39
|
+
countryCode: (t == null ? void 0 : t.countryCode) ?? r,
|
|
40
|
+
regionId: (t == null ? void 0 : t.regionId) ?? s,
|
|
41
|
+
publishableKey: (t == null ? void 0 : t.publishableKey) ?? process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY,
|
|
42
|
+
backendUrl: (t == null ? void 0 : t.backendUrl) ?? process.env.NEXT_PUBLIC_MEDUSA_BACKEND_URL ?? process.env.MEDUSA_BACKEND_URL,
|
|
43
|
+
company: (t == null ? void 0 : t.company) ?? i ?? m
|
|
44
|
+
}),
|
|
45
|
+
[t, r, s, i]
|
|
46
|
+
);
|
|
47
|
+
return /* @__PURE__ */ f(d.Provider, { value: a, children: e });
|
|
48
|
+
}
|
|
49
|
+
function I() {
|
|
50
|
+
return S(d);
|
|
51
|
+
}
|
|
52
|
+
function j() {
|
|
53
|
+
return S(d).company ?? m;
|
|
54
|
+
}
|
|
55
|
+
function F(e) {
|
|
56
|
+
const [t, r] = _(), [s, i] = p(null), [a, u] = p(null);
|
|
57
|
+
return { run: b(
|
|
58
|
+
(...E) => (i(null), new Promise((c) => {
|
|
59
|
+
r(() => {
|
|
60
|
+
(async () => {
|
|
61
|
+
try {
|
|
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
|
+
} else
|
|
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
|
+
}
|
|
72
|
+
})();
|
|
73
|
+
});
|
|
74
|
+
})),
|
|
75
|
+
[e]
|
|
76
|
+
), isPending: t, error: s, data: a, clearError: () => i(null) };
|
|
77
|
+
}
|
|
78
|
+
function G(e, t) {
|
|
79
|
+
const r = e.seo.openGraph ?? {}, s = e.seo.twitter ?? {};
|
|
80
|
+
return {
|
|
81
|
+
metadataBase: t,
|
|
82
|
+
title: {
|
|
83
|
+
template: e.seo.titleTemplate,
|
|
84
|
+
default: e.seo.defaultTitle
|
|
85
|
+
},
|
|
86
|
+
description: e.seo.description,
|
|
87
|
+
openGraph: {
|
|
88
|
+
title: r.title ?? e.seo.defaultTitle,
|
|
89
|
+
description: r.description ?? e.seo.description,
|
|
90
|
+
url: e.siteUrl,
|
|
91
|
+
siteName: e.siteName,
|
|
92
|
+
images: r.image ? [
|
|
93
|
+
{
|
|
94
|
+
url: r.image,
|
|
95
|
+
width: 1200,
|
|
96
|
+
height: 630,
|
|
97
|
+
alt: r.imageAlt ?? e.siteName
|
|
98
|
+
}
|
|
99
|
+
] : void 0,
|
|
100
|
+
locale: r.locale ?? e.locale ?? "en_US",
|
|
101
|
+
type: "website"
|
|
102
|
+
},
|
|
103
|
+
twitter: {
|
|
104
|
+
card: "summary_large_image",
|
|
105
|
+
title: s.title ?? e.seo.defaultTitle,
|
|
106
|
+
description: s.description ?? e.seo.description,
|
|
107
|
+
images: s.image ? [s.image] : r.image ? [r.image] : void 0
|
|
108
|
+
},
|
|
109
|
+
icons: e.icons,
|
|
110
|
+
alternates: {
|
|
111
|
+
canonical: e.siteUrl
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
class O extends N {
|
|
116
|
+
constructor() {
|
|
117
|
+
super(...arguments);
|
|
118
|
+
l(this, "state", { error: null });
|
|
119
|
+
}
|
|
120
|
+
static getDerivedStateFromError(r) {
|
|
121
|
+
return { error: r };
|
|
122
|
+
}
|
|
123
|
+
render() {
|
|
124
|
+
const { error: r } = this.state;
|
|
125
|
+
if (r) {
|
|
126
|
+
const { fallback: s } = this.props;
|
|
127
|
+
return typeof s == "function" ? s(r) : s || /* @__PURE__ */ f("div", { role: "alert", className: "p-4 text-sm text-red-700", children: r.message });
|
|
128
|
+
}
|
|
129
|
+
return this.props.children;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
export {
|
|
133
|
+
K as MedusaSiteProvider,
|
|
134
|
+
O as StorefrontErrorBoundary,
|
|
135
|
+
G as buildSiteMetadata,
|
|
136
|
+
k as err,
|
|
137
|
+
M as fromCaught,
|
|
138
|
+
B as getErrorMessage,
|
|
139
|
+
L as ok,
|
|
140
|
+
P as parseMedusaStoreError,
|
|
141
|
+
I as useMedusaSite,
|
|
142
|
+
j as useSiteCompany,
|
|
143
|
+
F as useStorefrontAction
|
|
144
|
+
};
|
|
@@ -0,0 +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 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"})});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { StorefrontResult } from './types';
|
|
2
|
+
|
|
3
|
+
export declare function useStorefrontAction<TArgs extends unknown[], TData>(action: (...args: TArgs) => Promise<StorefrontResult<TData> | TData>): {
|
|
4
|
+
run: (...args: TArgs) => Promise<StorefrontResult<TData>>;
|
|
5
|
+
isPending: boolean;
|
|
6
|
+
error: string | null;
|
|
7
|
+
data: TData | null;
|
|
8
|
+
clearError: () => void;
|
|
9
|
+
};
|