@cloudcart/nitro 0.1.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/analytics/index.d.ts +39 -0
- package/dist/analytics/index.js +13 -0
- package/dist/analytics/index.js.map +1 -0
- package/dist/cache/index.d.ts +39 -0
- package/dist/cache/index.js +19 -0
- package/dist/cache/index.js.map +1 -0
- package/dist/cart/index.d.ts +73 -0
- package/dist/cart/index.js +9 -0
- package/dist/cart/index.js.map +1 -0
- package/dist/chunk-2VLIYNGM.js +51 -0
- package/dist/chunk-2VLIYNGM.js.map +1 -0
- package/dist/chunk-3YTOR4GE.js +25 -0
- package/dist/chunk-3YTOR4GE.js.map +1 -0
- package/dist/chunk-6DOUKEDG.js +555 -0
- package/dist/chunk-6DOUKEDG.js.map +1 -0
- package/dist/chunk-IZ4Y4UBN.js +279 -0
- package/dist/chunk-IZ4Y4UBN.js.map +1 -0
- package/dist/chunk-JHZ4UBA2.js +57 -0
- package/dist/chunk-JHZ4UBA2.js.map +1 -0
- package/dist/chunk-LVUU4ZBR.js +65 -0
- package/dist/chunk-LVUU4ZBR.js.map +1 -0
- package/dist/chunk-RKT3VKU2.js +94 -0
- package/dist/chunk-RKT3VKU2.js.map +1 -0
- package/dist/chunk-RTJ73SCX.js +45 -0
- package/dist/chunk-RTJ73SCX.js.map +1 -0
- package/dist/chunk-WJCN2EO3.js +47 -0
- package/dist/chunk-WJCN2EO3.js.map +1 -0
- package/dist/csp/index.d.ts +38 -0
- package/dist/csp/index.js +11 -0
- package/dist/csp/index.js.map +1 -0
- package/dist/errors-a5iG09pc.d.ts +42 -0
- package/dist/i18n/index.d.ts +23 -0
- package/dist/i18n/index.js +9 -0
- package/dist/i18n/index.js.map +1 -0
- package/dist/index.d.ts +54 -0
- package/dist/index.js +108 -0
- package/dist/index.js.map +1 -0
- package/dist/seo/index.d.ts +59 -0
- package/dist/seo/index.js +11 -0
- package/dist/seo/index.js.map +1 -0
- package/dist/session/index.d.ts +17 -0
- package/dist/session/index.js +7 -0
- package/dist/session/index.js.map +1 -0
- package/dist/storefront/index.d.ts +10 -0
- package/dist/storefront/index.js +14 -0
- package/dist/storefront/index.js.map +1 -0
- package/dist/types-BIsRLMWU.d.ts +152 -0
- package/dist/types-CaRAihQJ.d.ts +9 -0
- package/package.json +47 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
|
|
4
|
+
declare const AnalyticsEvent: {
|
|
5
|
+
readonly PAGE_VIEW: "page_view";
|
|
6
|
+
readonly PRODUCT_VIEW: "product_view";
|
|
7
|
+
readonly COLLECTION_VIEW: "collection_view";
|
|
8
|
+
readonly SEARCH_VIEW: "search_view";
|
|
9
|
+
readonly CART_VIEW: "cart_view";
|
|
10
|
+
readonly CART_UPDATED: "cart_updated";
|
|
11
|
+
readonly ADD_TO_CART: "add_to_cart";
|
|
12
|
+
readonly REMOVE_FROM_CART: "remove_from_cart";
|
|
13
|
+
};
|
|
14
|
+
type AnalyticsEventName = (typeof AnalyticsEvent)[keyof typeof AnalyticsEvent];
|
|
15
|
+
interface AnalyticsPayload {
|
|
16
|
+
event: AnalyticsEventName;
|
|
17
|
+
data?: Record<string, unknown>;
|
|
18
|
+
timestamp?: number;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
type AnalyticsSubscriber = (payload: AnalyticsPayload) => void;
|
|
22
|
+
/**
|
|
23
|
+
* Hook for publishing analytics events from components.
|
|
24
|
+
*/
|
|
25
|
+
declare function useAnalytics(): {
|
|
26
|
+
publish: (event: AnalyticsEventName, data?: Record<string, unknown>) => void;
|
|
27
|
+
subscribe: (fn: AnalyticsSubscriber) => () => void;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
interface AnalyticsContextValue {
|
|
31
|
+
publish: (event: AnalyticsEventName, data?: Record<string, unknown>) => void;
|
|
32
|
+
subscribe: (fn: AnalyticsSubscriber) => () => void;
|
|
33
|
+
}
|
|
34
|
+
declare function AnalyticsProvider({ children }: {
|
|
35
|
+
children: ReactNode;
|
|
36
|
+
}): react_jsx_runtime.JSX.Element;
|
|
37
|
+
declare function useAnalyticsContext(): AnalyticsContextValue;
|
|
38
|
+
|
|
39
|
+
export { AnalyticsEvent, type AnalyticsEventName, type AnalyticsPayload, AnalyticsProvider, type AnalyticsSubscriber, useAnalytics, useAnalyticsContext };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { C as CacheStrategy } from '../types-CaRAihQJ.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Short-lived cache: 1 second fresh, 9 seconds stale-while-revalidate.
|
|
5
|
+
* Use for frequently changing data (pricing, availability).
|
|
6
|
+
*/
|
|
7
|
+
declare function CacheShort(): CacheStrategy;
|
|
8
|
+
/**
|
|
9
|
+
* Long-lived cache: 1 hour fresh, 23 hours stale-while-revalidate.
|
|
10
|
+
* Use for stable data (product descriptions, collection titles).
|
|
11
|
+
*/
|
|
12
|
+
declare function CacheLong(): CacheStrategy;
|
|
13
|
+
/**
|
|
14
|
+
* No caching. Use for customer-specific or sensitive data.
|
|
15
|
+
*/
|
|
16
|
+
declare function CacheNone(): CacheStrategy;
|
|
17
|
+
/**
|
|
18
|
+
* Custom cache strategy with user-defined values.
|
|
19
|
+
*/
|
|
20
|
+
declare function CacheCustom(options: Partial<CacheStrategy>): CacheStrategy;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Generates a Cache-Control header string from a CacheStrategy.
|
|
24
|
+
*/
|
|
25
|
+
declare function generateCacheControlHeader(strategy: CacheStrategy): string;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Simple in-memory cache for development.
|
|
29
|
+
* In production, use the Web Cache API or a platform-specific cache.
|
|
30
|
+
*/
|
|
31
|
+
declare class InMemoryCache {
|
|
32
|
+
#private;
|
|
33
|
+
get<T>(key: string): Promise<T | undefined>;
|
|
34
|
+
set(key: string, value: unknown, strategy: CacheStrategy): Promise<void>;
|
|
35
|
+
delete(key: string): Promise<void>;
|
|
36
|
+
clear(): Promise<void>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { CacheCustom, CacheLong, CacheNone, CacheShort, CacheStrategy, InMemoryCache, generateCacheControlHeader };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {
|
|
2
|
+
generateCacheControlHeader
|
|
3
|
+
} from "../chunk-3YTOR4GE.js";
|
|
4
|
+
import {
|
|
5
|
+
CacheCustom,
|
|
6
|
+
CacheLong,
|
|
7
|
+
CacheNone,
|
|
8
|
+
CacheShort,
|
|
9
|
+
InMemoryCache
|
|
10
|
+
} from "../chunk-JHZ4UBA2.js";
|
|
11
|
+
export {
|
|
12
|
+
CacheCustom,
|
|
13
|
+
CacheLong,
|
|
14
|
+
CacheNone,
|
|
15
|
+
CacheShort,
|
|
16
|
+
InMemoryCache,
|
|
17
|
+
generateCacheControlHeader
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { c as Money, I as Image, S as StorefrontClient } from '../types-BIsRLMWU.js';
|
|
2
|
+
import '../types-CaRAihQJ.js';
|
|
3
|
+
|
|
4
|
+
interface CartLine {
|
|
5
|
+
id: string;
|
|
6
|
+
quantity: number;
|
|
7
|
+
merchandise: {
|
|
8
|
+
id: string;
|
|
9
|
+
title: string;
|
|
10
|
+
product: {
|
|
11
|
+
title: string;
|
|
12
|
+
handle: string;
|
|
13
|
+
};
|
|
14
|
+
price: Money;
|
|
15
|
+
image: Image | null;
|
|
16
|
+
selectedOptions: {
|
|
17
|
+
name: string;
|
|
18
|
+
value: string;
|
|
19
|
+
}[];
|
|
20
|
+
};
|
|
21
|
+
cost: {
|
|
22
|
+
totalAmount: Money;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
interface CartData {
|
|
26
|
+
id: string;
|
|
27
|
+
totalQuantity: number;
|
|
28
|
+
lines: {
|
|
29
|
+
nodes: CartLine[];
|
|
30
|
+
};
|
|
31
|
+
cost: {
|
|
32
|
+
subtotalAmount: Money;
|
|
33
|
+
totalAmount: Money;
|
|
34
|
+
};
|
|
35
|
+
discountCodes: {
|
|
36
|
+
code: string;
|
|
37
|
+
}[];
|
|
38
|
+
}
|
|
39
|
+
interface BuyerIdentityInput {
|
|
40
|
+
email?: string;
|
|
41
|
+
phone?: string;
|
|
42
|
+
countryCode?: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
interface CartHandlerConfig {
|
|
46
|
+
getCartId: () => string | undefined;
|
|
47
|
+
setCartId: (cartId: string) => void;
|
|
48
|
+
}
|
|
49
|
+
interface CartHandler {
|
|
50
|
+
get(): Promise<CartData>;
|
|
51
|
+
addLines(lines: {
|
|
52
|
+
merchandiseId: string;
|
|
53
|
+
quantity: number;
|
|
54
|
+
}[]): Promise<CartData>;
|
|
55
|
+
updateLines(lines: {
|
|
56
|
+
id: string;
|
|
57
|
+
quantity: number;
|
|
58
|
+
}[]): Promise<CartData>;
|
|
59
|
+
removeLines(lineIds: string[]): Promise<CartData>;
|
|
60
|
+
updateDiscountCodes(codes: string[]): Promise<CartData>;
|
|
61
|
+
updateBuyerIdentity(buyerIdentity: BuyerIdentityInput): Promise<CartData>;
|
|
62
|
+
updateNote(note: string): Promise<CartData>;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
declare function createCartHandler(storefront: StorefrontClient, config: CartHandlerConfig): CartHandler;
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Mock cart handler for development — in-memory cart.
|
|
69
|
+
*/
|
|
70
|
+
|
|
71
|
+
declare function createMockCartHandler(): CartHandler;
|
|
72
|
+
|
|
73
|
+
export { type BuyerIdentityInput, type CartData, type CartHandler, type CartHandlerConfig, type CartLine, createCartHandler, createMockCartHandler };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// src/i18n/locale.ts
|
|
2
|
+
function getLocaleFromRequest(request, config) {
|
|
3
|
+
const url = new URL(request.url);
|
|
4
|
+
if (config.strategy === "url-path") {
|
|
5
|
+
const pathSegments = url.pathname.split("/").filter(Boolean);
|
|
6
|
+
const prefix = pathSegments[0];
|
|
7
|
+
if (prefix) {
|
|
8
|
+
const match = config.locales.find(
|
|
9
|
+
(l) => l.pathPrefix === prefix || l.language.toLowerCase() === prefix.toLowerCase()
|
|
10
|
+
);
|
|
11
|
+
if (match) return match;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
if (config.strategy === "domain" || config.strategy === "subdomain") {
|
|
15
|
+
const hostname = url.hostname;
|
|
16
|
+
const match = config.locales.find(
|
|
17
|
+
(l) => l.pathPrefix && hostname.includes(l.pathPrefix)
|
|
18
|
+
);
|
|
19
|
+
if (match) return match;
|
|
20
|
+
}
|
|
21
|
+
if (config.strategy === "cookie") {
|
|
22
|
+
const cookieHeader = request.headers.get("Cookie") ?? "";
|
|
23
|
+
const match = cookieHeader.match(/locale=([^;]+)/);
|
|
24
|
+
if (match) {
|
|
25
|
+
const [lang, country] = match[1].split("-");
|
|
26
|
+
const found = config.locales.find(
|
|
27
|
+
(l) => l.language.toLowerCase() === lang?.toLowerCase() && l.country.toLowerCase() === country?.toLowerCase()
|
|
28
|
+
);
|
|
29
|
+
if (found) return found;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return config.defaultLocale;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// src/i18n/directive.ts
|
|
36
|
+
function injectI18nVariables(query, variables, locale) {
|
|
37
|
+
const result = { ...variables };
|
|
38
|
+
if (query.includes("$country") && !("country" in result)) {
|
|
39
|
+
result.country = locale.country;
|
|
40
|
+
}
|
|
41
|
+
if (query.includes("$language") && !("language" in result)) {
|
|
42
|
+
result.language = locale.language;
|
|
43
|
+
}
|
|
44
|
+
return result;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export {
|
|
48
|
+
getLocaleFromRequest,
|
|
49
|
+
injectI18nVariables
|
|
50
|
+
};
|
|
51
|
+
//# sourceMappingURL=chunk-2VLIYNGM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/i18n/locale.ts","../src/i18n/directive.ts"],"sourcesContent":["import type {Locale, I18nConfig} from './types.js';\n\n/**\n * Detects the locale from the request URL based on the i18n strategy.\n */\nexport function getLocaleFromRequest(request: Request, config: I18nConfig): Locale {\n const url = new URL(request.url);\n\n if (config.strategy === 'url-path') {\n const pathSegments = url.pathname.split('/').filter(Boolean);\n const prefix = pathSegments[0];\n\n if (prefix) {\n const match = config.locales.find(\n (l) => l.pathPrefix === prefix || l.language.toLowerCase() === prefix.toLowerCase(),\n );\n if (match) return match;\n }\n }\n\n if (config.strategy === 'domain' || config.strategy === 'subdomain') {\n const hostname = url.hostname;\n const match = config.locales.find(\n (l) => l.pathPrefix && hostname.includes(l.pathPrefix),\n );\n if (match) return match;\n }\n\n if (config.strategy === 'cookie') {\n const cookieHeader = request.headers.get('Cookie') ?? '';\n const match = cookieHeader.match(/locale=([^;]+)/);\n if (match) {\n const [lang, country] = match[1].split('-');\n const found = config.locales.find(\n (l) => l.language.toLowerCase() === lang?.toLowerCase() && l.country.toLowerCase() === country?.toLowerCase(),\n );\n if (found) return found;\n }\n }\n\n return config.defaultLocale;\n}\n","import type {Locale} from './types.js';\n\n/**\n * Injects i18n variables ($country, $language) into a GraphQL variables object\n * when the query references them via @inContext directive.\n */\nexport function injectI18nVariables(\n query: string,\n variables: Record<string, unknown>,\n locale: Locale,\n): Record<string, unknown> {\n const result = {...variables};\n\n if (query.includes('$country') && !('country' in result)) {\n result.country = locale.country;\n }\n\n if (query.includes('$language') && !('language' in result)) {\n result.language = locale.language;\n }\n\n return result;\n}\n"],"mappings":";AAKO,SAAS,qBAAqB,SAAkB,QAA4B;AACjF,QAAM,MAAM,IAAI,IAAI,QAAQ,GAAG;AAE/B,MAAI,OAAO,aAAa,YAAY;AAClC,UAAM,eAAe,IAAI,SAAS,MAAM,GAAG,EAAE,OAAO,OAAO;AAC3D,UAAM,SAAS,aAAa,CAAC;AAE7B,QAAI,QAAQ;AACV,YAAM,QAAQ,OAAO,QAAQ;AAAA,QAC3B,CAAC,MAAM,EAAE,eAAe,UAAU,EAAE,SAAS,YAAY,MAAM,OAAO,YAAY;AAAA,MACpF;AACA,UAAI,MAAO,QAAO;AAAA,IACpB;AAAA,EACF;AAEA,MAAI,OAAO,aAAa,YAAY,OAAO,aAAa,aAAa;AACnE,UAAM,WAAW,IAAI;AACrB,UAAM,QAAQ,OAAO,QAAQ;AAAA,MAC3B,CAAC,MAAM,EAAE,cAAc,SAAS,SAAS,EAAE,UAAU;AAAA,IACvD;AACA,QAAI,MAAO,QAAO;AAAA,EACpB;AAEA,MAAI,OAAO,aAAa,UAAU;AAChC,UAAM,eAAe,QAAQ,QAAQ,IAAI,QAAQ,KAAK;AACtD,UAAM,QAAQ,aAAa,MAAM,gBAAgB;AACjD,QAAI,OAAO;AACT,YAAM,CAAC,MAAM,OAAO,IAAI,MAAM,CAAC,EAAE,MAAM,GAAG;AAC1C,YAAM,QAAQ,OAAO,QAAQ;AAAA,QAC3B,CAAC,MAAM,EAAE,SAAS,YAAY,MAAM,MAAM,YAAY,KAAK,EAAE,QAAQ,YAAY,MAAM,SAAS,YAAY;AAAA,MAC9G;AACA,UAAI,MAAO,QAAO;AAAA,IACpB;AAAA,EACF;AAEA,SAAO,OAAO;AAChB;;;ACnCO,SAAS,oBACd,OACA,WACA,QACyB;AACzB,QAAM,SAAS,EAAC,GAAG,UAAS;AAE5B,MAAI,MAAM,SAAS,UAAU,KAAK,EAAE,aAAa,SAAS;AACxD,WAAO,UAAU,OAAO;AAAA,EAC1B;AAEA,MAAI,MAAM,SAAS,WAAW,KAAK,EAAE,cAAc,SAAS;AAC1D,WAAO,WAAW,OAAO;AAAA,EAC3B;AAEA,SAAO;AACT;","names":[]}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// src/cache/headers.ts
|
|
2
|
+
function generateCacheControlHeader(strategy) {
|
|
3
|
+
if (strategy.mode === "no-store") {
|
|
4
|
+
return "no-store";
|
|
5
|
+
}
|
|
6
|
+
const parts = [strategy.mode];
|
|
7
|
+
if (strategy.maxAge >= 0) {
|
|
8
|
+
parts.push(`max-age=${strategy.maxAge}`);
|
|
9
|
+
}
|
|
10
|
+
if (strategy.staleWhileRevalidate > 0) {
|
|
11
|
+
parts.push(`stale-while-revalidate=${strategy.staleWhileRevalidate}`);
|
|
12
|
+
}
|
|
13
|
+
if (strategy.sMaxAge != null && strategy.sMaxAge >= 0) {
|
|
14
|
+
parts.push(`s-maxage=${strategy.sMaxAge}`);
|
|
15
|
+
}
|
|
16
|
+
if (strategy.staleIfError != null && strategy.staleIfError > 0) {
|
|
17
|
+
parts.push(`stale-if-error=${strategy.staleIfError}`);
|
|
18
|
+
}
|
|
19
|
+
return parts.join(", ");
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export {
|
|
23
|
+
generateCacheControlHeader
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=chunk-3YTOR4GE.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/cache/headers.ts"],"sourcesContent":["import type {CacheStrategy} from './types.js';\n\n/**\n * Generates a Cache-Control header string from a CacheStrategy.\n */\nexport function generateCacheControlHeader(strategy: CacheStrategy): string {\n if (strategy.mode === 'no-store') {\n return 'no-store';\n }\n\n const parts: string[] = [strategy.mode];\n\n if (strategy.maxAge >= 0) {\n parts.push(`max-age=${strategy.maxAge}`);\n }\n\n if (strategy.staleWhileRevalidate > 0) {\n parts.push(`stale-while-revalidate=${strategy.staleWhileRevalidate}`);\n }\n\n if (strategy.sMaxAge != null && strategy.sMaxAge >= 0) {\n parts.push(`s-maxage=${strategy.sMaxAge}`);\n }\n\n if (strategy.staleIfError != null && strategy.staleIfError > 0) {\n parts.push(`stale-if-error=${strategy.staleIfError}`);\n }\n\n return parts.join(', ');\n}\n"],"mappings":";AAKO,SAAS,2BAA2B,UAAiC;AAC1E,MAAI,SAAS,SAAS,YAAY;AAChC,WAAO;AAAA,EACT;AAEA,QAAM,QAAkB,CAAC,SAAS,IAAI;AAEtC,MAAI,SAAS,UAAU,GAAG;AACxB,UAAM,KAAK,WAAW,SAAS,MAAM,EAAE;AAAA,EACzC;AAEA,MAAI,SAAS,uBAAuB,GAAG;AACrC,UAAM,KAAK,0BAA0B,SAAS,oBAAoB,EAAE;AAAA,EACtE;AAEA,MAAI,SAAS,WAAW,QAAQ,SAAS,WAAW,GAAG;AACrD,UAAM,KAAK,YAAY,SAAS,OAAO,EAAE;AAAA,EAC3C;AAEA,MAAI,SAAS,gBAAgB,QAAQ,SAAS,eAAe,GAAG;AAC9D,UAAM,KAAK,kBAAkB,SAAS,YAAY,EAAE;AAAA,EACtD;AAEA,SAAO,MAAM,KAAK,IAAI;AACxB;","names":[]}
|