@ecomweb/storefront-kit 0.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/LICENSE +21 -0
- package/README.md +55 -0
- package/dist/api/client.js +162 -0
- package/dist/api/client.js.map +1 -0
- package/dist/api/index.js +7 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/proxy.js +145 -0
- package/dist/api/proxy.js.map +1 -0
- package/dist/api/response.js +55 -0
- package/dist/api/response.js.map +1 -0
- package/dist/api/server-client.js +159 -0
- package/dist/api/server-client.js.map +1 -0
- package/dist/auth/client-ip.js +44 -0
- package/dist/auth/client-ip.js.map +1 -0
- package/dist/auth/context.js +125 -0
- package/dist/auth/context.js.map +1 -0
- package/dist/auth/cookies.js +97 -0
- package/dist/auth/cookies.js.map +1 -0
- package/dist/auth/error-copy.js +49 -0
- package/dist/auth/error-copy.js.map +1 -0
- package/dist/auth/password-policy.js +29 -0
- package/dist/auth/password-policy.js.map +1 -0
- package/dist/auth/route-handlers.js +337 -0
- package/dist/auth/route-handlers.js.map +1 -0
- package/dist/auth/safe-redirect.js +20 -0
- package/dist/auth/safe-redirect.js.map +1 -0
- package/dist/auth/sdk.js +76 -0
- package/dist/auth/sdk.js.map +1 -0
- package/dist/auth/session-refresh.js +81 -0
- package/dist/auth/session-refresh.js.map +1 -0
- package/dist/auth/session.js +26 -0
- package/dist/auth/session.js.map +1 -0
- package/dist/auth/use-public-auth-config.js +29 -0
- package/dist/auth/use-public-auth-config.js.map +1 -0
- package/dist/cart/api.js +60 -0
- package/dist/cart/api.js.map +1 -0
- package/dist/cart/server-context.js +279 -0
- package/dist/cart/server-context.js.map +1 -0
- package/dist/cart/types.js +1 -0
- package/dist/cart/types.js.map +1 -0
- package/dist/cart/utils.js +49 -0
- package/dist/cart/utils.js.map +1 -0
- package/dist/checkout/get-payment-state.js +15 -0
- package/dist/checkout/get-payment-state.js.map +1 -0
- package/dist/checkout/initiate-gateway-payment.js +13 -0
- package/dist/checkout/initiate-gateway-payment.js.map +1 -0
- package/dist/checkout/order-handoff.js +61 -0
- package/dist/checkout/order-handoff.js.map +1 -0
- package/dist/checkout/payment-redirect.js +11 -0
- package/dist/checkout/payment-redirect.js.map +1 -0
- package/dist/checkout/payment-state-poll.js +45 -0
- package/dist/checkout/payment-state-poll.js.map +1 -0
- package/dist/checkout/start-gateway-redirect.js +16 -0
- package/dist/checkout/start-gateway-redirect.js.map +1 -0
- package/dist/checkout/stock-issues.js +35 -0
- package/dist/checkout/stock-issues.js.map +1 -0
- package/dist/checkout/success-state.js +15 -0
- package/dist/checkout/success-state.js.map +1 -0
- package/dist/checkout/types.js +1 -0
- package/dist/checkout/types.js.map +1 -0
- package/dist/checkout/use-checkout.js +256 -0
- package/dist/checkout/use-checkout.js.map +1 -0
- package/dist/checkout/utils.js +7 -0
- package/dist/checkout/utils.js.map +1 -0
- package/dist/config/index.js +7 -0
- package/dist/config/index.js.map +1 -0
- package/dist/config/log-level.js +8 -0
- package/dist/config/log-level.js.map +1 -0
- package/dist/config/mode.js +18 -0
- package/dist/config/mode.js.map +1 -0
- package/dist/config/public.js +115 -0
- package/dist/config/public.js.map +1 -0
- package/dist/config/schema.js +70 -0
- package/dist/config/schema.js.map +1 -0
- package/dist/config/server.js +68 -0
- package/dist/config/server.js.map +1 -0
- package/dist/config.d.ts +16 -0
- package/dist/config.js +15 -0
- package/dist/config.js.map +1 -0
- package/dist/currency.js +68 -0
- package/dist/currency.js.map +1 -0
- package/dist/index.d.ts +968 -0
- package/dist/index.js +146 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/api.types.js +1 -0
- package/dist/interfaces/api.types.js.map +1 -0
- package/dist/interfaces/index.js +2 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/logging.js +42 -0
- package/dist/logging.js.map +1 -0
- package/dist/middleware/create-storefront-middleware.js +175 -0
- package/dist/middleware/create-storefront-middleware.js.map +1 -0
- package/dist/middleware.d.ts +24 -0
- package/dist/middleware.js +9 -0
- package/dist/middleware.js.map +1 -0
- package/dist/mode-1ZKDELPZ.d.ts +16 -0
- package/dist/notices.js +31 -0
- package/dist/notices.js.map +1 -0
- package/dist/orders/api-client.js +32 -0
- package/dist/orders/api-client.js.map +1 -0
- package/dist/orders/derive-progress.js +36 -0
- package/dist/orders/derive-progress.js.map +1 -0
- package/dist/orders/index.js +6 -0
- package/dist/orders/index.js.map +1 -0
- package/dist/orders/types.js +13 -0
- package/dist/orders/types.js.map +1 -0
- package/dist/orders/use-order-status.js +137 -0
- package/dist/orders/use-order-status.js.map +1 -0
- package/dist/promotions/use-promotion-validation.js +106 -0
- package/dist/promotions/use-promotion-validation.js.map +1 -0
- package/dist/promotions/utils.js +40 -0
- package/dist/promotions/utils.js.map +1 -0
- package/dist/provider.js +25 -0
- package/dist/provider.js.map +1 -0
- package/dist/redirects/index.js +2 -0
- package/dist/redirects/index.js.map +1 -0
- package/dist/redirects/lookup-redirect.js +13 -0
- package/dist/redirects/lookup-redirect.js.map +1 -0
- package/dist/request/public-url.js +20 -0
- package/dist/request/public-url.js.map +1 -0
- package/dist/schema-CEMKsCwh.d.ts +52 -0
- package/dist/sdk.js +33 -0
- package/dist/sdk.js.map +1 -0
- package/dist/server/routes.js +56 -0
- package/dist/server/routes.js.map +1 -0
- package/dist/server.d.ts +58 -0
- package/dist/server.js +19 -0
- package/dist/server.js.map +1 -0
- package/dist/shipping/format-shipping-option.js +12 -0
- package/dist/shipping/format-shipping-option.js.map +1 -0
- package/dist/shipping/location-areas.js +104 -0
- package/dist/shipping/location-areas.js.map +1 -0
- package/dist/shipping/messages.js +19 -0
- package/dist/shipping/messages.js.map +1 -0
- package/dist/shipping/shipping-calculation-reducer.js +75 -0
- package/dist/shipping/shipping-calculation-reducer.js.map +1 -0
- package/dist/shipping/use-shipping-calculation.js +84 -0
- package/dist/shipping/use-shipping-calculation.js.map +1 -0
- package/dist/shipping/utils.js +18 -0
- package/dist/shipping/utils.js.map +1 -0
- package/dist/storage.js +116 -0
- package/dist/storage.js.map +1 -0
- package/dist/store/store-context.js +72 -0
- package/dist/store/store-context.js.map +1 -0
- package/dist/store-scope/index.js +33 -0
- package/dist/store-scope/index.js.map +1 -0
- package/dist/store-scope/root.js +15 -0
- package/dist/store-scope/root.js.map +1 -0
- package/dist/store-scope/store-url.js +45 -0
- package/dist/store-scope/store-url.js.map +1 -0
- package/dist/stores/basic-settings.js +67 -0
- package/dist/stores/basic-settings.js.map +1 -0
- package/dist/stores/cached.js +20 -0
- package/dist/stores/cached.js.map +1 -0
- package/dist/stores/get-store-by-host.js +38 -0
- package/dist/stores/get-store-by-host.js.map +1 -0
- package/dist/stores/index.js +7 -0
- package/dist/stores/index.js.map +1 -0
- package/dist/stores/metadata.js +19 -0
- package/dist/stores/metadata.js.map +1 -0
- package/dist/stores/store-path.js +9 -0
- package/dist/stores/store-path.js.map +1 -0
- package/dist/stores/store-suspension.js +14 -0
- package/dist/stores/store-suspension.js.map +1 -0
- package/package.json +64 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
import { StorefrontKitProvider } from "./provider.js";
|
|
2
|
+
import { useNotify } from "./notices.js";
|
|
3
|
+
import { useCheckout } from "./checkout/use-checkout.js";
|
|
4
|
+
import { useOrderLookup, useOrderStatus } from "./orders/use-order-status.js";
|
|
5
|
+
import {
|
|
6
|
+
useOptionalStoreId,
|
|
7
|
+
useStore,
|
|
8
|
+
useStoreCurrency,
|
|
9
|
+
useStoreData,
|
|
10
|
+
useStoreId,
|
|
11
|
+
useStoreLocale
|
|
12
|
+
} from "./store/store-context.js";
|
|
13
|
+
import { usePublicAuthConfig } from "./auth/use-public-auth-config.js";
|
|
14
|
+
import { publicApiClient } from "./api/client.js";
|
|
15
|
+
import { unwrap, unwrapOrNull } from "./api/response.js";
|
|
16
|
+
import { useAuth } from "./auth/context.js";
|
|
17
|
+
import { errorCopy, errorCopyFor } from "./auth/error-copy.js";
|
|
18
|
+
import {
|
|
19
|
+
getPasswordPolicyHints,
|
|
20
|
+
validatePasswordAgainstPolicy
|
|
21
|
+
} from "./auth/password-policy.js";
|
|
22
|
+
import { DEFAULT_REDIRECT, safeRedirectPath } from "./auth/safe-redirect.js";
|
|
23
|
+
import { useCart } from "./cart/server-context.js";
|
|
24
|
+
import { getPaymentState } from "./checkout/get-payment-state.js";
|
|
25
|
+
import { readOrderHandoff } from "./checkout/order-handoff.js";
|
|
26
|
+
import { pollPaymentState } from "./checkout/payment-state-poll.js";
|
|
27
|
+
import { STOCK_ISSUE_TOAST_DESCRIPTION } from "./checkout/stock-issues.js";
|
|
28
|
+
import {
|
|
29
|
+
resolveInitialState,
|
|
30
|
+
shouldPollForConfirmation
|
|
31
|
+
} from "./checkout/success-state.js";
|
|
32
|
+
import {
|
|
33
|
+
formatNumber,
|
|
34
|
+
formatPrice,
|
|
35
|
+
formatPriceRange,
|
|
36
|
+
formatPriceWithoutSymbol,
|
|
37
|
+
getDefaultLocale,
|
|
38
|
+
money
|
|
39
|
+
} from "./currency.js";
|
|
40
|
+
import {
|
|
41
|
+
ORDER_PROGRESS_STEPS,
|
|
42
|
+
deriveOrderProgress
|
|
43
|
+
} from "./orders/derive-progress.js";
|
|
44
|
+
import { STATUS_OPTIONS } from "./orders/types.js";
|
|
45
|
+
import { getPromotionDescription } from "./promotions/utils.js";
|
|
46
|
+
import { createStoreSdk, sdk } from "./sdk.js";
|
|
47
|
+
import { formatShippingAmount } from "./shipping/format-shipping-option.js";
|
|
48
|
+
import {
|
|
49
|
+
loadWards,
|
|
50
|
+
searchTextFor,
|
|
51
|
+
useProvinces,
|
|
52
|
+
useWards
|
|
53
|
+
} from "./shipping/location-areas.js";
|
|
54
|
+
import { SHIPPING_MESSAGES, formatShippingEstimate } from "./shipping/messages.js";
|
|
55
|
+
import {
|
|
56
|
+
findProvinceByCodeOrName,
|
|
57
|
+
findWardByCodeOrName
|
|
58
|
+
} from "./shipping/utils.js";
|
|
59
|
+
import {
|
|
60
|
+
resolveAssetSrc,
|
|
61
|
+
resolveTransformedImageUrl,
|
|
62
|
+
resolveTransformedProductImageUrl,
|
|
63
|
+
resolveTransformedStoreLogoUrl
|
|
64
|
+
} from "./storage.js";
|
|
65
|
+
import { resolveStoreRef, storeApiPath, storePath } from "./store-scope/index.js";
|
|
66
|
+
import { buildStoreUrl } from "./store-scope/store-url.js";
|
|
67
|
+
import { readBasicSettings, resolveLegalHref } from "./stores/basic-settings.js";
|
|
68
|
+
import { getCachedStore } from "./stores/cached.js";
|
|
69
|
+
import {
|
|
70
|
+
SUSPENDED_STORE_METADATA,
|
|
71
|
+
withSuspendedStoreMetadataFallback
|
|
72
|
+
} from "./stores/metadata.js";
|
|
73
|
+
import { refFromPathname } from "./stores/store-path.js";
|
|
74
|
+
import { isStoreSuspendedError } from "./stores/store-suspension.js";
|
|
75
|
+
import { applyConsoleFilter, getLogLevel, shouldLog } from "./logging.js";
|
|
76
|
+
export {
|
|
77
|
+
DEFAULT_REDIRECT,
|
|
78
|
+
ORDER_PROGRESS_STEPS,
|
|
79
|
+
SHIPPING_MESSAGES,
|
|
80
|
+
STATUS_OPTIONS,
|
|
81
|
+
STOCK_ISSUE_TOAST_DESCRIPTION,
|
|
82
|
+
SUSPENDED_STORE_METADATA,
|
|
83
|
+
StorefrontKitProvider,
|
|
84
|
+
applyConsoleFilter,
|
|
85
|
+
buildStoreUrl,
|
|
86
|
+
createStoreSdk,
|
|
87
|
+
deriveOrderProgress,
|
|
88
|
+
errorCopy,
|
|
89
|
+
errorCopyFor,
|
|
90
|
+
findProvinceByCodeOrName,
|
|
91
|
+
findWardByCodeOrName,
|
|
92
|
+
formatNumber,
|
|
93
|
+
formatPrice,
|
|
94
|
+
formatPriceRange,
|
|
95
|
+
formatPriceWithoutSymbol,
|
|
96
|
+
formatShippingAmount,
|
|
97
|
+
formatShippingEstimate,
|
|
98
|
+
getCachedStore,
|
|
99
|
+
getDefaultLocale,
|
|
100
|
+
getLogLevel,
|
|
101
|
+
getPasswordPolicyHints,
|
|
102
|
+
getPaymentState,
|
|
103
|
+
getPromotionDescription,
|
|
104
|
+
isStoreSuspendedError,
|
|
105
|
+
loadWards,
|
|
106
|
+
money,
|
|
107
|
+
pollPaymentState,
|
|
108
|
+
publicApiClient,
|
|
109
|
+
readBasicSettings,
|
|
110
|
+
readOrderHandoff,
|
|
111
|
+
refFromPathname,
|
|
112
|
+
resolveAssetSrc,
|
|
113
|
+
resolveInitialState,
|
|
114
|
+
resolveLegalHref,
|
|
115
|
+
resolveStoreRef,
|
|
116
|
+
resolveTransformedImageUrl,
|
|
117
|
+
resolveTransformedProductImageUrl,
|
|
118
|
+
resolveTransformedStoreLogoUrl,
|
|
119
|
+
safeRedirectPath,
|
|
120
|
+
sdk,
|
|
121
|
+
searchTextFor,
|
|
122
|
+
shouldLog,
|
|
123
|
+
shouldPollForConfirmation,
|
|
124
|
+
storeApiPath,
|
|
125
|
+
storePath,
|
|
126
|
+
unwrap,
|
|
127
|
+
unwrapOrNull,
|
|
128
|
+
useAuth,
|
|
129
|
+
useCart,
|
|
130
|
+
useCheckout,
|
|
131
|
+
useNotify,
|
|
132
|
+
useOptionalStoreId,
|
|
133
|
+
useOrderLookup,
|
|
134
|
+
useOrderStatus,
|
|
135
|
+
useProvinces,
|
|
136
|
+
usePublicAuthConfig,
|
|
137
|
+
useStore,
|
|
138
|
+
useStoreCurrency,
|
|
139
|
+
useStoreData,
|
|
140
|
+
useStoreId,
|
|
141
|
+
useStoreLocale,
|
|
142
|
+
useWards,
|
|
143
|
+
validatePasswordAgainstPolicy,
|
|
144
|
+
withSuspendedStoreMetadataFallback
|
|
145
|
+
};
|
|
146
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["// @ecomweb/storefront-kit: client-safe hooks, providers and helpers.\nexport { StorefrontKitProvider } from \"./provider\";\nexport type { StorefrontKitProviderProps } from \"./provider\";\nexport { useNotify } from \"./notices\";\nexport { useCheckout } from \"./checkout/use-checkout\";\nexport { useOrderLookup, useOrderStatus } from \"./orders/use-order-status\";\nexport type { BankAccountView } from \"./orders/use-order-status\";\nexport type {\n PlacedOrder,\n PlaceOrderInput,\n PlaceOrderResult,\n UseCheckoutOptions,\n} from \"./checkout/use-checkout\";\nexport type { Notice, NoticeHandler, NoticeKind } from \"./notices\";\nexport {\n useOptionalStoreId,\n useStore,\n useStoreCurrency,\n useStoreData,\n useStoreId,\n useStoreLocale,\n} from \"./store/store-context\";\nexport { usePublicAuthConfig } from \"./auth/use-public-auth-config\";\nexport { publicApiClient } from \"./api/client\";\nexport { unwrap, unwrapOrNull } from \"./api/response\";\nexport { useAuth } from \"./auth/context\";\nexport { errorCopy, errorCopyFor } from \"./auth/error-copy\";\nexport {\n getPasswordPolicyHints,\n validatePasswordAgainstPolicy,\n} from \"./auth/password-policy\";\nexport { DEFAULT_REDIRECT, safeRedirectPath } from \"./auth/safe-redirect\";\nexport { useCart } from \"./cart/server-context\";\nexport { getPaymentState } from \"./checkout/get-payment-state\";\nexport { readOrderHandoff } from \"./checkout/order-handoff\";\nexport type { OrderHandoff } from \"./checkout/order-handoff\";\nexport { pollPaymentState } from \"./checkout/payment-state-poll\";\nexport { STOCK_ISSUE_TOAST_DESCRIPTION } from \"./checkout/stock-issues\";\nexport {\n resolveInitialState,\n shouldPollForConfirmation,\n} from \"./checkout/success-state\";\nexport type { PaymentConfirmationState } from \"./checkout/success-state\";\nexport type { OrderSuccessInfo } from \"./checkout/types\";\nexport {\n formatNumber,\n formatPrice,\n formatPriceRange,\n formatPriceWithoutSymbol,\n getDefaultLocale,\n money,\n} from \"./currency\";\nexport type { SupportedCurrency } from \"./currency\";\nexport {\n ORDER_PROGRESS_STEPS,\n deriveOrderProgress,\n} from \"./orders/derive-progress\";\nexport { STATUS_OPTIONS } from \"./orders/types\";\nexport { getPromotionDescription } from \"./promotions/utils\";\nexport { createStoreSdk, sdk } from \"./sdk\";\nexport { formatShippingAmount } from \"./shipping/format-shipping-option\";\nexport {\n loadWards,\n searchTextFor,\n useProvinces,\n useWards,\n} from \"./shipping/location-areas\";\nexport { SHIPPING_MESSAGES, formatShippingEstimate } from \"./shipping/messages\";\nexport {\n findProvinceByCodeOrName,\n findWardByCodeOrName,\n} from \"./shipping/utils\";\nexport {\n resolveAssetSrc,\n resolveTransformedImageUrl,\n resolveTransformedProductImageUrl,\n resolveTransformedStoreLogoUrl,\n} from \"./storage\";\nexport { resolveStoreRef, storeApiPath, storePath } from \"./store-scope\";\nexport { buildStoreUrl } from \"./store-scope/store-url\";\nexport { readBasicSettings, resolveLegalHref } from \"./stores/basic-settings\";\nexport { getCachedStore } from \"./stores/cached\";\nexport {\n SUSPENDED_STORE_METADATA,\n withSuspendedStoreMetadataFallback,\n} from \"./stores/metadata\";\nexport { refFromPathname } from \"./stores/store-path\";\nexport { isStoreSuspendedError } from \"./stores/store-suspension\";\nexport { applyConsoleFilter, getLogLevel, shouldLog } from \"./logging\";\n"],"mappings":"AACA,SAAS,6BAA6B;AAEtC,SAAS,iBAAiB;AAC1B,SAAS,mBAAmB;AAC5B,SAAS,gBAAgB,sBAAsB;AAS/C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,2BAA2B;AACpC,SAAS,uBAAuB;AAChC,SAAS,QAAQ,oBAAoB;AACrC,SAAS,eAAe;AACxB,SAAS,WAAW,oBAAoB;AACxC;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,kBAAkB,wBAAwB;AACnD,SAAS,eAAe;AACxB,SAAS,uBAAuB;AAChC,SAAS,wBAAwB;AAEjC,SAAS,wBAAwB;AACjC,SAAS,qCAAqC;AAC9C;AAAA,EACE;AAAA,EACA;AAAA,OACK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B,SAAS,+BAA+B;AACxC,SAAS,gBAAgB,WAAW;AACpC,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,mBAAmB,8BAA8B;AAC1D;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,iBAAiB,cAAc,iBAAiB;AACzD,SAAS,qBAAqB;AAC9B,SAAS,mBAAmB,wBAAwB;AACpD,SAAS,sBAAsB;AAC/B;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP,SAAS,uBAAuB;AAChC,SAAS,6BAA6B;AACtC,SAAS,oBAAoB,aAAa,iBAAiB;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=api.types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/interfaces/index.ts"],"sourcesContent":["// Re-export all interfaces for easier imports\nexport * from \"./api.types\";\n"],"mappings":"AACA,cAAc;","names":[]}
|
package/dist/logging.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { publicConfig } from "./config/public.js";
|
|
2
|
+
import { serverLogLevel } from "./config/log-level.js";
|
|
3
|
+
const levelOrder = {
|
|
4
|
+
silent: 0,
|
|
5
|
+
error: 1,
|
|
6
|
+
warn: 2,
|
|
7
|
+
info: 3,
|
|
8
|
+
debug: 4
|
|
9
|
+
};
|
|
10
|
+
function getLogLevel() {
|
|
11
|
+
const envLevel = publicConfig().logLevel ?? serverLogLevel();
|
|
12
|
+
if (envLevel && envLevel in levelOrder) return envLevel;
|
|
13
|
+
return process.env.NODE_ENV === "production" ? "warn" : "debug";
|
|
14
|
+
}
|
|
15
|
+
function shouldLog(currentLevel, messageLevel) {
|
|
16
|
+
return levelOrder[messageLevel] <= levelOrder[currentLevel] && currentLevel !== "silent";
|
|
17
|
+
}
|
|
18
|
+
let appliedLevel = null;
|
|
19
|
+
function applyConsoleFilter(level = getLogLevel()) {
|
|
20
|
+
if (appliedLevel === level) return;
|
|
21
|
+
appliedLevel = level;
|
|
22
|
+
const original = {
|
|
23
|
+
log: console.log.bind(console),
|
|
24
|
+
info: console.info ? console.info.bind(console) : console.log.bind(console),
|
|
25
|
+
debug: console.debug ? console.debug.bind(console) : console.log.bind(console),
|
|
26
|
+
warn: console.warn.bind(console),
|
|
27
|
+
error: console.error.bind(console)
|
|
28
|
+
};
|
|
29
|
+
const noop = () => {
|
|
30
|
+
};
|
|
31
|
+
console.debug = shouldLog(level, "debug") ? original.debug : noop;
|
|
32
|
+
console.log = shouldLog(level, "info") ? original.log : noop;
|
|
33
|
+
console.info = shouldLog(level, "info") ? original.info : noop;
|
|
34
|
+
console.warn = shouldLog(level, "warn") ? original.warn : noop;
|
|
35
|
+
console.error = shouldLog(level, "error") ? original.error : noop;
|
|
36
|
+
}
|
|
37
|
+
export {
|
|
38
|
+
applyConsoleFilter,
|
|
39
|
+
getLogLevel,
|
|
40
|
+
shouldLog
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=logging.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/logging.ts"],"sourcesContent":["/**\n * Lightweight logging helpers: log levels + console filtering.\n * - Defaults to 'warn' in production and 'debug' in development\n * - Honors `NEXT_PUBLIC_LOG_LEVEL` (client) or `LOG_LEVEL` (server)\n */\n\nimport { publicConfig } from \"./config/public\";\nimport { serverLogLevel } from \"./config/log-level\";\n\nexport type LogLevel = \"silent\" | \"error\" | \"warn\" | \"info\" | \"debug\";\n\nconst levelOrder: Record<LogLevel, number> = {\n silent: 0,\n error: 1,\n warn: 2,\n info: 3,\n debug: 4,\n};\n\nexport function getLogLevel(): LogLevel {\n const envLevel =\n publicConfig().logLevel ?? serverLogLevel();\n\n if (envLevel && envLevel in levelOrder) return envLevel;\n\n return process.env.NODE_ENV === \"production\" ? \"warn\" : \"debug\";\n}\n\nexport function shouldLog(currentLevel: LogLevel, messageLevel: LogLevel) {\n return (\n levelOrder[messageLevel] <= levelOrder[currentLevel] &&\n currentLevel !== \"silent\"\n );\n}\n\n/**\n * Replace noisy console methods based on configured level.\n * - Disables lower-priority methods while preserving warn/error by default.\n * - Safe to call multiple times; idempotent for the same level.\n */\nlet appliedLevel: LogLevel | null = null;\nexport function applyConsoleFilter(level: LogLevel = getLogLevel()) {\n if (appliedLevel === level) return; // avoid re-wrapping\n appliedLevel = level;\n\n const original = {\n log: console.log.bind(console),\n info: console.info ? console.info.bind(console) : console.log.bind(console),\n debug: console.debug\n ? console.debug.bind(console)\n : console.log.bind(console),\n warn: console.warn.bind(console),\n error: console.error.bind(console),\n } as const;\n\n const noop = () => {};\n\n console.debug = shouldLog(level, \"debug\") ? original.debug : noop;\n console.log = shouldLog(level, \"info\") ? original.log : noop;\n console.info = shouldLog(level, \"info\") ? original.info : noop;\n console.warn = shouldLog(level, \"warn\") ? original.warn : noop;\n console.error = shouldLog(level, \"error\") ? original.error : noop;\n}\n"],"mappings":"AAMA,SAAS,oBAAoB;AAC7B,SAAS,sBAAsB;AAI/B,MAAM,aAAuC;AAAA,EAC3C,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,MAAM;AAAA,EACN,MAAM;AAAA,EACN,OAAO;AACT;AAEO,SAAS,cAAwB;AACtC,QAAM,WACJ,aAAa,EAAE,YAAY,eAAe;AAE5C,MAAI,YAAY,YAAY,WAAY,QAAO;AAE/C,SAAO,QAAQ,IAAI,aAAa,eAAe,SAAS;AAC1D;AAEO,SAAS,UAAU,cAAwB,cAAwB;AACxE,SACE,WAAW,YAAY,KAAK,WAAW,YAAY,KACnD,iBAAiB;AAErB;AAOA,IAAI,eAAgC;AAC7B,SAAS,mBAAmB,QAAkB,YAAY,GAAG;AAClE,MAAI,iBAAiB,MAAO;AAC5B,iBAAe;AAEf,QAAM,WAAW;AAAA,IACf,KAAK,QAAQ,IAAI,KAAK,OAAO;AAAA,IAC7B,MAAM,QAAQ,OAAO,QAAQ,KAAK,KAAK,OAAO,IAAI,QAAQ,IAAI,KAAK,OAAO;AAAA,IAC1E,OAAO,QAAQ,QACX,QAAQ,MAAM,KAAK,OAAO,IAC1B,QAAQ,IAAI,KAAK,OAAO;AAAA,IAC5B,MAAM,QAAQ,KAAK,KAAK,OAAO;AAAA,IAC/B,OAAO,QAAQ,MAAM,KAAK,OAAO;AAAA,EACnC;AAEA,QAAM,OAAO,MAAM;AAAA,EAAC;AAEpB,UAAQ,QAAQ,UAAU,OAAO,OAAO,IAAI,SAAS,QAAQ;AAC7D,UAAQ,MAAM,UAAU,OAAO,MAAM,IAAI,SAAS,MAAM;AACxD,UAAQ,OAAO,UAAU,OAAO,MAAM,IAAI,SAAS,OAAO;AAC1D,UAAQ,OAAO,UAAU,OAAO,MAAM,IAAI,SAAS,OAAO;AAC1D,UAAQ,QAAQ,UAAU,OAAO,OAAO,IAAI,SAAS,QAAQ;AAC/D;","names":[]}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
import { publicNextUrl } from "../request/public-url.js";
|
|
2
|
+
import { NextResponse } from "next/server";
|
|
3
|
+
import { authCookiePath, writeAuthCookies } from "../auth/cookies.js";
|
|
4
|
+
import {
|
|
5
|
+
downstreamRequestHeaders,
|
|
6
|
+
refreshIfNearExpiry
|
|
7
|
+
} from "../auth/session-refresh.js";
|
|
8
|
+
import { publicConfig } from "../config/public.js";
|
|
9
|
+
import { lookupRedirect } from "../redirects/lookup-redirect.js";
|
|
10
|
+
import { multiTenantStorePath } from "../store-scope/index.js";
|
|
11
|
+
import { getStoreByHost } from "../stores/get-store-by-host.js";
|
|
12
|
+
const METADATA_FILES = [
|
|
13
|
+
"/robots.txt",
|
|
14
|
+
"/sitemap.xml",
|
|
15
|
+
"/favicon.ico",
|
|
16
|
+
"/manifest.json",
|
|
17
|
+
"/manifest.webmanifest",
|
|
18
|
+
"/icon",
|
|
19
|
+
"/apple-icon"
|
|
20
|
+
];
|
|
21
|
+
function storeRefFromPath(pathname) {
|
|
22
|
+
const match = /^\/store\/([^/]+)/.exec(pathname);
|
|
23
|
+
if (!match) return null;
|
|
24
|
+
try {
|
|
25
|
+
return decodeURIComponent(match[1]) || null;
|
|
26
|
+
} catch {
|
|
27
|
+
return match[1];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function buildRedirectResponse(req, redirect, pathPrefix = "") {
|
|
31
|
+
const redirectUrl = publicNextUrl(req);
|
|
32
|
+
redirectUrl.pathname = `${pathPrefix}${redirect.destination_path}`;
|
|
33
|
+
return NextResponse.redirect(redirectUrl, { status: redirect.redirect_type });
|
|
34
|
+
}
|
|
35
|
+
async function multiTenant(req) {
|
|
36
|
+
const host = req.headers.get("host") || "";
|
|
37
|
+
const pathname = req.nextUrl.pathname;
|
|
38
|
+
if (METADATA_FILES.includes(pathname)) {
|
|
39
|
+
return NextResponse.next();
|
|
40
|
+
}
|
|
41
|
+
const platformDomain = publicConfig().platformDomainSuffix ?? "ecomsite.app";
|
|
42
|
+
const hostIdentifiesStore = !host.includes("localhost") && !host.includes("127.0.0.1") && host !== platformDomain && host !== `www.${platformDomain}`;
|
|
43
|
+
let hostStoreRef = null;
|
|
44
|
+
let hostResolved = false;
|
|
45
|
+
let hostStoreSuspended = false;
|
|
46
|
+
if (hostIdentifiesStore) {
|
|
47
|
+
try {
|
|
48
|
+
const { storeRef: storeRef2, domain, isSubDomain, suspended } = await getStoreByHost(host);
|
|
49
|
+
hostResolved = true;
|
|
50
|
+
hostStoreRef = storeRef2 || null;
|
|
51
|
+
hostStoreSuspended = suspended;
|
|
52
|
+
if (storeRef2) {
|
|
53
|
+
if (isSubDomain && domain && domain !== host) {
|
|
54
|
+
const url = publicNextUrl(req);
|
|
55
|
+
url.hostname = domain;
|
|
56
|
+
url.protocol = "https:";
|
|
57
|
+
url.port = "";
|
|
58
|
+
return NextResponse.redirect(url, { status: 301 });
|
|
59
|
+
}
|
|
60
|
+
if (!pathname.startsWith(multiTenantStorePath(storeRef2))) {
|
|
61
|
+
const redirect = await lookupRedirect(storeRef2, pathname);
|
|
62
|
+
if (redirect) {
|
|
63
|
+
return buildRedirectResponse(req, redirect);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
} catch (error) {
|
|
68
|
+
console.debug("Middleware error:", error);
|
|
69
|
+
hostResolved = false;
|
|
70
|
+
hostStoreRef = null;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const storeRef = hostStoreRef ?? storeRefFromPath(pathname);
|
|
74
|
+
if (!hostStoreRef && storeRef) {
|
|
75
|
+
const prefix = multiTenantStorePath(storeRef);
|
|
76
|
+
if (pathname === prefix || pathname.startsWith(`${prefix}/`)) {
|
|
77
|
+
try {
|
|
78
|
+
const logicalPath = pathname.slice(prefix.length) || "/";
|
|
79
|
+
const redirect = await lookupRedirect(storeRef, logicalPath);
|
|
80
|
+
if (redirect) {
|
|
81
|
+
return buildRedirectResponse(req, redirect, prefix);
|
|
82
|
+
}
|
|
83
|
+
} catch (error) {
|
|
84
|
+
console.debug("Redirect lookup error:", error);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
const rotated = storeRef ? await refreshIfNearExpiry(req, storeRef) : null;
|
|
89
|
+
const init = {
|
|
90
|
+
request: {
|
|
91
|
+
headers: downstreamRequestHeaders(req, !!hostStoreRef, storeRef, rotated)
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
let response;
|
|
95
|
+
if (hostStoreRef) {
|
|
96
|
+
const url = req.nextUrl.clone();
|
|
97
|
+
if (!url.pathname.startsWith(multiTenantStorePath(hostStoreRef))) {
|
|
98
|
+
url.pathname = multiTenantStorePath(hostStoreRef, url.pathname);
|
|
99
|
+
}
|
|
100
|
+
response = NextResponse.rewrite(url, init);
|
|
101
|
+
response.headers.set("x-store-domain", "true");
|
|
102
|
+
response.headers.set("x-store-ref", hostStoreRef);
|
|
103
|
+
} else if (hostStoreSuspended) {
|
|
104
|
+
const url = req.nextUrl.clone();
|
|
105
|
+
url.pathname = "/store-suspended";
|
|
106
|
+
response = NextResponse.rewrite(url, init);
|
|
107
|
+
} else if (hostResolved) {
|
|
108
|
+
console.debug("Store not found for host:", host);
|
|
109
|
+
const url = req.nextUrl.clone();
|
|
110
|
+
url.pathname = "/404";
|
|
111
|
+
response = NextResponse.rewrite(url, init);
|
|
112
|
+
} else {
|
|
113
|
+
response = NextResponse.next(init);
|
|
114
|
+
}
|
|
115
|
+
if (rotated && storeRef) {
|
|
116
|
+
writeAuthCookies(
|
|
117
|
+
response,
|
|
118
|
+
storeRef,
|
|
119
|
+
rotated,
|
|
120
|
+
authCookiePath(storeRef, !!hostStoreRef)
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
return response;
|
|
124
|
+
}
|
|
125
|
+
async function singleStore(req) {
|
|
126
|
+
const pathname = req.nextUrl.pathname;
|
|
127
|
+
if (METADATA_FILES.includes(pathname)) return NextResponse.next();
|
|
128
|
+
const storeRef = publicConfig().storeRef;
|
|
129
|
+
try {
|
|
130
|
+
const redirect = await lookupRedirect(storeRef, pathname);
|
|
131
|
+
if (redirect) {
|
|
132
|
+
const url = publicNextUrl(req);
|
|
133
|
+
url.pathname = redirect.destination_path;
|
|
134
|
+
return NextResponse.redirect(url, { status: redirect.redirect_type });
|
|
135
|
+
}
|
|
136
|
+
} catch (error) {
|
|
137
|
+
console.debug("Redirect lookup error:", error);
|
|
138
|
+
}
|
|
139
|
+
const rotated = await refreshIfNearExpiry(req, storeRef);
|
|
140
|
+
const response = NextResponse.next({
|
|
141
|
+
request: {
|
|
142
|
+
headers: downstreamRequestHeaders(req, true, storeRef, rotated)
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
if (rotated) {
|
|
146
|
+
writeAuthCookies(
|
|
147
|
+
response,
|
|
148
|
+
storeRef,
|
|
149
|
+
rotated,
|
|
150
|
+
authCookiePath(storeRef, true)
|
|
151
|
+
);
|
|
152
|
+
}
|
|
153
|
+
return response;
|
|
154
|
+
}
|
|
155
|
+
function createStorefrontMiddleware(opts = {}) {
|
|
156
|
+
return (req) => (opts.mode ?? publicConfig().mode) === "multi" ? multiTenant(req) : singleStore(req);
|
|
157
|
+
}
|
|
158
|
+
const storefrontMiddlewareConfig = {
|
|
159
|
+
matcher: [
|
|
160
|
+
/*
|
|
161
|
+
* Match all request paths except for the ones starting with:
|
|
162
|
+
* - api (API routes)
|
|
163
|
+
* - _next/static (static files)
|
|
164
|
+
* - _next/image (image optimization files)
|
|
165
|
+
* - _vercel (Vercel Analytics; off Vercel, a store page render per hit)
|
|
166
|
+
* - favicon.ico (favicon file)
|
|
167
|
+
*/
|
|
168
|
+
"/((?!api|_next/static|_next/image|_vercel|favicon.ico).*)"
|
|
169
|
+
]
|
|
170
|
+
};
|
|
171
|
+
export {
|
|
172
|
+
createStorefrontMiddleware,
|
|
173
|
+
storefrontMiddlewareConfig
|
|
174
|
+
};
|
|
175
|
+
//# sourceMappingURL=create-storefront-middleware.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/middleware/create-storefront-middleware.ts"],"sourcesContent":["import { publicNextUrl } from \"../request/public-url\";\nimport { NextRequest, NextResponse } from \"next/server\";\nimport type { UrlRedirect } from \"@ecomweb/sdk\";\nimport { authCookiePath, writeAuthCookies } from \"../auth/cookies\";\nimport {\n downstreamRequestHeaders,\n refreshIfNearExpiry,\n} from \"../auth/session-refresh\";\nimport type { StorefrontMode } from \"../config/mode\";\nimport { publicConfig } from \"../config/public\";\nimport { lookupRedirect } from \"../redirects/lookup-redirect\";\nimport { multiTenantStorePath } from \"../store-scope\";\nimport { getStoreByHost } from \"../stores/get-store-by-host\";\n\n/** Served from the app root in both modes; never rewritten or redirected. */\nconst METADATA_FILES = [\n \"/robots.txt\",\n \"/sitemap.xml\",\n \"/favicon.ico\",\n \"/manifest.json\",\n \"/manifest.webmanifest\",\n \"/icon\",\n \"/apple-icon\",\n];\n\n/**\n * The store a request belongs to, as far as the *path* can say.\n *\n * On localhost and on the platform apex there is no host→store mapping, but\n * the path is `/store/<storeRef>/…` — which is also how the auth cookies are\n * named. `params.storeRef` arrives URL-decoded downstream, so decode here too.\n */\nfunction storeRefFromPath(pathname: string): string | null {\n const match = /^\\/store\\/([^/]+)/.exec(pathname);\n if (!match) return null;\n try {\n return decodeURIComponent(match[1]) || null;\n } catch {\n return match[1];\n }\n}\n\n/**\n * Turns a stored redirect row into the 301/302 response for it.\n *\n * `pathPrefix` re-adds the `/store/<ref>` segment that direct path-based\n * access needs on the destination but a host-mapped request (whose\n * `destination_path` is already store-root-relative) does not.\n */\nfunction buildRedirectResponse(\n req: NextRequest,\n redirect: UrlRedirect,\n pathPrefix = \"\"\n): NextResponse {\n const redirectUrl = publicNextUrl(req);\n redirectUrl.pathname = `${pathPrefix}${redirect.destination_path}`;\n return NextResponse.redirect(redirectUrl, { status: redirect.redirect_type });\n}\n\nasync function multiTenant(req: NextRequest): Promise<NextResponse> {\n const host = req.headers.get(\"host\") || \"\";\n const pathname = req.nextUrl.pathname;\n\n // Skip metadata files - these are served from app root level\n if (METADATA_FILES.includes(pathname)) {\n return NextResponse.next();\n }\n\n // Store-by-host resolution and redirect lookup genuinely do not apply on\n // localhost or on the platform apex — but the token refresh below does, so\n // these only skip the host-specific work now, not the whole middleware.\n const platformDomain = publicConfig().platformDomainSuffix ?? \"ecomsite.app\";\n const hostIdentifiesStore =\n !host.includes(\"localhost\") &&\n !host.includes(\"127.0.0.1\") &&\n host !== platformDomain &&\n host !== `www.${platformDomain}`;\n\n let hostStoreRef: string | null = null;\n let hostResolved = false;\n\n let hostStoreSuspended = false;\n\n if (hostIdentifiesStore) {\n try {\n const { storeRef, domain, isSubDomain, suspended } =\n await getStoreByHost(host);\n hostResolved = true;\n hostStoreRef = storeRef || null;\n hostStoreSuspended = suspended;\n\n if (storeRef) {\n // If accessing via subdomain but custom domain exists, redirect to custom domain\n if (isSubDomain && domain && domain !== host) {\n const url = publicNextUrl(req);\n url.hostname = domain;\n url.protocol = \"https:\";\n url.port = \"\"; // Remove port for custom domain\n return NextResponse.redirect(url, { status: 301 });\n }\n\n // Check for URL redirects BEFORE rewriting\n // Skip redirect check if path already starts with /store/ (internal rewrite)\n if (!pathname.startsWith(multiTenantStorePath(storeRef))) {\n const redirect = await lookupRedirect(storeRef, pathname);\n\n if (redirect) {\n return buildRedirectResponse(req, redirect);\n }\n }\n }\n } catch (error) {\n console.debug(\"Middleware error:\", error);\n // Fall through: no host mapping, but the refresh below still applies.\n hostResolved = false;\n hostStoreRef = null;\n }\n }\n\n // The host names the store on custom domains and subdomains; everywhere else\n // (localhost, the apex, direct /store/<ref>/… access) the path does.\n const storeRef = hostStoreRef ?? storeRefFromPath(pathname);\n\n // Direct /store/<ref>/… access never goes through the host-mapped branch\n // above, so it gets no redirect check there. `redirect_source_path` rows\n // are store-root-relative (e.g. \"/old\"), the same shape a host-mapped\n // request already checks against — strip the /store/<ref> prefix to\n // recover that shape, and re-add it on the destination.\n if (!hostStoreRef && storeRef) {\n const prefix = multiTenantStorePath(storeRef);\n if (pathname === prefix || pathname.startsWith(`${prefix}/`)) {\n try {\n const logicalPath = pathname.slice(prefix.length) || \"/\";\n const redirect = await lookupRedirect(storeRef, logicalPath);\n\n if (redirect) {\n return buildRedirectResponse(req, redirect, prefix);\n }\n } catch (error) {\n // Fail open: lookupRedirect already catches internally and never\n // rejects, but this belongs to the caller's contract, not the\n // callee's — a future regression there must not take the page down.\n console.debug(\"Redirect lookup error:\", error);\n }\n }\n }\n\n const rotated = storeRef ? await refreshIfNearExpiry(req, storeRef) : null;\n const init = {\n request: {\n headers: downstreamRequestHeaders(req, !!hostStoreRef, storeRef, rotated),\n },\n };\n\n let response: NextResponse;\n\n if (hostStoreRef) {\n const url = req.nextUrl.clone();\n // Only rewrite if the path doesn't already start with /store/\n if (!url.pathname.startsWith(multiTenantStorePath(hostStoreRef))) {\n url.pathname = multiTenantStorePath(hostStoreRef, url.pathname);\n }\n\n response = NextResponse.rewrite(url, init);\n // Add headers to indicate this is a domain-mapped store\n response.headers.set(\"x-store-domain\", \"true\");\n response.headers.set(\"x-store-ref\", hostStoreRef);\n } else if (hostStoreSuspended) {\n // A platform admin suspended this store. The 403 the backend returned\n // for a domain lookup carries no ref/id to route on (see\n // getStoreByHost), so this can't rewrite to `/store/<ref>` the way the\n // resolved-store branch above does — it goes to a platform-level page\n // instead of the not-found path below.\n const url = req.nextUrl.clone();\n url.pathname = \"/store-suspended\";\n response = NextResponse.rewrite(url, init);\n } else if (hostResolved) {\n // The host looked like a store host but resolved to nothing: 404.\n console.debug(\"Store not found for host:\", host);\n const url = req.nextUrl.clone();\n url.pathname = \"/404\";\n response = NextResponse.rewrite(url, init);\n } else {\n response = NextResponse.next(init);\n }\n\n if (rotated && storeRef) {\n // Same path the auth route handler writes with, from the same signal.\n writeAuthCookies(\n response,\n storeRef,\n rotated,\n authCookiePath(storeRef, !!hostStoreRef)\n );\n }\n\n return response;\n}\n\n/**\n * Single-store middleware: the store is fixed by ECOMWEB_STORE_REF, so there\n * is no host lookup and no rewrite. It applies the store's URL redirects and\n * refreshes a near-expiry session. Requests are stamped host-mapped, so auth\n * cookies use Path=/ (see auth/cookies.ts).\n */\nasync function singleStore(req: NextRequest): Promise<NextResponse> {\n const pathname = req.nextUrl.pathname;\n if (METADATA_FILES.includes(pathname)) return NextResponse.next();\n\n const storeRef = publicConfig().storeRef as string;\n\n try {\n const redirect = await lookupRedirect(storeRef, pathname);\n if (redirect) {\n const url = publicNextUrl(req);\n url.pathname = redirect.destination_path;\n return NextResponse.redirect(url, { status: redirect.redirect_type });\n }\n } catch (error) {\n // Fail open: a redirect lookup must never take the page down.\n console.debug(\"Redirect lookup error:\", error);\n }\n\n const rotated = await refreshIfNearExpiry(req, storeRef);\n const response = NextResponse.next({\n request: {\n headers: downstreamRequestHeaders(req, true, storeRef, rotated),\n },\n });\n\n if (rotated) {\n writeAuthCookies(\n response,\n storeRef,\n rotated,\n authCookiePath(storeRef, true)\n );\n }\n return response;\n}\n\n/**\n * The storefront's proxy.ts (Next middleware).\n * - multi: host → store lookup, rewrites to /store/<ref>, suspended and\n * unknown stores, redirects, session refresh.\n * - single: redirects and session refresh only.\n * Without `mode`, the configured mode (ECOMWEB_MODE) decides per request.\n */\nexport function createStorefrontMiddleware(\n opts: { mode?: StorefrontMode } = {}\n): (req: NextRequest) => Promise<NextResponse> {\n return req =>\n (opts.mode ?? publicConfig().mode) === \"multi\"\n ? multiTenant(req)\n : singleStore(req);\n}\n\n/**\n * Next reads `config` from proxy.ts statically, so an app re-exports this as\n * `export const config = { matcher: [...] }` with the same literal.\n */\nexport const storefrontMiddlewareConfig = {\n matcher: [\n /*\n * Match all request paths except for the ones starting with:\n * - api (API routes)\n * - _next/static (static files)\n * - _next/image (image optimization files)\n * - _vercel (Vercel Analytics; off Vercel, a store page render per hit)\n * - favicon.ico (favicon file)\n */\n \"/((?!api|_next/static|_next/image|_vercel|favicon.ico).*)\",\n ],\n};\n"],"mappings":"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","names":["storeRef"]}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { NextRequest, NextResponse } from 'next/server';
|
|
2
|
+
import { S as StorefrontMode } from './mode-1ZKDELPZ.js';
|
|
3
|
+
import './schema-CEMKsCwh.js';
|
|
4
|
+
import 'zod';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The storefront's proxy.ts (Next middleware).
|
|
8
|
+
* - multi: host → store lookup, rewrites to /store/<ref>, suspended and
|
|
9
|
+
* unknown stores, redirects, session refresh.
|
|
10
|
+
* - single: redirects and session refresh only.
|
|
11
|
+
* Without `mode`, the configured mode (ECOMWEB_MODE) decides per request.
|
|
12
|
+
*/
|
|
13
|
+
declare function createStorefrontMiddleware(opts?: {
|
|
14
|
+
mode?: StorefrontMode;
|
|
15
|
+
}): (req: NextRequest) => Promise<NextResponse>;
|
|
16
|
+
/**
|
|
17
|
+
* Next reads `config` from proxy.ts statically, so an app re-exports this as
|
|
18
|
+
* `export const config = { matcher: [...] }` with the same literal.
|
|
19
|
+
*/
|
|
20
|
+
declare const storefrontMiddlewareConfig: {
|
|
21
|
+
matcher: string[];
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export { createStorefrontMiddleware, storefrontMiddlewareConfig };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/middleware.ts"],"sourcesContent":["// @ecomweb/storefront-kit/middleware: the storefront's proxy.ts.\nexport {\n createStorefrontMiddleware,\n storefrontMiddlewareConfig,\n} from \"./middleware/create-storefront-middleware\";\n"],"mappings":"AACA;AAAA,EACE;AAAA,EACA;AAAA,OACK;","names":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { E as EnvSource } from './schema-CEMKsCwh.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* multi: the shared platform storefront, every store under /store/<ref> or
|
|
5
|
+
* its own host. single: one merchant's storefront, the store is the site.
|
|
6
|
+
*/
|
|
7
|
+
type StorefrontMode = "multi" | "single";
|
|
8
|
+
/**
|
|
9
|
+
* NEXT_PUBLIC_ECOMWEB_MODE is inlined into client bundles, so it wins;
|
|
10
|
+
* ECOMWEB_MODE is the server-side spelling. Unset means single: an ejected
|
|
11
|
+
* storefront needs no extra setting, and the shared app sets multi in
|
|
12
|
+
* next.config.mjs.
|
|
13
|
+
*/
|
|
14
|
+
declare function resolveMode(env: EnvSource): StorefrontMode;
|
|
15
|
+
|
|
16
|
+
export { type StorefrontMode as S, resolveMode as r };
|
package/dist/notices.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import {
|
|
4
|
+
createContext,
|
|
5
|
+
useCallback,
|
|
6
|
+
useContext,
|
|
7
|
+
useEffect,
|
|
8
|
+
useRef
|
|
9
|
+
} from "react";
|
|
10
|
+
const noop = () => {
|
|
11
|
+
};
|
|
12
|
+
const NoticeContext = createContext(noop);
|
|
13
|
+
function NoticeProvider({
|
|
14
|
+
onNotice,
|
|
15
|
+
children
|
|
16
|
+
}) {
|
|
17
|
+
const latest = useRef(onNotice);
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
latest.current = onNotice;
|
|
20
|
+
}, [onNotice]);
|
|
21
|
+
const notify = useCallback((n) => latest.current?.(n), []);
|
|
22
|
+
return /* @__PURE__ */ jsx(NoticeContext.Provider, { value: notify, children });
|
|
23
|
+
}
|
|
24
|
+
function useNotify() {
|
|
25
|
+
return useContext(NoticeContext);
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
NoticeProvider,
|
|
29
|
+
useNotify
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=notices.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/notices.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n createContext,\n useCallback,\n useContext,\n useEffect,\n useRef,\n type ReactNode,\n} from \"react\";\n\nexport type NoticeKind = \"success\" | \"error\" | \"info\";\n\n/**\n * Something the shopper should hear about (an item added, a failed request).\n * The kit never renders these; the app decides how, usually as a toast.\n */\nexport interface Notice {\n kind: NoticeKind;\n title: string;\n description?: string;\n /** Stable identifier for apps that render some notices specially. */\n code?: string;\n /** Values the description was built from, keyed by name. */\n data?: Record<string, string>;\n}\n\nexport type NoticeHandler = (notice: Notice) => void;\n\nconst noop: NoticeHandler = () => {};\n\nconst NoticeContext = createContext<NoticeHandler>(noop);\n\nexport function NoticeProvider({\n onNotice,\n children,\n}: {\n onNotice?: NoticeHandler;\n children: ReactNode;\n}) {\n // A stable function, so hooks can list it as a dependency without\n // re-running whenever the app passes a new inline handler.\n const latest = useRef(onNotice);\n useEffect(() => {\n latest.current = onNotice;\n }, [onNotice]);\n const notify = useCallback<NoticeHandler>(n => latest.current?.(n), []);\n return (\n <NoticeContext.Provider value={notify}>{children}</NoticeContext.Provider>\n );\n}\n\n/** Report a notice to the app; a no-op outside a NoticeProvider. */\nexport function useNotify(): NoticeHandler {\n return useContext(NoticeContext);\n}\n"],"mappings":";AAgDI;AA9CJ;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAoBP,MAAM,OAAsB,MAAM;AAAC;AAEnC,MAAM,gBAAgB,cAA6B,IAAI;AAEhD,SAAS,eAAe;AAAA,EAC7B;AAAA,EACA;AACF,GAGG;AAGD,QAAM,SAAS,OAAO,QAAQ;AAC9B,YAAU,MAAM;AACd,WAAO,UAAU;AAAA,EACnB,GAAG,CAAC,QAAQ,CAAC;AACb,QAAM,SAAS,YAA2B,OAAK,OAAO,UAAU,CAAC,GAAG,CAAC,CAAC;AACtE,SACE,oBAAC,cAAc,UAAd,EAAuB,OAAO,QAAS,UAAS;AAErD;AAGO,SAAS,YAA2B;AACzC,SAAO,WAAW,aAAa;AACjC;","names":[]}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { createStoreSdk, sdk } from "../sdk.js";
|
|
2
|
+
const publicOrdersApi = {
|
|
3
|
+
async getPublicOrderStatus(storeRef, orderNumber, contactInfo) {
|
|
4
|
+
const result = await sdk.orders.lookupGuest(storeRef, {
|
|
5
|
+
order_number: orderNumber,
|
|
6
|
+
customer_email: contactInfo.email,
|
|
7
|
+
customer_phone: contactInfo.phone
|
|
8
|
+
});
|
|
9
|
+
return result.found ? result.order : null;
|
|
10
|
+
},
|
|
11
|
+
/**
|
|
12
|
+
* `isAuth` comes from the caller's auth context — this module is not a
|
|
13
|
+
* component and must not read context or an httpOnly cookie itself.
|
|
14
|
+
*
|
|
15
|
+
* When true the SDK posts to `/tenant/stores/:ref/customers/orders`, which
|
|
16
|
+
* derives BOTH `customer_id` (ResolveCustomerInterceptor) and `user_id`
|
|
17
|
+
* (JWT) server-side; the payload carries neither, and `CreateOrderDto` has no
|
|
18
|
+
* such fields to carry them in. The request reaches that guarded route
|
|
19
|
+
* through the same-origin proxy, which attaches the bearer token.
|
|
20
|
+
*/
|
|
21
|
+
async createStoreOrder(storeRef, data, isAuth) {
|
|
22
|
+
return createStoreSdk(storeRef).orders.create(
|
|
23
|
+
storeRef,
|
|
24
|
+
data,
|
|
25
|
+
isAuth
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
export {
|
|
30
|
+
publicOrdersApi
|
|
31
|
+
};
|
|
32
|
+
//# sourceMappingURL=api-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/orders/api-client.ts"],"sourcesContent":["import { createStoreSdk, sdk } from \"../sdk\";\nimport type { CreateOrderRequest, Order, OrderWithItems } from \"@ecomweb/sdk\";\n\nexport const publicOrdersApi = {\n async getPublicOrderStatus(\n storeRef: string,\n orderNumber: number,\n contactInfo: { email?: string; phone?: string }\n ): Promise<Order | null> {\n const result = await sdk.orders.lookupGuest(storeRef, {\n order_number: orderNumber,\n customer_email: contactInfo.email,\n customer_phone: contactInfo.phone,\n });\n return result.found ? result.order : null;\n },\n\n /**\n * `isAuth` comes from the caller's auth context — this module is not a\n * component and must not read context or an httpOnly cookie itself.\n *\n * When true the SDK posts to `/tenant/stores/:ref/customers/orders`, which\n * derives BOTH `customer_id` (ResolveCustomerInterceptor) and `user_id`\n * (JWT) server-side; the payload carries neither, and `CreateOrderDto` has no\n * such fields to carry them in. The request reaches that guarded route\n * through the same-origin proxy, which attaches the bearer token.\n */\n async createStoreOrder(\n storeRef: string,\n data: Omit<CreateOrderRequest, \"store_id\">,\n isAuth: boolean\n ): Promise<OrderWithItems> {\n return createStoreSdk(storeRef).orders.create(\n storeRef,\n data as CreateOrderRequest,\n isAuth\n );\n },\n};\n\nexport type { CreateOrderRequest, CreateOrderItemRequest } from \"@ecomweb/sdk\";\n"],"mappings":"AAAA,SAAS,gBAAgB,WAAW;AAG7B,MAAM,kBAAkB;AAAA,EAC7B,MAAM,qBACJ,UACA,aACA,aACuB;AACvB,UAAM,SAAS,MAAM,IAAI,OAAO,YAAY,UAAU;AAAA,MACpD,cAAc;AAAA,MACd,gBAAgB,YAAY;AAAA,MAC5B,gBAAgB,YAAY;AAAA,IAC9B,CAAC;AACD,WAAO,OAAO,QAAQ,OAAO,QAAQ;AAAA,EACvC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYA,MAAM,iBACJ,UACA,MACA,QACyB;AACzB,WAAO,eAAe,QAAQ,EAAE,OAAO;AAAA,MACrC;AAAA,MACA;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const ORDER_PROGRESS_STEPS = [
|
|
2
|
+
"\u0110\xE3 \u0111\u1EB7t",
|
|
3
|
+
"\u0110\xE3 x\xE1c nh\u1EADn",
|
|
4
|
+
"\u0110ang chu\u1EA9n b\u1ECB",
|
|
5
|
+
"\u0110ang giao",
|
|
6
|
+
"\u0110\xE3 giao"
|
|
7
|
+
];
|
|
8
|
+
function deriveOrderProgress(order) {
|
|
9
|
+
if (order.order_status === "cancelled") {
|
|
10
|
+
return { kind: "terminal", label: "\u0110\xE3 hu\u1EF7", tone: "cancelled" };
|
|
11
|
+
}
|
|
12
|
+
if (order.order_status === "on_hold") {
|
|
13
|
+
return { kind: "terminal", label: "T\u1EA1m gi\u1EEF", tone: "on_hold" };
|
|
14
|
+
}
|
|
15
|
+
switch (order.shipping_status) {
|
|
16
|
+
case "delivered":
|
|
17
|
+
return { kind: "steps", current_index: 4 };
|
|
18
|
+
case "shipped":
|
|
19
|
+
case "in_transit":
|
|
20
|
+
case "out_for_delivery":
|
|
21
|
+
return { kind: "steps", current_index: 3 };
|
|
22
|
+
}
|
|
23
|
+
switch (order.order_status) {
|
|
24
|
+
case "processing":
|
|
25
|
+
return { kind: "steps", current_index: 2 };
|
|
26
|
+
case "confirmed":
|
|
27
|
+
return { kind: "steps", current_index: 1 };
|
|
28
|
+
default:
|
|
29
|
+
return { kind: "steps", current_index: 0 };
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
ORDER_PROGRESS_STEPS,
|
|
34
|
+
deriveOrderProgress
|
|
35
|
+
};
|
|
36
|
+
//# sourceMappingURL=derive-progress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/orders/derive-progress.ts"],"sourcesContent":["import type { Order } from \"@ecomweb/sdk\";\n\n/**\n * The shopper-facing journey. The API tracks four independent status fields;\n * only order_status and shipping_status are meaningful to a customer.\n * fulfillment_status is warehouse vocabulary (\"unfulfilled\",\n * \"return_requested\") and is never shown.\n */\nexport const ORDER_PROGRESS_STEPS = [\n \"Đã đặt\",\n \"Đã xác nhận\",\n \"Đang chuẩn bị\",\n \"Đang giao\",\n \"Đã giao\",\n] as const;\n\nexport type OrderProgress =\n | { kind: \"steps\"; current_index: number }\n | { kind: \"terminal\"; label: string; tone: \"cancelled\" | \"on_hold\" };\n\n/**\n * Rules are evaluated in order and the first match wins, so a cancelled order\n * shows the terminal state no matter how far shipping had progressed.\n */\nexport function deriveOrderProgress(order: Order): OrderProgress {\n if (order.order_status === \"cancelled\") {\n return { kind: \"terminal\", label: \"Đã huỷ\", tone: \"cancelled\" };\n }\n if (order.order_status === \"on_hold\") {\n return { kind: \"terminal\", label: \"Tạm giữ\", tone: \"on_hold\" };\n }\n\n switch (order.shipping_status) {\n case \"delivered\":\n return { kind: \"steps\", current_index: 4 };\n case \"shipped\":\n case \"in_transit\":\n case \"out_for_delivery\":\n return { kind: \"steps\", current_index: 3 };\n }\n\n switch (order.order_status) {\n case \"processing\":\n return { kind: \"steps\", current_index: 2 };\n case \"confirmed\":\n return { kind: \"steps\", current_index: 1 };\n default:\n return { kind: \"steps\", current_index: 0 };\n }\n}\n"],"mappings":"AAQO,MAAM,uBAAuB;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAUO,SAAS,oBAAoB,OAA6B;AAC/D,MAAI,MAAM,iBAAiB,aAAa;AACtC,WAAO,EAAE,MAAM,YAAY,OAAO,uBAAU,MAAM,YAAY;AAAA,EAChE;AACA,MAAI,MAAM,iBAAiB,WAAW;AACpC,WAAO,EAAE,MAAM,YAAY,OAAO,qBAAW,MAAM,UAAU;AAAA,EAC/D;AAEA,UAAQ,MAAM,iBAAiB;AAAA,IAC7B,KAAK;AACH,aAAO,EAAE,MAAM,SAAS,eAAe,EAAE;AAAA,IAC3C,KAAK;AAAA,IACL,KAAK;AAAA,IACL,KAAK;AACH,aAAO,EAAE,MAAM,SAAS,eAAe,EAAE;AAAA,EAC7C;AAEA,UAAQ,MAAM,cAAc;AAAA,IAC1B,KAAK;AACH,aAAO,EAAE,MAAM,SAAS,eAAe,EAAE;AAAA,IAC3C,KAAK;AACH,aAAO,EAAE,MAAM,SAAS,eAAe,EAAE;AAAA,IAC3C;AACE,aAAO,EAAE,MAAM,SAAS,eAAe,EAAE;AAAA,EAC7C;AACF;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/orders/index.ts"],"sourcesContent":["// Orders API - Pure API Client Architecture\n// Store-based objects pattern - All operations are store-scoped\n// All operations use backend API exclusively - no direct database calls\n// Supabase used only for auth and storage\n\n// Types (sourced from consolidated interface as single source of truth)\nexport * from \"./types\";\n\n// API Clients (store-scoped operations)\nexport { publicOrdersApi } from \"./api-client\";\n"],"mappings":"AAMA,cAAc;AAGd,SAAS,uBAAuB;","names":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const STATUS_OPTIONS = [
|
|
2
|
+
{ label: "T\u1EA5t c\u1EA3", value: "all" },
|
|
3
|
+
{ label: "Ch\u1EDD x\u1EED l\xFD", value: "pending" },
|
|
4
|
+
{ label: "\u0110\xE3 x\xE1c nh\u1EADn", value: "confirmed" },
|
|
5
|
+
{ label: "\u0110ang x\u1EED l\xFD", value: "processing" },
|
|
6
|
+
{ label: "T\u1EA1m gi\u1EEF", value: "on_hold" },
|
|
7
|
+
{ label: "\u0110\xE3 h\u1EE7y", value: "cancelled" },
|
|
8
|
+
{ label: "\u0110\xE3 ho\xE0n th\xE0nh", value: "completed" }
|
|
9
|
+
];
|
|
10
|
+
export {
|
|
11
|
+
STATUS_OPTIONS
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/orders/types.ts"],"sourcesContent":["import type { OrderStatus } from \"@ecomweb/sdk\";\n\nexport const STATUS_OPTIONS: { label: string; value: \"all\" | OrderStatus }[] = [\n { label: \"Tất cả\", value: \"all\" },\n { label: \"Chờ xử lý\", value: \"pending\" },\n { label: \"Đã xác nhận\", value: \"confirmed\" },\n { label: \"Đang xử lý\", value: \"processing\" },\n { label: \"Tạm giữ\", value: \"on_hold\" },\n { label: \"Đã hủy\", value: \"cancelled\" },\n { label: \"Đã hoàn thành\", value: \"completed\" },\n];\n"],"mappings":"AAEO,MAAM,iBAAkE;AAAA,EAC7E,EAAE,OAAO,oBAAU,OAAO,MAAM;AAAA,EAChC,EAAE,OAAO,0BAAa,OAAO,UAAU;AAAA,EACvC,EAAE,OAAO,+BAAe,OAAO,YAAY;AAAA,EAC3C,EAAE,OAAO,2BAAc,OAAO,aAAa;AAAA,EAC3C,EAAE,OAAO,qBAAW,OAAO,UAAU;AAAA,EACrC,EAAE,OAAO,uBAAU,OAAO,YAAY;AAAA,EACtC,EAAE,OAAO,+BAAiB,OAAO,YAAY;AAC/C;","names":[]}
|