1.0.1-beta.31 • Published 1 year ago

@teko-builder/client v1.0.1-beta.31

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

Tích hợp

Cài đặt

yarn add @teko-builder/client

# hoặc

npm install @teko-builder/client

Sử dụng với React - chỉ xử lý các component tĩnh của Tempi

import { builder, BuilderComponent } from "@teko-builder/client";
import "@teko-builder/client/dist/base.css";

const publishedDomain = 'vnshop.vn'

builder.init(publishedDomain, {
  env: "dev", // dev | stag | production
});

function App() {
  const [content, setContent] = useState();
  const [metaData, setMetaData] = useState();
  const slug = location.pathname.substring(1);
  
  useEffect(() => {
    const fetchPage = async () => {
      const { pbConfig, metaData } = await builder.getPublicPageV2({
        slug: slug || "/", 
        device: "desktop",
      });
      setContent(pbConfig);
      setMetaData(metaData);
    };
    fetchPage();
  }, []);

  return (
    <BuilderComponent
      content={content}
      configs={{
        ggSheetKey: {
          clientEmail: 'clientEmail',
          privateKey: 'privateKey',
        },
        terminalCode: 'vnshop',
        locationCode: 'HN001'
      }}
    />
  );
}

export default App;

API

builder

functionDescriptionType
initkhởi tạo builderfunction(domain: string, { env: 'dev' | 'stag' | 'production' | 'internal' }) => void
getPublicPageV2lấy data của pagefunction({ slug: string; device: 'desktop' | 'mobile' }) => Promise\<PublicPageResponseV2>
getSSRInputslấy các thông tin cần thiết sử dụng để khởi tạo dữ liệu SSR như products, megaMenu,...function(pbConfig: PageBuilderResponse) => { key: string: SSRInput[] }

BuilderComponent

PropertyDescriptionType
contentcấu hình của builder (dữ liêu pbConfig lấy từ builder.getPublicPageV2)PageBuilderResponse
configscác cấu hình thêm cho builder (terminalId hoặc terminalCode, locationCode, device, ...)object
mappingDynamicSlotsMapping giữa các slot visualize của tempi và các component sử dụng của EcommerceMappingDynamicSlots
ssrDataDữ liệu phục vụ cơ chế SSR cho các component động{key: string : SSROutput[]}
globalDataDữ liệu global sử dụng cho tất cả các elements bên trongobject

PublicPageResponseV2

PropertyDescriptionType
nameTên pagestring
pbConfigCấu hình page (format của Tempi)PageBuilderResponse
extraInfoCác thông tin thêm của page như SEO, tracking, ...PageExtraInfo
canonicalCanonical của pagestring
menuDanh sách menu của page nếu page thuộc websitearray

PublicPageResponse

PropertyDescriptionType
pageThông tin pagePage

Page

PropertyType
idnumber
pbConfigPageBuilderResponse
metaTitlestring
metaDescriptionstring
metaImagestring
faviconUrlstring

PageBuilderResponse

PropertyDescriptionType
key: stringCấu hình từng component (format của Tempi)PBComponent

PBComponent

PropertyDescriptionType
idid (unique) của từng componentstring
parentIdid của component cha của component hiện tại, nếu là root thì parentId = nullstring
childrendanh sách id của các component là con của component hiện tạistring[]
tagđịnh danh của từng loại component. Ví dụ: row, col, image, best_selling_product,...string
styleStyle chung của componentReact.CSSProperties
customAttributesCấu hình riêng của từng componentobject

PageExtraInfo

PropertyType
metaTitlestring
metaDescriptionstring
metaImagestring
faviconUrlstring
noIndexboolean
tekoTrackingWebMobilestring
tekoTrackingWebDesktopstring
facebookPixelIdstring
googleAnalyticsIdstring
googleTagManagerIdstring
googleAdsIdstring
tiktokPixelIdstring
headContentHtmlstring
bodyContentHtmlstring

SSRInput

PropertyDescriptionType
slotLoại slot cần sử dụng cơ chế SSRSlot
collectionSlugslug của collection (dùng cho danh sách sản phẩm) - slot = product_*string
menuZonezone của menu (dùng cho mega menu) - slot = mega_menustring

SSROutput

PropertyDescriptionType
slotLoại slot cần sử dụng cơ chế SSRSlot
serverDataDữ liệu đầu vào của slot sử dụng cơ chế SSRunknown (quy định bởi bên tích hợp)

MappingDynamicSlots

PropertyDescriptionType
key: Slotslot trên tempi và component trên Ecommerce tương ứngReact.Element

Slot

product_carousel_desktop | product_grid_desktop | product_carousel_mobile | product_grid_mobile | mega_menu | recent_search | recent_product | pending_payment

Sử dụng với Next - bao gồm cơ chế SSR bởi getServerSideProps

import { builder, BuilderComponent } from "@teko-builder/client";
import {
  ProductCarouselDesktop,
  ProductGridDesktop,
  ProductCarouselMobile,
  ProductGridMobile,
  MegaMenu,
  RecentSearch,
  RecentProduct,
  PendingPayment,
} from 'components'
import "@teko-builder/client/dist/base.css";

function Page({ pbConfig, extraInfo, ssrData }) {

  return (
    <>
      <CustomHead extraInfo={extraInfo} >
      <BuilderComponent
        content={pbConfig}
        ssrData={ssrData}
        mappingDynamicSlots={{
          product_carousel_desktop: ProductCarouselDesktop,
          product_grid_desktop: ProductGridDesktop,
          product_carousel_mobile: ProductCarouselMobile,
          product_grid_mobile: ProductGridMobile,
          mega_menu: MegaMenu,
          recent_search: RecentSearch,
          recent_product: RecentProduct,
          pending_payment: PendingPayment
        }}
        configs={{
          ggSheetKey: {
            clientEmail: 'clientEmail',
            privateKey: 'privateKey',
          },
          terminalCode: 'vnshop',
          locationCode: 'HN001',
          device: 'desktop', // quan trọng, sử dụng để hiển thị các component ở từng chế độ màn hình
        }}
      />
    </>
  );
};
export async function getServerSideProps() {
  builder.init(publishedDomain, {
    env: "dev", // dev | stag | production | internal
  });

  const { pbConfig, metaData } = await builder.getPublicPageV2({
    slug: slug || "/", 
    device: "desktop",
  });

  const ssrInputs = builder.getSSRInputs(pbConfig);

  const ssrData = await ecommerceFunctionGetData(ssrInputs) // hàm này sẽ xử lý lấy data SSR, ví dụ products, megaMenu, ...

  // Pass data to the page via props
  return { props: { pbConfig, extraInfo, ssrData } }
}
1.0.1-beta.30

1 year ago

1.0.1-beta.31

1 year ago

1.0.1-beta.25

1 year ago

1.0.1-beta.26

1 year ago

1.0.1-beta.24

1 year ago

1.0.1-beta.29

1 year ago

1.0.1-beta.27

1 year ago

1.0.1-beta.28

1 year ago

1.0.1-beta.22

1 year ago

1.0.1-beta.23

1 year ago

1.0.1-beta.21

1 year ago

1.0.1-beta.18

1 year ago

1.0.1-beta.19

1 year ago

1.0.1-beta.17

1 year ago

1.0.1-beta.9

1 year ago

1.0.1-beta.8

1 year ago

1.0.1-beta.7

1 year ago

1.0.1-beta.10

1 year ago

1.0.1-beta.11

1 year ago

1.0.1-beta.14

1 year ago

1.0.1-beta.15

1 year ago

1.0.1-beta.12

1 year ago

1.0.1-beta.13

1 year ago

1.0.1-beta.16

1 year ago

1.0.0

2 years ago

1.0.1-beta.2

1 year ago

1.0.0-beta.2

2 years ago

1.0.1-beta.1

2 years ago

1.0.0-beta.3

2 years ago

1.0.1-beta.0

2 years ago

1.0.0-beta.4

2 years ago

1.0.1-beta.6

1 year ago

1.0.1-beta.5

1 year ago

1.0.1-beta.4

1 year ago

1.0.0-beta.0

2 years ago

1.0.1-beta.3

1 year ago

1.0.0-beta.1

2 years ago

0.6.1

2 years ago

0.6.0

2 years ago

0.5.8

2 years ago

0.5.7

2 years ago

0.5.9

2 years ago

0.4.9

2 years ago

0.4.8

2 years ago

0.5.4

2 years ago

0.5.3

2 years ago

0.5.6

2 years ago

0.5.5

2 years ago

0.5.0

2 years ago

0.5.2

2 years ago

0.5.1

2 years ago

0.4.5

2 years ago

0.4.4

2 years ago

0.4.7

2 years ago

0.4.6

2 years ago

0.4.1

2 years ago

0.4.3

2 years ago

0.4.2

2 years ago

0.3.17

2 years ago

0.3.16

2 years ago

0.3.20

2 years ago

0.3.23

2 years ago

0.3.22

2 years ago

0.3.21

2 years ago

0.3.19

2 years ago

0.3.18

2 years ago

0.4.0

2 years ago

0.3.4

2 years ago

0.3.15

2 years ago

0.3.14

2 years ago

0.3.9

2 years ago

0.3.13

2 years ago

0.3.12

2 years ago

0.3.11

2 years ago

0.3.10

2 years ago

0.3.8

2 years ago

0.3.7

2 years ago

0.3.6

2 years ago

0.3.5

2 years ago

0.3.0

2 years ago

0.3.2

2 years ago

0.3.3

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.15

2 years ago

0.1.14

2 years ago

0.1.13

2 years ago

0.1.12

2 years ago

0.1.11

2 years ago

0.1.10

2 years ago

0.1.9

2 years ago

0.1.8

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago