diff --git a/compat/$live/mod.ts b/compat/$live/mod.ts index 70948835b..1fb56215b 100644 --- a/compat/$live/mod.ts +++ b/compat/$live/mod.ts @@ -5,7 +5,7 @@ import { buildSourceMap } from "$live/blocks/utils.tsx"; import type { Manifest as LiveManifest } from "$live/live.gen.ts"; import type { Manifest as WebSiteManifest } from "../../website/manifest.gen.ts"; -import webSite from "../../website/mod.ts"; +import webSite, { Props } from "../../website/mod.ts"; import type { Manifest as WorkflowsManifest } from "../../workflows/manifest.gen.ts"; import { SourceMap } from "$live/blocks/app.ts"; @@ -83,9 +83,6 @@ const manifestMappings: ManifestMappings = { "$live/flags/multivariate.ts": "website/flags/multivariate.ts", }, }; -// deno-lint-ignore no-empty-interface -export interface Props { -} /** * @title $live */ diff --git a/compat/std/mod.ts b/compat/std/mod.ts index 12aa47a0f..be9c3a9b3 100644 --- a/compat/std/mod.ts +++ b/compat/std/mod.ts @@ -11,6 +11,8 @@ import type { Manifest as VNDAManifest } from "../../vnda/manifest.gen.ts"; import vnda, { Props as VNDAProps } from "../../vnda/mod.ts"; import type { Manifest as VTEXManifest } from "../../vtex/manifest.gen.ts"; import vtex, { Props as VTEXProps } from "../../vtex/mod.ts"; +import commerce, { Props as CommerceProps } from "../../commerce/mod.ts"; + import type { Manifest as WebSiteManifest } from "../../website/manifest.gen.ts"; import type { ShopifyAccount, @@ -209,72 +211,88 @@ type Manifest = { : ManifestWithStdCompat[key]; }; -export type Props = VTEXProps | ShopifyProps | VNDAProps; +type AvailableCommerceProps = CommerceProps["commerce"]; -const isVTEXProps = (props: Props): props is VTEXProps => { - return (props as VTEXProps).platform === "vtex"; +const isVTEXProps = (props: AvailableCommerceProps): props is VTEXProps => { + return (props as VTEXProps)?.platform === "vtex"; }; -const isShopifyProps = (props: Props): props is ShopifyProps => { - return (props as ShopifyProps).platform === "shopify"; +const isShopifyProps = ( + props: AvailableCommerceProps, +): props is ShopifyProps => { + return (props as ShopifyProps)?.platform === "shopify"; }; -const isVNDAProps = (props: Props): props is VNDAProps => { - return (props as VNDAProps).platform === "vnda"; +const isVNDAProps = (props: AvailableCommerceProps): props is VNDAProps => { + return (props as VNDAProps)?.platform === "vnda"; }; export type State = { configVTEX?: VTEXAccount; configShopify?: ShopifyAccount; configVNDA?: VNDAAccount; -} & Props; +} & AvailableCommerceProps; +export type { CommerceProps as Props }; export default function Std( - props: Props, -): App]> { + props: CommerceProps, +): App< + Manifest, + State, + [ReturnType, ReturnType] +> { const targetApps: Record< string, { manifest: AppManifest; sourceMap: SourceMap } > = {}; - const state: State = { ...props }; - if (isVTEXProps(props)) { + + const { dependencies, ...commerceApp } = commerce( + props, + ); + let state: State = { ...props.commerce }; + if (isVTEXProps(props.commerce)) { state.configVTEX = { defaultLocale: "pt-BR", defaultPriceCurrency: "BRL", defaultSalesChannel: "1", - ...props, + ...props.commerce, }; - const { manifest } = vtex(props); + const { manifest, state: appState } = vtex(props.commerce); + state = { ...state, ...appState }; targetApps["vtex"] = { sourceMap: buildSourceMap(manifest), manifest, }; } - if (isShopifyProps(props)) { - state.configShopify = props; - const { manifest } = shopify(props); + if (isShopifyProps(props.commerce)) { + state.configShopify = props.commerce; + const { manifest, state: appState } = shopify(props.commerce); + state = { ...state, ...appState }; + targetApps["shopify"] = { sourceMap: buildSourceMap(manifest), manifest, }; } - if (isVNDAProps(props)) { + if (isVNDAProps(props.commerce)) { state.configVNDA = { - domain: props.publicUrl, - internalDomain: `${props.account}.cdn.vnda.com.br`, - useSandbox: props.sandbox, - authToken: props.authToken, + domain: props.commerce.publicUrl, + internalDomain: `${props.commerce.account}.cdn.vnda.com.br`, + useSandbox: props.commerce.sandbox, + authToken: props.commerce.authToken, defaultPriceCurrency: "BRL", }; - const { manifest } = vnda(props); + const { manifest, state: appState } = vnda(props.commerce); + state = { ...state, ...appState }; + targetApps["vnda"] = { sourceMap: buildSourceMap(manifest), manifest, }; } const liveApp = $live(props); - const webSiteApp = liveApp.dependencies![0]; + const { resolvables: _ignoreResolvables, ...webSiteApp } = dependencies![0]; const sourceMap: SourceMap = { ...buildSourceMap(manifest), }; @@ -306,9 +324,12 @@ export default function Std( } return { - state: props, + state, sourceMap, manifest: _manifest as Manifest, - dependencies: [liveApp], + dependencies: [liveApp, { + ...commerceApp, + dependencies: [webSiteApp, dependencies![1]], + }], }; } diff --git a/compat/std/runtime.ts b/compat/std/runtime.ts index c6d780f6f..9edafce04 100644 --- a/compat/std/runtime.ts +++ b/compat/std/runtime.ts @@ -1,4 +1,4 @@ import { forApp } from "$live/clients/withManifest.ts"; import app from "./mod.ts"; -export const Runtime = forApp>(); +export const Runtime = forApp>(); \ No newline at end of file diff --git a/import_map.json b/import_map.json index d81cc7ded..acb8540c4 100644 --- a/import_map.json +++ b/import_map.json @@ -9,7 +9,7 @@ "@preact/signals-core": "https://esm.sh/@preact/signals-core@1.3.0", "std/": "https://deno.land/std@0.190.0/", "partytown/": "https://deno.land/x/partytown@0.3.4/", - "deco-sites/std/": "https://denopkg.com/deco-sites/std@1.21.3/", + "deco-sites/std/": "https://denopkg.com/deco-sites/std@1.21.6/", "deco/": "https://denopkg.com/deco-cx/deco@1.32.1/" } }