@growth-labs/store 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/README.md +41 -0
- package/dist/api.d.ts +30 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +126 -0
- package/dist/api.js.map +1 -0
- package/dist/availability.d.ts +30 -0
- package/dist/availability.d.ts.map +1 -0
- package/dist/availability.js +47 -0
- package/dist/availability.js.map +1 -0
- package/dist/cache.d.ts +34 -0
- package/dist/cache.d.ts.map +1 -0
- package/dist/cache.js +80 -0
- package/dist/cache.js.map +1 -0
- package/dist/cart-client.d.ts +54 -0
- package/dist/cart-client.d.ts.map +1 -0
- package/dist/cart-client.js +347 -0
- package/dist/cart-client.js.map +1 -0
- package/dist/checkout-client.d.ts +20 -0
- package/dist/checkout-client.d.ts.map +1 -0
- package/dist/checkout-client.js +33 -0
- package/dist/checkout-client.js.map +1 -0
- package/dist/checkout-url.d.ts +25 -0
- package/dist/checkout-url.d.ts.map +1 -0
- package/dist/checkout-url.js +36 -0
- package/dist/checkout-url.js.map +1 -0
- package/dist/client.d.ts +459 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +139 -0
- package/dist/client.js.map +1 -0
- package/dist/collections.d.ts +27 -0
- package/dist/collections.d.ts.map +1 -0
- package/dist/collections.js +24 -0
- package/dist/collections.js.map +1 -0
- package/dist/health.d.ts +17 -0
- package/dist/health.d.ts.map +1 -0
- package/dist/health.js +38 -0
- package/dist/health.js.map +1 -0
- package/dist/image.d.ts +25 -0
- package/dist/image.d.ts.map +1 -0
- package/dist/image.js +43 -0
- package/dist/image.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +48 -0
- package/dist/index.js.map +1 -0
- package/dist/options.d.ts +174 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/options.js +59 -0
- package/dist/options.js.map +1 -0
- package/dist/product-card-variant.d.ts +13 -0
- package/dist/product-card-variant.d.ts.map +1 -0
- package/dist/product-card-variant.js +33 -0
- package/dist/product-card-variant.js.map +1 -0
- package/dist/routes/cart-bootstrap.d.ts +3 -0
- package/dist/routes/cart-bootstrap.d.ts.map +1 -0
- package/dist/routes/cart-bootstrap.js +5 -0
- package/dist/routes/cart-bootstrap.js.map +1 -0
- package/dist/routes/checkout.d.ts +4 -0
- package/dist/routes/checkout.d.ts.map +1 -0
- package/dist/routes/checkout.js +14 -0
- package/dist/routes/checkout.js.map +1 -0
- package/dist/routes/webhook.d.ts +4 -0
- package/dist/routes/webhook.d.ts.map +1 -0
- package/dist/routes/webhook.js +12 -0
- package/dist/routes/webhook.js.map +1 -0
- package/dist/state.d.ts +5 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +14 -0
- package/dist/state.js.map +1 -0
- package/dist/types.d.ts +5111 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +167 -0
- package/dist/types.js.map +1 -0
- package/dist/variant.d.ts +59 -0
- package/dist/variant.d.ts.map +1 -0
- package/dist/variant.js +81 -0
- package/dist/variant.js.map +1 -0
- package/dist/vite-plugin.d.ts +4 -0
- package/dist/vite-plugin.d.ts.map +1 -0
- package/dist/vite-plugin.js +24 -0
- package/dist/vite-plugin.js.map +1 -0
- package/package.json +59 -0
- package/src/analytics-window.d.ts +15 -0
- package/src/api.ts +184 -0
- package/src/availability.ts +65 -0
- package/src/cache.ts +118 -0
- package/src/cart-client.ts +423 -0
- package/src/checkout-client.ts +49 -0
- package/src/checkout-url.ts +52 -0
- package/src/client.ts +216 -0
- package/src/cloudflare-workers.d.ts +3 -0
- package/src/collections.ts +63 -0
- package/src/components/AddToCartButton.astro +146 -0
- package/src/components/CartDrawer.astro +276 -0
- package/src/components/CartIcon.astro +96 -0
- package/src/components/CollectionCard.astro +81 -0
- package/src/components/CurrencySelector.astro +73 -0
- package/src/components/Price.astro +34 -0
- package/src/components/ProductCard.astro +225 -0
- package/src/components/StoreCartPage.astro +219 -0
- package/src/components/StoreCollectionPage.astro +166 -0
- package/src/components/StoreIndexPage.astro +193 -0
- package/src/components/StoreProductPage.astro +296 -0
- package/src/components/VariantPicker.astro +190 -0
- package/src/health.ts +54 -0
- package/src/image.ts +58 -0
- package/src/index.ts +75 -0
- package/src/options.ts +74 -0
- package/src/product-card-variant.ts +47 -0
- package/src/routes/cart-bootstrap.ts +6 -0
- package/src/routes/checkout.ts +16 -0
- package/src/routes/webhook.ts +14 -0
- package/src/state.ts +20 -0
- package/src/types.ts +196 -0
- package/src/variant.ts +119 -0
- package/src/virtual.d.ts +6 -0
- package/src/vite-plugin.ts +27 -0
package/dist/health.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Structurally matches `@growth-labs/health`'s `CustomCheck` without
|
|
3
|
+
* importing that package — packages don't import one another directly.
|
|
4
|
+
* Wire it in the consuming site's `astro.config.mjs`:
|
|
5
|
+
*
|
|
6
|
+
* health({ checks: [createStoreHealthCheck()] })
|
|
7
|
+
*/
|
|
8
|
+
export interface StoreHealthCheckResult {
|
|
9
|
+
ok: boolean;
|
|
10
|
+
ms: number;
|
|
11
|
+
error?: string;
|
|
12
|
+
}
|
|
13
|
+
export declare function createStoreHealthCheck(): {
|
|
14
|
+
name: string;
|
|
15
|
+
check: () => Promise<StoreHealthCheckResult>;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=health.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../src/health.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,WAAW,sBAAsB;IACtC,EAAE,EAAE,OAAO,CAAA;IACX,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,CAAC,EAAE,MAAM,CAAA;CACd;AAmBD,wBAAgB,sBAAsB,IAAI;IACzC,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,MAAM,OAAO,CAAC,sBAAsB,CAAC,CAAA;CAC5C,CAkBA"}
|
package/dist/health.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { isWebhookConfigured } from './api.js';
|
|
2
|
+
/**
|
|
3
|
+
* Resolves `cloudflare:workers` via a dynamic import wrapped in try/catch,
|
|
4
|
+
* keeping the specifier off this module's static import graph — this file
|
|
5
|
+
* is re-exported from the package's main entry, and Node's default ESM
|
|
6
|
+
* loader rejects the `cloudflare:` scheme outright (it isn't a matter of
|
|
7
|
+
* the module being unresolvable at runtime, the loader refuses the scheme
|
|
8
|
+
* before resolution even starts). See scripts/verify-pure-node-import.mjs.
|
|
9
|
+
*/
|
|
10
|
+
async function resolveCloudflareEnv() {
|
|
11
|
+
try {
|
|
12
|
+
const mod = (await import('cloudflare:workers'));
|
|
13
|
+
return mod?.env ?? null;
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function createStoreHealthCheck() {
|
|
20
|
+
return {
|
|
21
|
+
name: 'store',
|
|
22
|
+
async check() {
|
|
23
|
+
const start = Date.now();
|
|
24
|
+
const env = await resolveCloudflareEnv();
|
|
25
|
+
const configured = isWebhookConfigured(env);
|
|
26
|
+
return {
|
|
27
|
+
ok: configured,
|
|
28
|
+
ms: Date.now() - start,
|
|
29
|
+
...(configured
|
|
30
|
+
? {}
|
|
31
|
+
: {
|
|
32
|
+
error: 'FW_WEBHOOK_SECRET is not set — order telemetry is silently dropping orders',
|
|
33
|
+
}),
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=health.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.js","sourceRoot":"","sources":["../src/health.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAe9C;;;;;;;GAOG;AACH,KAAK,UAAU,oBAAoB;IAClC,IAAI,CAAC;QACJ,MAAM,GAAG,GAAG,CAAC,MAAM,MAAM,CAAC,oBAAoB,CAAC,CAAsC,CAAA;QACrF,OAAQ,GAAG,EAAE,GAAkD,IAAI,IAAI,CAAA;IACxE,CAAC;IAAC,MAAM,CAAC;QACR,OAAO,IAAI,CAAA;IACZ,CAAC;AACF,CAAC;AAED,MAAM,UAAU,sBAAsB;IAIrC,OAAO;QACN,IAAI,EAAE,OAAO;QACb,KAAK,CAAC,KAAK;YACV,MAAM,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAA;YACxB,MAAM,GAAG,GAAG,MAAM,oBAAoB,EAAE,CAAA;YACxC,MAAM,UAAU,GAAG,mBAAmB,CAAC,GAAG,CAAC,CAAA;YAC3C,OAAO;gBACN,EAAE,EAAE,UAAU;gBACd,EAAE,EAAE,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK;gBACtB,GAAG,CAAC,UAAU;oBACb,CAAC,CAAC,EAAE;oBACJ,CAAC,CAAC;wBACA,KAAK,EAAE,4EAA4E;qBACnF,CAAC;aACJ,CAAA;QACF,CAAC;KACD,CAAA;AACF,CAAC"}
|
package/dist/image.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Route a remote image URL through Cloudflare Image Resizing.
|
|
3
|
+
*
|
|
4
|
+
* Uses the zone-local `/cdn-cgi/image/...` transform endpoint. Works on any
|
|
5
|
+
* custom domain whose zone has "Any origin" image resizing enabled. It does
|
|
6
|
+
* NOT work on the workers.dev subdomain, so non-matching URLs pass through
|
|
7
|
+
* unmodified.
|
|
8
|
+
*
|
|
9
|
+
* Opt-in via `imageTransform` on `StoreOptions`. Until a custom domain with
|
|
10
|
+
* Image Resizing is wired up, this stays off and raw CDN URLs ship as-is.
|
|
11
|
+
*
|
|
12
|
+
* `format=auto` picks AVIF/WebP/JPEG based on the request's `Accept` header.
|
|
13
|
+
*/
|
|
14
|
+
import type { FwProduct } from './types.js';
|
|
15
|
+
export interface OptimizeFwImageOpts {
|
|
16
|
+
width: number;
|
|
17
|
+
height?: number;
|
|
18
|
+
quality?: number;
|
|
19
|
+
fit?: 'cover' | 'contain' | 'scale-down' | 'crop' | 'pad';
|
|
20
|
+
/** From `StoreOptions.imageTransform`. Defaults to disabled. */
|
|
21
|
+
enabled?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export declare function hasProductImages(product: Pick<FwProduct, 'images' | 'variants'>): boolean;
|
|
24
|
+
export declare function optimizeFwImage(url: string | null | undefined, opts: OptimizeFwImageOpts): string | null;
|
|
25
|
+
//# sourceMappingURL=image.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../src/image.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAE3C,MAAM,WAAW,mBAAmB;IACnC,KAAK,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,GAAG,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,YAAY,GAAG,MAAM,GAAG,KAAK,CAAA;IACzD,gEAAgE;IAChE,OAAO,CAAC,EAAE,OAAO,CAAA;CACjB;AAID,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,SAAS,EAAE,QAAQ,GAAG,UAAU,CAAC,GAAG,OAAO,CAKzF;AAED,wBAAgB,eAAe,CAC9B,GAAG,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAC9B,IAAI,EAAE,mBAAmB,GACvB,MAAM,GAAG,IAAI,CAoBf"}
|
package/dist/image.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Route a remote image URL through Cloudflare Image Resizing.
|
|
3
|
+
*
|
|
4
|
+
* Uses the zone-local `/cdn-cgi/image/...` transform endpoint. Works on any
|
|
5
|
+
* custom domain whose zone has "Any origin" image resizing enabled. It does
|
|
6
|
+
* NOT work on the workers.dev subdomain, so non-matching URLs pass through
|
|
7
|
+
* unmodified.
|
|
8
|
+
*
|
|
9
|
+
* Opt-in via `imageTransform` on `StoreOptions`. Until a custom domain with
|
|
10
|
+
* Image Resizing is wired up, this stays off and raw CDN URLs ship as-is.
|
|
11
|
+
*
|
|
12
|
+
* `format=auto` picks AVIF/WebP/JPEG based on the request's `Accept` header.
|
|
13
|
+
*/
|
|
14
|
+
const TRANSFORMABLE_HOSTS = ['cdn.fourthwall.com', 'storage.googleapis.com'];
|
|
15
|
+
export function hasProductImages(product) {
|
|
16
|
+
return (product.images.some((image) => Boolean(image.url.trim())) ||
|
|
17
|
+
product.variants.some((variant) => variant.images?.some((image) => Boolean(image.url.trim()))));
|
|
18
|
+
}
|
|
19
|
+
export function optimizeFwImage(url, opts) {
|
|
20
|
+
if (!url)
|
|
21
|
+
return null;
|
|
22
|
+
if (!opts.enabled)
|
|
23
|
+
return url;
|
|
24
|
+
try {
|
|
25
|
+
const parsed = new URL(url);
|
|
26
|
+
if (!TRANSFORMABLE_HOSTS.some((h) => parsed.host.endsWith(h))) {
|
|
27
|
+
return url;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
catch {
|
|
31
|
+
return url;
|
|
32
|
+
}
|
|
33
|
+
const params = [
|
|
34
|
+
`width=${opts.width}`,
|
|
35
|
+
`quality=${opts.quality ?? 82}`,
|
|
36
|
+
`fit=${opts.fit ?? 'cover'}`,
|
|
37
|
+
'format=auto',
|
|
38
|
+
];
|
|
39
|
+
if (opts.height)
|
|
40
|
+
params.push(`height=${opts.height}`);
|
|
41
|
+
return `/cdn-cgi/image/${params.join(',')}/${url}`;
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=image.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image.js","sourceRoot":"","sources":["../src/image.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;G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,EAAE,CAAC,CAAA;IACrD,OAAO,kBAAkB,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,EAAE,CAAA;AACnD,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AstroIntegration } from 'astro';
|
|
2
|
+
import { type StoreOptions } from './options.js';
|
|
3
|
+
export default function store(userOptions: StoreOptions): AstroIntegration;
|
|
4
|
+
export type { CheckoutEnv, OrderPlacedHandler, WebhookEnv } from './api.js';
|
|
5
|
+
export { FOURTHWALL_SIGNATURE_HEADER, isWebhookConfigured, setOrderPlacedHandler } from './api.js';
|
|
6
|
+
export type { FourthwallAvailability, FourthwallAvailabilityStatus } from './availability.js';
|
|
7
|
+
export { resolveFourthwallAvailability } from './availability.js';
|
|
8
|
+
export { buildCacheKey, cachedJson, purgeCollectionCache, purgeProductCache } from './cache.js';
|
|
9
|
+
export { buildCheckoutUrl } from './checkout-url.js';
|
|
10
|
+
export type { FourthwallClient, FourthwallClientConfig } from './client.js';
|
|
11
|
+
export { createFourthwallClient } from './client.js';
|
|
12
|
+
export type { StoreCollection, StoreCollectionGrouping } from './collections.js';
|
|
13
|
+
export { filterPublishedCollections, getGroupedCollections, getStoreCollection, resolveProductKind, } from './collections.js';
|
|
14
|
+
export { createStoreHealthCheck } from './health.js';
|
|
15
|
+
export { hasProductImages, optimizeFwImage } from './image.js';
|
|
16
|
+
export type { ResolvedStoreOptions, StoreOptions } from './options.js';
|
|
17
|
+
export { storeOptionsSchema } from './options.js';
|
|
18
|
+
export type * from './types.js';
|
|
19
|
+
export type { MerchantReturnPolicy, StoreVariantClientData } from './variant.js';
|
|
20
|
+
export { buildStoreProductJsonLd, buildStoreVariantClientData, createStoreAddToCartAvailabilityState, isStoreVariantAvailable, normalizeStoreVariantSku, selectStoreVariant, } from './variant.js';
|
|
21
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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sBAAsB,EAAE,MAAM,cAAc,CAAA;AAChF,OAAO,EACN,uBAAuB,EACvB,2BAA2B,EAC3B,qCAAqC,EACrC,uBAAuB,EACvB,wBAAwB,EACxB,kBAAkB,GAClB,MAAM,cAAc,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url';
|
|
2
|
+
import { storeOptionsSchema } from './options.js';
|
|
3
|
+
import { _setConfig } from './state.js';
|
|
4
|
+
import { growthLabsStorePlugin } from './vite-plugin.js';
|
|
5
|
+
function isSourceEntrypoint() {
|
|
6
|
+
return typeof import.meta.url === 'string' && import.meta.url.endsWith('.ts');
|
|
7
|
+
}
|
|
8
|
+
const ENTRYPOINT_EXTENSION = isSourceEntrypoint() ? '.ts' : '.js';
|
|
9
|
+
function resolveEntrypoint(path) {
|
|
10
|
+
return fileURLToPath(new URL(`${path}${ENTRYPOINT_EXTENSION}`, import.meta.url));
|
|
11
|
+
}
|
|
12
|
+
export default function store(userOptions) {
|
|
13
|
+
const options = storeOptionsSchema.parse(userOptions);
|
|
14
|
+
_setConfig(options);
|
|
15
|
+
return {
|
|
16
|
+
name: '@growth-labs/store',
|
|
17
|
+
hooks: {
|
|
18
|
+
'astro:config:setup': ({ injectRoute, updateConfig }) => {
|
|
19
|
+
updateConfig({
|
|
20
|
+
vite: { plugins: [growthLabsStorePlugin(options)] },
|
|
21
|
+
});
|
|
22
|
+
injectRoute({
|
|
23
|
+
pattern: options.routes.checkoutPath,
|
|
24
|
+
entrypoint: resolveEntrypoint('./routes/checkout'),
|
|
25
|
+
});
|
|
26
|
+
injectRoute({
|
|
27
|
+
pattern: options.routes.webhookPath,
|
|
28
|
+
entrypoint: resolveEntrypoint('./routes/webhook'),
|
|
29
|
+
});
|
|
30
|
+
injectRoute({
|
|
31
|
+
pattern: options.routes.cartBootstrapPath,
|
|
32
|
+
entrypoint: resolveEntrypoint('./routes/cart-bootstrap'),
|
|
33
|
+
});
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
export { FOURTHWALL_SIGNATURE_HEADER, isWebhookConfigured, setOrderPlacedHandler } from './api.js';
|
|
39
|
+
export { resolveFourthwallAvailability } from './availability.js';
|
|
40
|
+
export { buildCacheKey, cachedJson, purgeCollectionCache, purgeProductCache } from './cache.js';
|
|
41
|
+
export { buildCheckoutUrl } from './checkout-url.js';
|
|
42
|
+
export { createFourthwallClient } from './client.js';
|
|
43
|
+
export { filterPublishedCollections, getGroupedCollections, getStoreCollection, resolveProductKind, } from './collections.js';
|
|
44
|
+
export { createStoreHealthCheck } from './health.js';
|
|
45
|
+
export { hasProductImages, optimizeFwImage } from './image.js';
|
|
46
|
+
export { storeOptionsSchema } from './options.js';
|
|
47
|
+
export { buildStoreProductJsonLd, buildStoreVariantClientData, createStoreAddToCartAvailabilityState, isStoreVariantAvailable, normalizeStoreVariantSku, selectStoreVariant, } from './variant.js';
|
|
48
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAExC,OAAO,EAAqB,kBAAkB,EAAE,MAAM,cAAc,CAAA;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAA;AACvC,OAAO,EAAE,qBAAqB,EAAE,MAAM,kBAAkB,CAAA;AAExD,SAAS,kBAAkB;IAC1B,OAAO,OAAO,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAA;AAC9E,CAAC;AAED,MAAM,oBAAoB,GAAG,kBAAkB,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAA;AAEjE,SAAS,iBAAiB,CAAC,IAAY;IACtC,O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M,mBAAmB,CAAA;AAEpD,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAEpD,OAAO,EACN,0BAA0B,EAC1B,qBAAqB,EACrB,kBAAkB,EAClB,kBAAkB,GAClB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAE9D,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAGjD,OAAO,EACN,uBAAuB,EACvB,2BAA2B,EAC3B,qCAAqC,EACrC,uBAAuB,EACvB,wBAAwB,EACxB,kBAAkB,GAClB,MAAM,cAAc,CAAA"}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
declare const storeCollectionSchema: z.ZodObject<{
|
|
3
|
+
handle: z.ZodString;
|
|
4
|
+
name: z.ZodString;
|
|
5
|
+
description: z.ZodOptional<z.ZodString>;
|
|
6
|
+
coverImagePath: z.ZodOptional<z.ZodString>;
|
|
7
|
+
grouping: z.ZodOptional<z.ZodEnum<["division", "type"]>>;
|
|
8
|
+
hidden: z.ZodDefault<z.ZodBoolean>;
|
|
9
|
+
productKind: z.ZodDefault<z.ZodString>;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
name: string;
|
|
12
|
+
handle: string;
|
|
13
|
+
hidden: boolean;
|
|
14
|
+
productKind: string;
|
|
15
|
+
description?: string | undefined;
|
|
16
|
+
coverImagePath?: string | undefined;
|
|
17
|
+
grouping?: "type" | "division" | undefined;
|
|
18
|
+
}, {
|
|
19
|
+
name: string;
|
|
20
|
+
handle: string;
|
|
21
|
+
description?: string | undefined;
|
|
22
|
+
coverImagePath?: string | undefined;
|
|
23
|
+
grouping?: "type" | "division" | undefined;
|
|
24
|
+
hidden?: boolean | undefined;
|
|
25
|
+
productKind?: string | undefined;
|
|
26
|
+
}>;
|
|
27
|
+
export declare const storeOptionsSchema: z.ZodObject<{
|
|
28
|
+
/** Shown in the store JSON-LD `brand.name` and page copy. */
|
|
29
|
+
brandName: z.ZodString;
|
|
30
|
+
/**
|
|
31
|
+
* The Fourthwall catalogue for this site, reconciled into config instead
|
|
32
|
+
* of a per-site fork. An empty array is valid — a site without a
|
|
33
|
+
* Fourthwall shop yet (bigbrain, pre-launch) still gets the health check
|
|
34
|
+
* and routes; checkout stays disabled until `checkoutEnabled` is true.
|
|
35
|
+
*/
|
|
36
|
+
collections: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
37
|
+
handle: z.ZodString;
|
|
38
|
+
name: z.ZodString;
|
|
39
|
+
description: z.ZodOptional<z.ZodString>;
|
|
40
|
+
coverImagePath: z.ZodOptional<z.ZodString>;
|
|
41
|
+
grouping: z.ZodOptional<z.ZodEnum<["division", "type"]>>;
|
|
42
|
+
hidden: z.ZodDefault<z.ZodBoolean>;
|
|
43
|
+
productKind: z.ZodDefault<z.ZodString>;
|
|
44
|
+
}, "strip", z.ZodTypeAny, {
|
|
45
|
+
name: string;
|
|
46
|
+
handle: string;
|
|
47
|
+
hidden: boolean;
|
|
48
|
+
productKind: string;
|
|
49
|
+
description?: string | undefined;
|
|
50
|
+
coverImagePath?: string | undefined;
|
|
51
|
+
grouping?: "type" | "division" | undefined;
|
|
52
|
+
}, {
|
|
53
|
+
name: string;
|
|
54
|
+
handle: string;
|
|
55
|
+
description?: string | undefined;
|
|
56
|
+
coverImagePath?: string | undefined;
|
|
57
|
+
grouping?: "type" | "division" | undefined;
|
|
58
|
+
hidden?: boolean | undefined;
|
|
59
|
+
productKind?: string | undefined;
|
|
60
|
+
}>, "many">>;
|
|
61
|
+
/** Fourthwall collection handle treated as "everything" (default `"all"`). */
|
|
62
|
+
catalogueHandle: z.ZodDefault<z.ZodString>;
|
|
63
|
+
/**
|
|
64
|
+
* How many products the landing page shows by default. `"all"` (the
|
|
65
|
+
* default) paginates through the full Fourthwall catalogue — sites used
|
|
66
|
+
* to hardcode a 3-product teaser here, which is the "3/11 products
|
|
67
|
+
* shown" defect the channel-store-recovery review found.
|
|
68
|
+
*/
|
|
69
|
+
landingProductCount: z.ZodDefault<z.ZodUnion<[z.ZodLiteral<"all">, z.ZodNumber]>>;
|
|
70
|
+
defaultCurrency: z.ZodDefault<z.ZodString>;
|
|
71
|
+
supportedCurrencies: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
|
|
72
|
+
/** UTM/analytics origin marker forwarded to Fourthwall checkout, e.g. `"megaprojects"`. */
|
|
73
|
+
cartOrigin: z.ZodString;
|
|
74
|
+
/**
|
|
75
|
+
* Whether this site's Fourthwall shop is live. When false, product and
|
|
76
|
+
* collection pages still render (catalogue browsing works) but add-to-cart
|
|
77
|
+
* and checkout are disabled with an explicit "coming soon" state — never
|
|
78
|
+
* fixture/fake products. Used by bigbrain until its shop exists.
|
|
79
|
+
*/
|
|
80
|
+
checkoutEnabled: z.ZodDefault<z.ZodBoolean>;
|
|
81
|
+
merchantReturnPolicy: z.ZodOptional<z.ZodObject<{
|
|
82
|
+
applicableCountry: z.ZodString;
|
|
83
|
+
returnPolicyCategory: z.ZodString;
|
|
84
|
+
}, "strip", z.ZodTypeAny, {
|
|
85
|
+
applicableCountry: string;
|
|
86
|
+
returnPolicyCategory: string;
|
|
87
|
+
}, {
|
|
88
|
+
applicableCountry: string;
|
|
89
|
+
returnPolicyCategory: string;
|
|
90
|
+
}>>;
|
|
91
|
+
imageTransform: z.ZodDefault<z.ZodObject<{
|
|
92
|
+
enabled: z.ZodDefault<z.ZodBoolean>;
|
|
93
|
+
}, "strip", z.ZodTypeAny, {
|
|
94
|
+
enabled: boolean;
|
|
95
|
+
}, {
|
|
96
|
+
enabled?: boolean | undefined;
|
|
97
|
+
}>>;
|
|
98
|
+
routes: z.ZodDefault<z.ZodObject<{
|
|
99
|
+
checkoutPath: z.ZodDefault<z.ZodString>;
|
|
100
|
+
webhookPath: z.ZodDefault<z.ZodString>;
|
|
101
|
+
cartBootstrapPath: z.ZodDefault<z.ZodString>;
|
|
102
|
+
}, "strip", z.ZodTypeAny, {
|
|
103
|
+
checkoutPath: string;
|
|
104
|
+
webhookPath: string;
|
|
105
|
+
cartBootstrapPath: string;
|
|
106
|
+
}, {
|
|
107
|
+
checkoutPath?: string | undefined;
|
|
108
|
+
webhookPath?: string | undefined;
|
|
109
|
+
cartBootstrapPath?: string | undefined;
|
|
110
|
+
}>>;
|
|
111
|
+
}, "strip", z.ZodTypeAny, {
|
|
112
|
+
brandName: string;
|
|
113
|
+
collections: {
|
|
114
|
+
name: string;
|
|
115
|
+
handle: string;
|
|
116
|
+
hidden: boolean;
|
|
117
|
+
productKind: string;
|
|
118
|
+
description?: string | undefined;
|
|
119
|
+
coverImagePath?: string | undefined;
|
|
120
|
+
grouping?: "type" | "division" | undefined;
|
|
121
|
+
}[];
|
|
122
|
+
catalogueHandle: string;
|
|
123
|
+
landingProductCount: number | "all";
|
|
124
|
+
defaultCurrency: string;
|
|
125
|
+
supportedCurrencies: string[];
|
|
126
|
+
cartOrigin: string;
|
|
127
|
+
checkoutEnabled: boolean;
|
|
128
|
+
imageTransform: {
|
|
129
|
+
enabled: boolean;
|
|
130
|
+
};
|
|
131
|
+
routes: {
|
|
132
|
+
checkoutPath: string;
|
|
133
|
+
webhookPath: string;
|
|
134
|
+
cartBootstrapPath: string;
|
|
135
|
+
};
|
|
136
|
+
merchantReturnPolicy?: {
|
|
137
|
+
applicableCountry: string;
|
|
138
|
+
returnPolicyCategory: string;
|
|
139
|
+
} | undefined;
|
|
140
|
+
}, {
|
|
141
|
+
brandName: string;
|
|
142
|
+
cartOrigin: string;
|
|
143
|
+
collections?: {
|
|
144
|
+
name: string;
|
|
145
|
+
handle: string;
|
|
146
|
+
description?: string | undefined;
|
|
147
|
+
coverImagePath?: string | undefined;
|
|
148
|
+
grouping?: "type" | "division" | undefined;
|
|
149
|
+
hidden?: boolean | undefined;
|
|
150
|
+
productKind?: string | undefined;
|
|
151
|
+
}[] | undefined;
|
|
152
|
+
catalogueHandle?: string | undefined;
|
|
153
|
+
landingProductCount?: number | "all" | undefined;
|
|
154
|
+
defaultCurrency?: string | undefined;
|
|
155
|
+
supportedCurrencies?: string[] | undefined;
|
|
156
|
+
checkoutEnabled?: boolean | undefined;
|
|
157
|
+
merchantReturnPolicy?: {
|
|
158
|
+
applicableCountry: string;
|
|
159
|
+
returnPolicyCategory: string;
|
|
160
|
+
} | undefined;
|
|
161
|
+
imageTransform?: {
|
|
162
|
+
enabled?: boolean | undefined;
|
|
163
|
+
} | undefined;
|
|
164
|
+
routes?: {
|
|
165
|
+
checkoutPath?: string | undefined;
|
|
166
|
+
webhookPath?: string | undefined;
|
|
167
|
+
cartBootstrapPath?: string | undefined;
|
|
168
|
+
} | undefined;
|
|
169
|
+
}>;
|
|
170
|
+
export type StoreOptions = z.input<typeof storeOptionsSchema>;
|
|
171
|
+
export type ResolvedStoreOptions = z.output<typeof storeOptionsSchema>;
|
|
172
|
+
export type StoreCollectionInput = z.input<typeof storeCollectionSchema>;
|
|
173
|
+
export {};
|
|
174
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,QAAA,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;;;;EAQzB,CAAA;AAOF,eAAO,MAAM,kBAAkB;IAC9B,6DAA6D;;IAG7D;;;;;OAKG;;;;;;;;;;;;;;;;;;;;;;;;;;IAGH,8EAA8E;;IAG9E;;;;;OAKG;;;;IAMH,2FAA2F;;IAG3F;;;;;OAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkBF,CAAA;AAEF,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAA;AAC7D,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,MAAM,CAAC,OAAO,kBAAkB,CAAC,CAAA;AACtE,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAA"}
|
package/dist/options.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
const storeCollectionSchema = z.object({
|
|
3
|
+
handle: z.string().min(1),
|
|
4
|
+
name: z.string().min(1),
|
|
5
|
+
description: z.string().optional(),
|
|
6
|
+
coverImagePath: z.string().optional(),
|
|
7
|
+
grouping: z.enum(['division', 'type']).optional(),
|
|
8
|
+
hidden: z.boolean().default(false),
|
|
9
|
+
productKind: z.string().default('merch'),
|
|
10
|
+
});
|
|
11
|
+
const merchantReturnPolicySchema = z.object({
|
|
12
|
+
applicableCountry: z.string().min(1),
|
|
13
|
+
returnPolicyCategory: z.string().min(1),
|
|
14
|
+
});
|
|
15
|
+
export const storeOptionsSchema = z.object({
|
|
16
|
+
/** Shown in the store JSON-LD `brand.name` and page copy. */
|
|
17
|
+
brandName: z.string().min(1),
|
|
18
|
+
/**
|
|
19
|
+
* The Fourthwall catalogue for this site, reconciled into config instead
|
|
20
|
+
* of a per-site fork. An empty array is valid — a site without a
|
|
21
|
+
* Fourthwall shop yet (bigbrain, pre-launch) still gets the health check
|
|
22
|
+
* and routes; checkout stays disabled until `checkoutEnabled` is true.
|
|
23
|
+
*/
|
|
24
|
+
collections: z.array(storeCollectionSchema).default([]),
|
|
25
|
+
/** Fourthwall collection handle treated as "everything" (default `"all"`). */
|
|
26
|
+
catalogueHandle: z.string().default('all'),
|
|
27
|
+
/**
|
|
28
|
+
* How many products the landing page shows by default. `"all"` (the
|
|
29
|
+
* default) paginates through the full Fourthwall catalogue — sites used
|
|
30
|
+
* to hardcode a 3-product teaser here, which is the "3/11 products
|
|
31
|
+
* shown" defect the channel-store-recovery review found.
|
|
32
|
+
*/
|
|
33
|
+
landingProductCount: z.union([z.literal('all'), z.number().int().positive()]).default('all'),
|
|
34
|
+
defaultCurrency: z.string().default('USD'),
|
|
35
|
+
supportedCurrencies: z.array(z.string()).default(['USD', 'GBP', 'EUR', 'CAD', 'AUD']),
|
|
36
|
+
/** UTM/analytics origin marker forwarded to Fourthwall checkout, e.g. `"megaprojects"`. */
|
|
37
|
+
cartOrigin: z.string().min(1),
|
|
38
|
+
/**
|
|
39
|
+
* Whether this site's Fourthwall shop is live. When false, product and
|
|
40
|
+
* collection pages still render (catalogue browsing works) but add-to-cart
|
|
41
|
+
* and checkout are disabled with an explicit "coming soon" state — never
|
|
42
|
+
* fixture/fake products. Used by bigbrain until its shop exists.
|
|
43
|
+
*/
|
|
44
|
+
checkoutEnabled: z.boolean().default(true),
|
|
45
|
+
merchantReturnPolicy: merchantReturnPolicySchema.optional(),
|
|
46
|
+
imageTransform: z
|
|
47
|
+
.object({
|
|
48
|
+
enabled: z.boolean().default(false),
|
|
49
|
+
})
|
|
50
|
+
.default({}),
|
|
51
|
+
routes: z
|
|
52
|
+
.object({
|
|
53
|
+
checkoutPath: z.string().default('/api/store/checkout'),
|
|
54
|
+
webhookPath: z.string().default('/api/store/webhook'),
|
|
55
|
+
cartBootstrapPath: z.string().default('/api/store/cart-bootstrap'),
|
|
56
|
+
})
|
|
57
|
+
.default({}),
|
|
58
|
+
});
|
|
59
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,MAAM,qBAAqB,GAAG,CAAC,CAAC,MAAM,CAAC;IACtC,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACzB,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE,CA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AAC,OAAO,CAAC,KAAK,CAAC;IAC1C,mBAAmB,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IAErF,2FAA2F;IAC3F,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IAE7B;;;;;OAKG;IACH,eAAe,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC;IAE1C,oBAAoB,EAAE,0BAA0B,CAAC,QAAQ,EAAE;IAE3D,cAAc,EAAE,CAAC;SACf,MAAM,CAAC;QACP,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;KACnC,CAAC;SACD,OAAO,CAAC,EAAE,CAAC;IAEb,MAAM,EAAE,CAAC;SACP,MAAM,CAAC;QACP,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,qBAAqB,CAAC;QACvD,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,oBAAoB,CAAC;QACrD,iBAAiB,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,OAAO,CAAC,2BAA2B,CAAC;KAClE,CAAC;SACD,OAAO,CAAC,EAAE,CAAC;CACb,CAAC,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FwImage, FwPrice, FwProduct } from './types.js';
|
|
2
|
+
export interface ProductCardColorOption {
|
|
3
|
+
variantId: string;
|
|
4
|
+
colorName: string;
|
|
5
|
+
swatch: string | null;
|
|
6
|
+
price: FwPrice;
|
|
7
|
+
compareAt: FwPrice | null;
|
|
8
|
+
image: FwImage | null;
|
|
9
|
+
hoverImage: FwImage | null;
|
|
10
|
+
}
|
|
11
|
+
export declare function getProductCardColorOptions(product: FwProduct): ProductCardColorOption[];
|
|
12
|
+
export declare function formatStorePrice(price: FwPrice): string;
|
|
13
|
+
//# sourceMappingURL=product-card-variant.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product-card-variant.d.ts","sourceRoot":"","sources":["../src/product-card-variant.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAa,MAAM,YAAY,CAAA;AAGxE,MAAM,WAAW,sBAAsB;IACtC,SAAS,EAAE,MAAM,CAAA;IACjB,SAAS,EAAE,MAAM,CAAA;IACjB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;IACrB,KAAK,EAAE,OAAO,CAAA;IACd,SAAS,EAAE,OAAO,GAAG,IAAI,CAAA;IACzB,KAAK,EAAE,OAAO,GAAG,IAAI,CAAA;IACrB,UAAU,EAAE,OAAO,GAAG,IAAI,CAAA;CAC1B;AAED,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,SAAS,GAAG,sBAAsB,EAAE,CAyBvF;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAMvD"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { isStoreVariantAvailable } from './variant.js';
|
|
2
|
+
export function getProductCardColorOptions(product) {
|
|
3
|
+
const byColor = new Map();
|
|
4
|
+
for (const variant of product.variants) {
|
|
5
|
+
const sellable = isStoreVariantAvailable(variant);
|
|
6
|
+
const colorName = variant.attributes?.color?.name;
|
|
7
|
+
if (!colorName || !sellable)
|
|
8
|
+
continue;
|
|
9
|
+
if (!byColor.has(colorName)) {
|
|
10
|
+
byColor.set(colorName, variant);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return [...byColor.entries()].map(([colorName, variant]) => {
|
|
14
|
+
const images = variant.images?.length ? variant.images : product.images;
|
|
15
|
+
return {
|
|
16
|
+
variantId: variant.id,
|
|
17
|
+
colorName,
|
|
18
|
+
swatch: variant.attributes?.color?.swatch ?? null,
|
|
19
|
+
price: variant.unitPrice,
|
|
20
|
+
compareAt: variant.compareAtPrice ?? null,
|
|
21
|
+
image: images[0] ?? null,
|
|
22
|
+
hoverImage: images[1] ?? null,
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
export function formatStorePrice(price) {
|
|
27
|
+
return new Intl.NumberFormat('en-US', {
|
|
28
|
+
style: 'currency',
|
|
29
|
+
currency: price.currency,
|
|
30
|
+
maximumFractionDigits: Number.isInteger(price.value) ? 0 : 2,
|
|
31
|
+
}).format(price.value);
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=product-card-variant.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"product-card-variant.js","sourceRoot":"","sources":["../src/product-card-variant.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAA;AAYtD,MAAM,UAAU,0BAA0B,CAAC,OAAkB;IAC5D,MAAM,OAAO,GAAG,IAAI,GAAG,EAAqB,CAAA;IAE5C,KAAK,MAAM,OAAO,IAAI,OAAO,CAAC,QAAQ,EAAE,CAAC;QACxC,MAAM,QAAQ,GAAG,uBAAuB,CAAC,OAAO,CAAC,CAAA;QACjD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,EAAE,KAAK,EAAE,IAAI,CAAA;QACjD,IAAI,CAAC,SAAS,IAAI,CAAC,QAAQ;YAAE,SAAQ;QAErC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;YAC7B,OAAO,CAAC,GAAG,CAAC,SAAS,EAAE,OAAO,CAAC,CAAA;QAChC,CAAC;IACF,CAAC;IAED,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,SAAS,EAAE,OAAO,CAAC,EAAE,EAAE;QAC1D,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAA;QACvE,OAAO;YACN,SAAS,EAAE,OAAO,CAAC,EAAE;YACrB,SAAS;YACT,MAAM,EAAE,OAAO,CAAC,UAAU,EAAE,KAAK,EAAE,MAAM,IAAI,IAAI;YACjD,KAAK,EAAE,OAAO,CAAC,SAAS;YACxB,SAAS,EAAE,OAAO,CAAC,cAAc,IAAI,IAAI;YACzC,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,IAAI;YACxB,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC,IAAI,IAAI;SAC7B,CAAA;IACF,CAAC,CAAC,CAAA;AACH,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAc;IAC9C,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,OAAO,EAAE;QACrC,KAAK,EAAE,UAAU;QACjB,QAAQ,EAAE,KAAK,CAAC,QAAQ;QACxB,qBAAqB,EAAE,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;KAC5D,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;AACvB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cart-bootstrap.d.ts","sourceRoot":"","sources":["../../src/routes/cart-bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAGvC,wBAAsB,GAAG,CAAC,QAAQ,EAAE,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,CAEjE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cart-bootstrap.js","sourceRoot":"","sources":["../../src/routes/cart-bootstrap.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEvC,MAAM,CAAC,KAAK,UAAU,GAAG,CAAC,QAAoB;IAC7C,OAAO,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,eAAe,EAAE,CAAC,CAAA;AAChE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkout.d.ts","sourceRoot":"","sources":["../../src/routes/checkout.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAIvC,wBAAsB,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,CAMjE;AAED,wBAAgB,GAAG,IAAI,QAAQ,CAE9B"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { env as cloudflareEnv } from 'cloudflare:workers';
|
|
2
|
+
import { createCheckoutResponse } from '../api.js';
|
|
3
|
+
import { getConfig } from '../state.js';
|
|
4
|
+
export async function POST(context) {
|
|
5
|
+
return createCheckoutResponse({
|
|
6
|
+
request: context.request,
|
|
7
|
+
env: cloudflareEnv,
|
|
8
|
+
cartOrigin: getConfig().cartOrigin,
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
export function ALL() {
|
|
12
|
+
return Response.json({ error: 'Method not allowed' }, { status: 405 });
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=checkout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"checkout.js","sourceRoot":"","sources":["../../src/routes/checkout.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,IAAI,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAEzD,OAAO,EAAoB,sBAAsB,EAAE,MAAM,WAAW,CAAA;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEvC,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,OAAmB;IAC7C,OAAO,sBAAsB,CAAC;QAC7B,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,GAAG,EAAE,aAA4B;QACjC,UAAU,EAAE,SAAS,EAAE,CAAC,UAAU;KAClC,CAAC,CAAA;AACH,CAAC;AAED,MAAM,UAAU,GAAG;IAClB,OAAO,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,oBAAoB,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAA;AACvE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook.d.ts","sourceRoot":"","sources":["../../src/routes/webhook.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAGvC,wBAAsB,IAAI,CAAC,OAAO,EAAE,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC,CAKjE;AAED,wBAAgB,GAAG,IAAI,QAAQ,CAE9B"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { env as cloudflareEnv } from 'cloudflare:workers';
|
|
2
|
+
import { createWebhookResponse } from '../api.js';
|
|
3
|
+
export async function POST(context) {
|
|
4
|
+
return createWebhookResponse({
|
|
5
|
+
request: context.request,
|
|
6
|
+
env: cloudflareEnv,
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
export function ALL() {
|
|
10
|
+
return Response.json({ error: 'Method not allowed' }, { status: 405 });
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=webhook.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webhook.js","sourceRoot":"","sources":["../../src/routes/webhook.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,IAAI,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAEzD,OAAO,EAAE,qBAAqB,EAAmB,MAAM,WAAW,CAAA;AAElE,MAAM,CAAC,KAAK,UAAU,IAAI,CAAC,OAAmB;IAC7C,OAAO,qBAAqB,CAAC;QAC5B,OAAO,EAAE,OAAO,CAAC,OAAO;QACxB,GAAG,EAAE,aAA2B;KAChC,CAAC,CAAA;AACH,CAAC;AAED,MAAM,UAAU,GAAG;IAClB,OAAO,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,oBAAoB,EAAE,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,CAAA;AACvE,CAAC"}
|
package/dist/state.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ResolvedStoreOptions } from './options.js';
|
|
2
|
+
export declare function _setConfig(next: ResolvedStoreOptions): void;
|
|
3
|
+
export declare function getConfig(): ResolvedStoreOptions;
|
|
4
|
+
export declare function getConfigOrNull(): ResolvedStoreOptions | null;
|
|
5
|
+
//# sourceMappingURL=state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.d.ts","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAIxD,wBAAgB,UAAU,CAAC,IAAI,EAAE,oBAAoB,GAAG,IAAI,CAE3D;AAED,wBAAgB,SAAS,IAAI,oBAAoB,CAOhD;AAED,wBAAgB,eAAe,IAAI,oBAAoB,GAAG,IAAI,CAE7D"}
|
package/dist/state.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
let config = null;
|
|
2
|
+
export function _setConfig(next) {
|
|
3
|
+
config = next;
|
|
4
|
+
}
|
|
5
|
+
export function getConfig() {
|
|
6
|
+
if (!config) {
|
|
7
|
+
throw new Error('@growth-labs/store: config accessed before the integration ran. Add store() to astro.config.mjs.');
|
|
8
|
+
}
|
|
9
|
+
return config;
|
|
10
|
+
}
|
|
11
|
+
export function getConfigOrNull() {
|
|
12
|
+
return config;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"state.js","sourceRoot":"","sources":["../src/state.ts"],"names":[],"mappings":"AAEA,IAAI,MAAM,GAAgC,IAAI,CAAA;AAE9C,MAAM,UAAU,UAAU,CAAC,IAA0B;IACpD,MAAM,GAAG,IAAI,CAAA;AACd,CAAC;AAED,MAAM,UAAU,SAAS;IACxB,IAAI,CAAC,MAAM,EAAE,CAAC;QACb,MAAM,IAAI,KAAK,CACd,kGAAkG,CAClG,CAAA;IACF,CAAC;IACD,OAAO,MAAM,CAAA;AACd,CAAC;AAED,MAAM,UAAU,eAAe;IAC9B,OAAO,MAAM,CAAA;AACd,CAAC"}
|