Compare commits

..

No commits in common. "eb0e01a4dfd70dc1087cc70b1ba158e729cbf0c0" and "c989bbaa9cee7e3d6883fd728a4ec24a48d60426" have entirely different histories.

21 changed files with 105 additions and 109 deletions

View File

@ -44,7 +44,7 @@ export default defineConfig({
transformMixedEsModules: true, transformMixedEsModules: true,
}, },
rollupOptions: { rollupOptions: {
// external: ['@squidex/squidex', '../squidex-node-sdk'], external: ['@squidex/squidex', '../squidex-node-sdk'],
} }
}, },
vite: { vite: {
@ -52,7 +52,7 @@ export default defineConfig({
commonjs(/**/) commonjs(/**/)
], ],
optimizeDeps: { optimizeDeps: {
// exclude: ['@squidex/squidex', '../squidex-node-sdk'], exclude: ['@squidex/squidex', '../squidex-node-sdk'],
} }
// resolve: { // resolve: {
// alias: [ // alias: [

View File

@ -97,11 +97,11 @@ export const amazonAppendImagesCommand = (amazonCommand: Command) =>
} }
if (didUpdate) { if (didUpdate) {
log(`Listing did update, updating product listing with appended images.`); log(`Listing did update, updating product listing with appended images.`);
let updatedDto = await core.client.contents.putContent({ let updatedDto = await core.client.contents.putContent(SCHEMAS.LISTINGS, listingDto.id, {
schema: SCHEMAS.LISTINGS,
id: listingDto.id,
unpublished: false, unpublished: false,
requestBody: listing as any, body: listing as any,
}, {
timeoutInSeconds: core.TIMEOUT_IN_SECONDS
}); });
log(`Listing version ${updatedDto.version} stored.`); log(`Listing version ${updatedDto.version} stored.`);
} }

View File

@ -20,15 +20,13 @@ import axios from 'axios';
import ollama from 'ollama'; import ollama from 'ollama';
import slugify from 'slugify'; import slugify from 'slugify';
import type { Offer } from '../../../data/models/multis/Offer.ts'; import type { Offer } from '../../../data/models/multis/Offer.ts';
// import { Blob } from 'buffer';
import { lookup as mimeLookup } from 'mime-types';
export function isValidASIN(asinOrNot: string) { export function isValidASIN(asinOrNot: string) {
return asinOrNot.match(/[A-Z0-9]{10}/g) ? true : false; return asinOrNot.match(/[A-Z0-9]{10}/g) ? true : false;
} }
export async function getAmazonGetItemsRequestSchemaDto() { export async function getAmazonGetItemsRequestSchemaDto() {
return await client.schemas.getSchema({ schema: 'amazon-pa-get-items-request' }); return await client.schemas.getSchema('amazon-pa-get-items-request');
} }
export async function lookupAmazonASINs(asins: string[]) { export async function lookupAmazonASINs(asins: string[]) {
@ -48,21 +46,20 @@ export async function lookupAmazonASINs(asins: string[]) {
] } }, ] } },
requestDate: { iv: requestDate } requestDate: { iv: requestDate }
} }
let amazonGetItemDto = await client.contents.postContent({ let amazonGetItemDto = await client.contents.postContent(SCHEMAS.AMAZON_GET_ITEMS, {
schema: SCHEMAS.AMAZON_GET_ITEMS,
publish: true, publish: true,
requestBody: amazonGetItem as any, body: amazonGetItem as any,
}) })
let amazonGetItemsDto = await getContentsByIds<AmazonGetItem>(SCHEMAS.AMAZON_GET_ITEMS, amazonGetItemDto.id); let amazonGetItemsDto = await getContentsByIds<AmazonGetItem>(SCHEMAS.AMAZON_GET_ITEMS, amazonGetItemDto.id);
return amazonGetItemsDto; return amazonGetItemsDto;
} }
export async function getMarketplaceConnectionSchemaDto() { export async function getMarketplaceConnectionSchemaDto() {
return await client.schemas.getSchema({ schema: 'product-marketplace-connection' }); return await client.schemas.getSchema('product-marketplace-connection');
} }
export async function getAmazonMarketplaceConnectionSchemaDto() { export async function getAmazonMarketplaceConnectionSchemaDto() {
return await client.schemas.getSchema({ schema: 'product-marketplace-connection-amazon' }) return await client.schemas.getSchema('product-marketplace-connection-amazon')
} }
export async function getAmazonMarketplaceDto() { export async function getAmazonMarketplaceDto() {
@ -100,9 +97,8 @@ export async function getBrandDtoByName(brandName: string) {
} }
export async function getAddNewBrandDtoByName(brandName: string) { export async function getAddNewBrandDtoByName(brandName: string) {
let brandDto = await client.contents.postContent({ let brandDto = await client.contents.postContent(SCHEMAS.BRANDS, {
schema: SCHEMAS.BRANDS, body: {
requestBody: {
brandName: { brandName: {
"en-US": brandName!, "en-US": brandName!,
"es-US": brandName!, "es-US": brandName!,
@ -114,8 +110,10 @@ export async function getAddNewBrandDtoByName(brandName: string) {
"fr-CA": `fr-CA/${slugify(brandName!, { lower: true, trim: true })}` "fr-CA": `fr-CA/${slugify(brandName!, { lower: true, trim: true })}`
}, },
} }
}, {
timeoutInSeconds: TIMEOUT_IN_SECONDS,
}); });
let brandsDto = await client.contents.getContents({ schema: SCHEMAS.BRANDS, unpublished: true, ids: brandDto.id }) as ContentsDto<Brand>; let brandsDto = await client.contents.getContents(SCHEMAS.BRANDS, { unpublished: true, ids: brandDto.id }, { timeoutInSeconds: TIMEOUT_IN_SECONDS }) as ContentsDto<Brand>;
return brandsDto; return brandsDto;
} }
@ -130,9 +128,8 @@ export async function getSellerDtoByName(sellerName: string) {
} }
export async function getAddNewSellerDtoByName(sellerName: string) { export async function getAddNewSellerDtoByName(sellerName: string) {
let sellerDto = await client.contents.postContent({ let sellerDto = await client.contents.postContent(SCHEMAS.SELLERS, {
schema: SCHEMAS.SELLERS, body: {
requestBody: {
sellerName: { sellerName: {
"en-US": sellerName!, "en-US": sellerName!,
"es-US": sellerName!, "es-US": sellerName!,
@ -144,8 +141,10 @@ export async function getAddNewSellerDtoByName(sellerName: string) {
"fr-CA": `fr-CA/${slugify(sellerName!, { lower: true, trim: true })}` "fr-CA": `fr-CA/${slugify(sellerName!, { lower: true, trim: true })}`
}, },
} }
}, {
timeoutInSeconds: TIMEOUT_IN_SECONDS,
}); });
let sellersDto = await client.contents.getContents({ schema: SCHEMAS.SELLERS, unpublished: true, ids: sellerDto.id }) as ContentsDto<Seller>; let sellersDto = await client.contents.getContents(SCHEMAS.SELLERS, { unpublished: true, ids: sellerDto.id }, {timeoutInSeconds: TIMEOUT_IN_SECONDS}) as ContentsDto<Seller>;
return sellersDto; return sellersDto;
} }
@ -408,16 +407,17 @@ export async function translateTags_from_en_US_to_fr_CA(tags_en_US: string[]) {
} }
export async function getAddNewProductSubCategoryDto(parentProductCategoryId: NonLocalized<string[]>, categoryName: Localized<string>, description: Localized<string>) { export async function getAddNewProductSubCategoryDto(parentProductCategoryId: NonLocalized<string[]>, categoryName: Localized<string>, description: Localized<string>) {
let productCategoryDto = await client.contents.postContent({ let productCategoryDto = await client.contents.postContent(SCHEMAS.PRODUCT_CATEGORIES, {
schema: SCHEMAS.PRODUCT_CATEGORIES,
publish: false, publish: false,
requestBody: { body: {
categoryName, categoryName,
description, description,
parentCategory: parentProductCategoryId, parentCategory: parentProductCategoryId,
}, },
}, {
timeoutInSeconds: TIMEOUT_IN_SECONDS,
}); });
let productCategoriesDto = await client.contents.getContents({ schema: SCHEMAS.PRODUCT_CATEGORIES, unpublished: true, ids: productCategoryDto.id }) as ContentsDto<ProductCategory>; let productCategoriesDto = await client.contents.getContents(SCHEMAS.PRODUCT_CATEGORIES, { unpublished: true, ids: productCategoryDto.id }, {timeoutInSeconds: TIMEOUT_IN_SECONDS}) as ContentsDto<ProductCategory>;
return productCategoriesDto; return productCategoriesDto;
} }
@ -448,26 +448,28 @@ export async function translateAmazonDescription_from_en_US_to_fr_CA(brandName:
} }
export async function getAddNewProductDtoByProduct(product: Product) { export async function getAddNewProductDtoByProduct(product: Product) {
let productDto = await client.contents.postContent({ let productDto = await client.contents.postContent(SCHEMAS.PRODUCTS, {
schema: SCHEMAS.PRODUCTS,
publish: false, publish: false,
requestBody: { body: {
...product ...product
}, },
}, {
timeoutInSeconds: TIMEOUT_IN_SECONDS,
}); });
let productsDto = await client.contents.getContents({ schema: SCHEMAS.PRODUCTS, unpublished: true, ids: productDto.id }) as ContentsDto<Product>; let productsDto = await client.contents.getContents(SCHEMAS.PRODUCTS, { unpublished: true, ids: productDto.id }, {timeoutInSeconds: TIMEOUT_IN_SECONDS}) as ContentsDto<Product>;
return productsDto; return productsDto;
} }
export async function getAddNewProductListingDtoByProduct(listing: Listing) { export async function getAddNewProductListingDtoByProduct(listing: Listing) {
let listingDto = await client.contents.postContent({ let listingDto = await client.contents.postContent(SCHEMAS.LISTINGS, {
schema: SCHEMAS.LISTINGS,
publish: true, publish: true,
requestBody: { body: {
...listing ...listing
} }
}, {
timeoutInSeconds: TIMEOUT_IN_SECONDS,
}); });
let listingsDto = await client.contents.getContents({ schema: SCHEMAS.LISTINGS, unpublished: true, ids: listingDto.id }) as ContentsDto<Listing>; let listingsDto = await client.contents.getContents(SCHEMAS.LISTINGS, { unpublished: true, ids: listingDto.id }, {timeoutInSeconds: TIMEOUT_IN_SECONDS}) as ContentsDto<Listing>;
return listingsDto; return listingsDto;
} }
@ -480,11 +482,11 @@ export function removeQuotes(str: string) {
} }
export async function upsertAssetFolder(folderName: string, parentFolderId?: string|undefined) { export async function upsertAssetFolder(folderName: string, parentFolderId?: string|undefined) {
const assetFolders = await client.assets.getAssetFolders({ scope: 'Items', parentId: parentFolderId }); const assetFolders = await client.assets.getAssetFolders({ scope: 'Items', parentId: parentFolderId }, { timeoutInSeconds: TIMEOUT_IN_SECONDS });
let assetFolder; let assetFolder;
let assetFolderLookup = assetFolders.items.filter(folder => folder.folderName === folderName); let assetFolderLookup = assetFolders.items.filter(folder => folder.folderName === folderName);
if (assetFolderLookup.length === 0) { if (assetFolderLookup.length === 0) {
assetFolder = await client.assets.postAssetFolder({ createAssetFolderDto: { folderName: folderName, parentId: parentFolderId }}); assetFolder = await client.assets.postAssetFolder({ folderName: folderName, parentId: parentFolderId }, { timeoutInSeconds: TIMEOUT_IN_SECONDS });
} }
else { else {
assetFolder = assetFolderLookup[0]; assetFolder = assetFolderLookup[0];
@ -498,28 +500,21 @@ export async function getAllAssetsInFolder(assetFolderId: string) {
} }
export async function uploadDownloadedImageToSquidexAsAsset(downloadUrl: string, assetFolderId: string) { export async function uploadDownloadedImageToSquidexAsAsset(downloadUrl: string, assetFolderId: string) {
let url = new URL(downloadUrl); let filename = downloadUrl.substring(downloadUrl.lastIndexOf('/')+1);
let filename = url.pathname.substring(downloadUrl.lastIndexOf('/')+1);//.replace(/[A-Z0-9\.-_]*, '$0');
let response = await axios.get(downloadUrl, { timeout: TIMEOUT_IN_SECONDS * 1000, responseType: 'arraybuffer' }); let response = await axios.get(downloadUrl, { timeout: TIMEOUT_IN_SECONDS * 1000, responseType: 'arraybuffer' });
let form = new FormData(); let assetDto = await client.assets.postAsset({ readable: response.data, fileName: filename }, { timeoutInSeconds: TIMEOUT_IN_SECONDS });
let blob = new Blob(response.data, {type: mimeLookup(filename) as string}); assetDto = await client.assets.putAsset(assetDto.id, { fileName: filename, metadata: { ...assetDto.metadata, 'amazon-url': downloadUrl }, tags: ['amazon', 'product'] })
form.append('fileName', filename); assetDto = await client.assets.putAssetParent(assetDto.id, { parentId: assetFolderId });
form.append('file', blob, filename);
form.append('parentId', assetFolderId);
let assetDto = await client.assets.postAsset({ file: blob, fileName: filename, fileUrl: filename, parentId: assetFolderId }, {
body: form
});
assetDto = await client.assets.putAsset({ id: assetDto.id, annotateAssetDto: { metadata: { ...assetDto.metadata, 'amazon-url': downloadUrl }, tags: ['amazon', 'product'] } })
// assetDto = await client.assets.putAssetParent({ id: assetDto.id, moveAssetDto: { parentId: assetFolderId } });
return assetDto; return assetDto;
} }
export async function getAddNewOfferDto(offer: Offer) { export async function getAddNewOfferDto(offer: Offer) {
let offerDto = await client.contents.postContent({ let offerDto = await client.contents.postContent(SCHEMAS.OFFERS, {
schema: SCHEMAS.OFFERS,
publish: true, publish: true,
requestBody: offer as any, body: offer as any,
}, {
timeoutInSeconds: TIMEOUT_IN_SECONDS,
}); });
let offersDto = await client.contents.getContents({ schema: SCHEMAS.OFFERS, unpublished: true, ids: offerDto.id }) as ContentsDto<ProductCategory>; let offersDto = await client.contents.getContents(SCHEMAS.OFFERS, { unpublished: true, ids: offerDto.id }, {timeoutInSeconds: TIMEOUT_IN_SECONDS}) as ContentsDto<ProductCategory>;
return offersDto; return offersDto;
} }

View File

@ -11,7 +11,7 @@ interface Props extends Multilingual, SquidexEditable {
const { brand, editToken, locale } = Astro.props; const { brand, editToken, locale } = Astro.props;
let brandLogoImage = path.posix.join('/img', (await getAssetById(brand.logoImage![locale])) let brandLogoImage = path.posix.join('/img', (await getAssetById(brand.logoImage[locale]))
.links['content'] .links['content']
.href .href
.split('/') .split('/')
@ -27,10 +27,10 @@ let brandLogoImage = path.posix.join('/img', (await getAssetById(brand.logoImage
<img src={brandLogoImage} alt={brand.brandName[locale]} title={brand.brandName[locale]} /> <img src={brandLogoImage} alt={brand.brandName[locale]} title={brand.brandName[locale]} />
} }
<div class="flex-right"> <div class="flex-right">
{getLocaleField(locale, brand.shortDescription!) && <div class="short-desc"><Fragment set:html={renderMarkdown(getLocaleField(locale, brand.shortDescription!)!)} /></div> } {getLocaleField(locale, brand.shortDescription) && <div class="short-desc"><Fragment set:html={renderMarkdown(getLocaleField(locale, brand.shortDescription)!)} /></div> }
</div> </div>
</div> </div>
{getLocaleField(locale, brand.longDescription!) && <div class="after-flex"><Fragment set:html={renderMarkdown(getLocaleField(locale, brand.longDescription!)!)} /></div> } {getLocaleField(locale, brand.longDescription) && <div class="after-flex"><Fragment set:html={renderMarkdown(getLocaleField(locale, brand.longDescription)!)} /></div> }
</div> </div>
<style> <style>

View File

@ -10,7 +10,7 @@ interface Props extends Multilingual, SquidexEditable {
const { brand, editToken, locale } = Astro.props; const { brand, editToken, locale } = Astro.props;
let brandLogoImage = path.posix.join('/img', (await getAssetById(brand.logoImage![locale])) let brandLogoImage = path.posix.join('/img', (await getAssetById(brand.logoImage[locale]))
.links['content'] .links['content']
.href .href
//The purpose of .split('/').reverse().filter(...2...).reverse().join('/') is to //The purpose of .split('/').reverse().filter(...2...).reverse().join('/') is to

View File

@ -120,7 +120,7 @@ async function flatWalkSubCategories (productCategoryId: string): Promise<Conten
if (recurseCategory.parentCategory && recurseCategory.parentCategory.iv && recurseCategory.parentCategory.iv.length > 0) { if (recurseCategory.parentCategory && recurseCategory.parentCategory.iv && recurseCategory.parentCategory.iv.length > 0) {
if (abortAfterRecursions !== 0) { if (abortAfterRecursions !== 0) {
let parentCategoriesDto = await getProductCategoriesByIds(recurseCategory.parentCategory.iv[0]); let parentCategoriesDto = await getProductCategoriesByIds(recurseCategory.parentCategory.iv[0]);
parentCategories = await walkParentCategoriesForCrumbsRecursive(parentCategoriesDto.items[0].data!, abortAfterRecursions--, parentCategoriesDto.items[0].editToken!); parentCategories = await walkParentCategoriesForCrumbsRecursive(parentCategoriesDto.items[0].data!, abortAfterRecursions--, parentCategoriesDto.items[0].editToken);
} }
} }
if (startCategory.slug !== recurseCategory.slug) { if (startCategory.slug !== recurseCategory.slug) {
@ -166,7 +166,7 @@ async function flatWalkSubCategories (productCategoryId: string): Promise<Conten
return ( return (
<BrandCard <BrandCard
locale={locale} locale={locale}
editToken={brandDto.editToken!} editToken={brandDto.editToken}
brand={brandDto.data!} brand={brandDto.data!}
/> />
); );
@ -189,7 +189,7 @@ async function flatWalkSubCategories (productCategoryId: string): Promise<Conten
return ( return (
<BrandCard <BrandCard
locale={locale} locale={locale}
editToken={brandDto.editToken!} editToken={brandDto.editToken}
brand={brandDto.data!} brand={brandDto.data!}
/> />
); );
@ -213,7 +213,7 @@ async function flatWalkSubCategories (productCategoryId: string): Promise<Conten
return ( return (
<BrandCard <BrandCard
locale={locale} locale={locale}
editToken={brandDto.editToken!} editToken={brandDto.editToken}
brand={brandDto.data!} brand={brandDto.data!}
/> />
); );
@ -255,7 +255,7 @@ async function flatWalkSubCategories (productCategoryId: string): Promise<Conten
<ul class="link-card-grid marketplaces" data-squidex-token={pageEditToken}> <ul class="link-card-grid marketplaces" data-squidex-token={pageEditToken}>
{marketplaces.sort((a, b) => a.data!.marketplaceName[locale].localeCompare(b.data!.marketplaceName[locale])).map(marketplaceDto => ( {marketplaces.sort((a, b) => a.data!.marketplaceName[locale].localeCompare(b.data!.marketplaceName[locale])).map(marketplaceDto => (
<MarketplaceCard <MarketplaceCard
editToken={marketplaceDto.editToken!} editToken={marketplaceDto.editToken}
locale={locale} locale={locale}
marketplace={marketplaceDto.data!} marketplace={marketplaceDto.data!}
/> />
@ -276,7 +276,7 @@ async function flatWalkSubCategories (productCategoryId: string): Promise<Conten
<ul class="link-card-grid sellers" data-squidex-token={pageEditToken}> <ul class="link-card-grid sellers" data-squidex-token={pageEditToken}>
{sellers.sort((a, b) => a.data!.sellerName[locale].localeCompare(b.data!.sellerName[locale])).map(sellerDto => ( {sellers.sort((a, b) => a.data!.sellerName[locale].localeCompare(b.data!.sellerName[locale])).map(sellerDto => (
<SellerCard <SellerCard
editToken={sellerDto.editToken!} editToken={sellerDto.editToken}
locale={locale} locale={locale}
seller={sellerDto.data!} seller={sellerDto.data!}
/> />
@ -308,7 +308,7 @@ async function flatWalkSubCategories (productCategoryId: string): Promise<Conten
let editToken = productCategoryDto.editToken; let editToken = productCategoryDto.editToken;
return ( return (
<ProductCategoryCard <ProductCategoryCard
editToken={editToken!} editToken={editToken}
locale={locale} locale={locale}
productCategory={productCategoryDto.data!} productCategory={productCategoryDto.data!}
/> />
@ -333,7 +333,7 @@ async function flatWalkSubCategories (productCategoryId: string): Promise<Conten
let editToken = productDto.editToken; let editToken = productDto.editToken;
return ( return (
<ProductCard <ProductCard
editToken={editToken!} editToken={editToken}
locale={locale} locale={locale}
productDto={productDto} productDto={productDto}
/> />

View File

@ -1,5 +1,5 @@
--- ---
// import type { Brand } from '../data/brands/brand'; import type { Brand } from '../data/brands/brand';
// import { Swiper, SwiperSlide } from 'swiper/react'; // import { Swiper, SwiperSlide } from 'swiper/react';
// import { Navigation as SwiperNavigation, Pagination as SwiperPagination } from 'swiper/modules'; // import { Navigation as SwiperNavigation, Pagination as SwiperPagination } from 'swiper/modules';
import CarouselSwiper from './CarouselSwiper'; import CarouselSwiper from './CarouselSwiper';

View File

@ -25,7 +25,7 @@ const formatAsCurrency = (amount: number) => amount.toLocaleString(locale, { sty
const { productDto, editToken, locale } = Astro.props; const { productDto, editToken, locale } = Astro.props;
const product = productDto.items[0].data!; const product = productDto.items[0].data!;
let amazonConnectorSchemaId = (await core.client.schemas.getSchema({ schema: 'product-marketplace-connection-amazon' })).id; let amazonConnectorSchemaId = (await core.client.schemas.getSchema('product-marketplace-connection-amazon')).id;
let brandDto = (await getBrandsByIds(product.brand.iv[0])); let brandDto = (await getBrandsByIds(product.brand.iv[0]));
let possibleAmazonConnectors = product.marketplaceConnections.iv.filter((connection) => connection.connection.schemaId === amazonConnectorSchemaId); let possibleAmazonConnectors = product.marketplaceConnections.iv.filter((connection) => connection.connection.schemaId === amazonConnectorSchemaId);
let amazonConnector = possibleAmazonConnectors.length > 0 ? possibleAmazonConnectors[0].connection as AmazonMarketplaceConnection : undefined; let amazonConnector = possibleAmazonConnectors.length > 0 ? possibleAmazonConnectors[0].connection as AmazonMarketplaceConnection : undefined;

View File

@ -1,6 +1,6 @@
import * as core from "./core/client"; import * as core from "./core/client";
import { SCHEMAS } from "./models/schemas"; import { SCHEMAS } from "./models/schemas";
import { getAllContents } from "./core/client.js"; import { getContents } from "./core/client.js";
import { SupportedLocales, type Localized } from "./internals/LocalizedT.js"; import { SupportedLocales, type Localized } from "./internals/LocalizedT.js";
import type { Component } from "./internals/Component"; import type { Component } from "./internals/Component";
import type { Brand } from "./models/multis/Brand"; import type { Brand } from "./models/multis/Brand";
@ -14,6 +14,7 @@ import type { Slug } from "./models/multis/Slug";
import type { Seller } from "./models/multis/Seller"; import type { Seller } from "./models/multis/Seller";
import type { NonLocalized } from "./internals/NonLocalizedT.js"; import type { NonLocalized } from "./internals/NonLocalizedT.js";
import type { ContentsDto } from "./internals/ContentsDtoT"; import type { ContentsDto } from "./internals/ContentsDtoT";
import type { ContentData } from "@squidex/squidex/api/types/ContentData";
import type { ContentDto } from "./internals/ContentDtoT"; import type { ContentDto } from "./internals/ContentDtoT";
import type { Listing } from "./models/multis/Listing.js"; import type { Listing } from "./models/multis/Listing.js";
import type { Offer } from "./models/multis/Offer.js"; import type { Offer } from "./models/multis/Offer.js";
@ -143,7 +144,7 @@ export const getRedirectsByPreviousSlug = async (prevSlug: string) =>
/** Slugs handlers */ /** Slugs handlers */
export const getAllSlugs = async () => export const getAllSlugs = async () =>
await core.getAllContents<Slug>(SCHEMAS.SLUGS); await core.getContents<Slug>(SCHEMAS.SLUGS);
export const getSlugByLangSlug = async (forLang: SupportedLocales|string, slug: string) => export const getSlugByLangSlug = async (forLang: SupportedLocales|string, slug: string) =>
await core.getContentsUsingJsonQuery<Slug>(SCHEMAS.SLUGS, JSON.stringify({ await core.getContentsUsingJsonQuery<Slug>(SCHEMAS.SLUGS, JSON.stringify({
@ -158,7 +159,7 @@ export const getSlugByLangSlug = async (forLang: SupportedLocales|string, slug:
/** Site handlers */ /** Site handlers */
export const getSite = async () => export const getSite = async () =>
await getAllContents<Site>(SCHEMAS.SITE); await getContents<Site>(SCHEMAS.SITE);
export const getSiteHomePage = async (site: Site) => { export const getSiteHomePage = async (site: Site) => {
if (site.homePage && site.homePage.iv.length > 0) { if (site.homePage && site.homePage.iv.length > 0) {
@ -170,7 +171,7 @@ export const getSiteHomePage = async (site: Site) => {
} }
export const getSiteConfig = async () => export const getSiteConfig = async () =>
await getAllContents<SiteConfig>(SCHEMAS.SITE_CONFIG); await getContents<SiteConfig>(SCHEMAS.SITE_CONFIG);
export async function performSyncLocalizedSlugs(logFn = console.log) { export async function performSyncLocalizedSlugs(logFn = console.log) {
logFn("Begin sync localized slugs.") logFn("Begin sync localized slugs.")
@ -320,10 +321,10 @@ export async function performSyncLocalizedSlugs(logFn = console.log) {
}); });
const MAX_TIME_TO_POST_SLUGS = 60;//s const MAX_TIME_TO_POST_SLUGS = 60;//s
logFn("Add", batchAddSlugsQueue.length, "slugs"); logFn("Add", batchAddSlugsQueue.length, "slugs");
let bulkAddResult = await core.client.contents.postContents({ schema: SCHEMAS.SLUGS, importContentsDto: { datas: batchAddSlugsQueue as any, publish: true } }); let bulkAddResult = await core.client.contents.postContents(SCHEMAS.SLUGS, { datas: batchAddSlugsQueue as unknown as ContentData[], publish: true }, { timeoutInSeconds: MAX_TIME_TO_POST_SLUGS });
logFn("Remove by id", batchRemoveSlugsQueue.length, "slugs"); logFn("Remove by id", batchRemoveSlugsQueue.length, "slugs");
batchRemoveSlugsQueue.forEach(async (removeId) => { batchRemoveSlugsQueue.forEach(async (removeId) => {
await core.client.contents.deleteContent({ schema: SCHEMAS.SLUGS, id: removeId }) await core.client.contents.deleteContent(SCHEMAS.SLUGS, removeId)
}) })
logFn("Finish sync localized slugs.") logFn("Finish sync localized slugs.")
} }

View File

@ -1,8 +1,9 @@
import { config } from "../../config.js"; import { config } from "../../config.js";
import { SquidexClient } from "@squidex/squidex"; import { Squidex, SquidexClient } from "@squidex/squidex";
import type { ContentsDto } from "../internals/ContentsDtoT.js"; import type { ContentsDto } from "../internals/ContentsDtoT.js";
import type { SupportedLocales } from "../internals/LocalizedT.js"; import type { SupportedLocales } from "../internals/LocalizedT.js";
import type { SCHEMAS } from "../models/schemas.js"; import type { SCHEMAS } from "../models/schemas.js";
import type { Contents } from "@squidex/squidex/api/resources/contents/client/Client.js";
export const client = new SquidexClient({ export const client = new SquidexClient({
appName: config.squidexAppName!, appName: config.squidexAppName!,
@ -19,21 +20,21 @@ export const TIMEOUT_IN_SECONDS = 10;
/** Asset Handling */ /** Asset Handling */
export const getAssetById = async (assetId: string) => ( export const getAssetById = async (assetId: string) => (
await client.assets.getAsset({ id: assetId }) await client.assets.getAsset(assetId, {timeoutInSeconds: TIMEOUT_IN_SECONDS})
); );
/** Generic Content Handling */ /** Generic Content Handling */
export const getAllContents = async <T>(schema: SCHEMAS|string) => ( export const getContents = async <T>(schema: SCHEMAS|string) => (
await client.contents.getContents({ schema }) await client.contents.getContents(schema, { }, { timeoutInSeconds: TIMEOUT_IN_SECONDS })
) as ContentsDto<T>; ) as ContentsDto<T>;
export const getContentsByIds = async <T>(schema: SCHEMAS|string, ids: string) => ( export const getContentsByIds = async <T>(schema: SCHEMAS|string, ids: string) => (
await client.contents.getContents({ schema, ids }) await client.contents.getContents(schema, { ids }, { timeoutInSeconds: TIMEOUT_IN_SECONDS })
) as ContentsDto<T>; ) as ContentsDto<T>;
export const getContentsUsingJsonQuery = async <T>(schema: SCHEMAS|string, jsonQuery: string|undefined = undefined) => ( export const getContentsUsingJsonQuery = async <T>(schema: SCHEMAS|string, jsonQuery: string|undefined = undefined) => (
await client.contents.getContents({ schema, q: jsonQuery }) await client.contents.getContents(schema, { q: jsonQuery }, { timeoutInSeconds: TIMEOUT_IN_SECONDS })
) as ContentsDto<T>; ) as ContentsDto<T>;
export const getContentsByLangSlug = async <T>(schema: SCHEMAS|string, forLang: SupportedLocales|string, slug: string) => ( export const getContentsByLangSlug = async <T>(schema: SCHEMAS|string, forLang: SupportedLocales|string, slug: string) => (

View File

@ -1,5 +1,5 @@
import type { ContentDto as SquidexContentDto } from "@squidex/squidex"; import { Squidex } from "@squidex/squidex";
export interface ContentDto<T> extends SquidexContentDto { export interface ContentDto<T> extends Squidex.ContentDto {
data: T; data?: T;
} }

View File

@ -1,7 +1,7 @@
import type { ContentDto } from "./ContentDtoT"; import type { ContentDto } from "./ContentDtoT";
import type { ContentsDto as SquidexContentsDto } from "@squidex/squidex"; import { Squidex } from "@squidex/squidex";
export interface ContentsDto<T> extends SquidexContentsDto { export interface ContentsDto<T> extends Squidex.ContentsDto {
/** The generic content items. */ /** The generic content items. */
items: ContentDto<T>[]; items: ContentDto<T>[];
} }

View File

@ -64,7 +64,7 @@ const cssFixSquidex = `
<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script> <script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
<script src="https://code.jquery.com/ui/1.13.3/jquery-ui.min.js" integrity="sha256-sw0iNNXmOJbQhYFuC9OF2kOlD5KQKe1y5lfBn4C9Sjg=" crossorigin="anonymous"></script> <script src="https://code.jquery.com/ui/1.13.3/jquery-ui.min.js" integrity="sha256-sw0iNNXmOJbQhYFuC9OF2kOlD5KQKe1y5lfBn4C9Sjg=" crossorigin="anonymous"></script>
<script src="https://unpkg.com/htmx.org@1.9.9" integrity="sha384-QFjmbokDn2DjBjq+fM+8LUIVrAgqcNW2s0PjAxHETgRn9l4fvX31ZxDxvwQnyMOX" crossorigin="anonymous"></script> <script src="https://unpkg.com/htmx.org@1.9.9" integrity="sha384-QFjmbokDn2DjBjq+fM+8LUIVrAgqcNW2s0PjAxHETgRn9l4fvX31ZxDxvwQnyMOX" crossorigin="anonymous"></script>
<script is:inline src={bootstrap}></script> <script src={bootstrap}></script>
<link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Holtwood+One+SC&family=Caveat:wght@400..700&family=Noto+Sans:ital,wght@0,100..900;1,100..900&family=Urbanist:ital,wght@0,100..900;1,100..900&family=Saira+Extra+Condensed&display=swap" rel="stylesheet"> <link href="https://fonts.googleapis.com/css2?family=Holtwood+One+SC&family=Caveat:wght@400..700&family=Noto+Sans:ital,wght@0,100..900;1,100..900&family=Urbanist:ital,wght@0,100..900;1,100..900&family=Saira+Extra+Condensed&display=swap" rel="stylesheet">

View File

@ -140,7 +140,7 @@ try {
} }
} }
--- ---
<Layout locale={locale} title={title} site={site} siteConfig={siteConfig} siteEditToken={siteDto.items[0].editToken!} page={page as Page} shouldEmbedSquidexSDK={shouldEmbedSquidexSDK}> <Layout locale={locale} title={title} site={site} siteConfig={siteConfig} siteEditToken={siteDto.items[0].editToken} page={page as Page} shouldEmbedSquidexSDK={shouldEmbedSquidexSDK}>
<slot name="head"> <slot name="head">
<meta name="description" content={metaDescription} /> <meta name="description" content={metaDescription} />
{ {
@ -160,7 +160,7 @@ try {
<main> <main>
<Banner editToken={siteDto.items[0].editToken} homePageLink={`/${locale}/`} siteName={site.siteName[locale]} /> <Banner editToken={siteDto.items[0].editToken} homePageLink={`/${locale}/`} siteName={site.siteName[locale]} />
<ComponentRouter <ComponentRouter
pageEditToken={pageDto?.items[0].editToken!} pageEditToken={pageDto?.items[0].editToken}
componentRouter={getLocaleField(locale, page.content)||[]} componentRouter={getLocaleField(locale, page.content)||[]}
homePage={homePage as Page} homePage={homePage as Page}
isHomePage={isHomePage} isHomePage={isHomePage}

View File

@ -88,10 +88,9 @@ else {
console.log("redirectDto:", redirectDto); console.log("redirectDto:", redirectDto);
if (redirectDto && redirectDto.items && redirectDto.items.length > 0) { if (redirectDto && redirectDto.items && redirectDto.items.length > 0) {
console.log("getting redirectReferencesDto for", SCHEMAS.REDIRECTS, redirectDto.items[0].id); console.log("getting redirectReferencesDto for", SCHEMAS.REDIRECTS, redirectDto.items[0].id);
//next line crashes: let redirectReferencesDto = await client.contents.getReferences(SCHEMAS.REDIRECTS, redirectDto.items[0].id);
let redirectReferencesDto = await client.contents.getReferences({ schema: SCHEMAS.REDIRECTS, id: redirectDto.items[0].id });
console.log("redirectReferencesDto:", redirectReferencesDto); console.log("redirectReferencesDto:", redirectReferencesDto);
// client.contents.getConten client.contents.getConten
// switch (redirectDto.items[0].data?.referenceSchema.iv) { // switch (redirectDto.items[0].data?.referenceSchema.iv) {
// case SCHEMAS.BRANDS: // case SCHEMAS.BRANDS:
// return Astro.rewrite(`/view/brands/${locale}/${objectId}`); // return Astro.rewrite(`/view/brands/${locale}/${objectId}`);
@ -137,7 +136,7 @@ const renderContext = {
shouldEmbedSquidexSDK, shouldEmbedSquidexSDK,
} }
--- ---
<Layout locale={locale} title={title} site={site} siteConfig={siteConfig} siteEditToken={siteDto.items[0].editToken!} page={page} shouldEmbedSquidexSDK={shouldEmbedSquidexSDK}> <Layout locale={locale} title={title} site={site} siteConfig={siteConfig} siteEditToken={siteDto.items[0].editToken} page={page} shouldEmbedSquidexSDK={shouldEmbedSquidexSDK}>
<slot slot="head"> <slot slot="head">
{ metaDescription && <meta name="description" content={metaDescription} /> } { metaDescription && <meta name="description" content={metaDescription} /> }
{ {
@ -178,7 +177,7 @@ const renderContext = {
pageEditToken={pageEditToken} pageEditToken={pageEditToken}
brand={brand||undefined} brand={brand||undefined}
site={site} site={site}
siteEditToken={siteEditToken!} siteEditToken={siteEditToken}
/> />
</main> </main>
<slot name="disclaimers" slot="disclaimers"> <slot name="disclaimers" slot="disclaimers">

View File

@ -65,7 +65,7 @@ const renderContext = {
shouldEmbedSquidexSDK, shouldEmbedSquidexSDK,
} }
--- ---
<Layout locale={locale} title={title} site={site} siteConfig={siteConfig} siteEditToken={siteDto.items[0].editToken!} page={page} shouldEmbedSquidexSDK={shouldEmbedSquidexSDK}> <Layout locale={locale} title={title} site={site} siteConfig={siteConfig} siteEditToken={siteDto.items[0].editToken} page={page} shouldEmbedSquidexSDK={shouldEmbedSquidexSDK}>
<slot name="head"> <slot name="head">
{ metaDescription && <meta name="description" content={metaDescription} /> } { metaDescription && <meta name="description" content={metaDescription} /> }
{ {
@ -90,10 +90,10 @@ const renderContext = {
isHomePage={false} isHomePage={false}
locale={locale} locale={locale}
page={page} page={page}
pageEditToken={pageEditToken!} pageEditToken={pageEditToken}
brand={brand||undefined} brand={brand||undefined}
site={site} site={site}
siteEditToken={siteEditToken!} siteEditToken={siteEditToken}
/> />
</main> </main>
<span slot="disclaimers"> <span slot="disclaimers">

View File

@ -65,7 +65,7 @@ const renderContext = {
shouldEmbedSquidexSDK, shouldEmbedSquidexSDK,
} }
--- ---
<Layout locale={locale} title={title} site={site} siteConfig={siteConfig} siteEditToken={siteDto.items[0].editToken!} page={page} shouldEmbedSquidexSDK={shouldEmbedSquidexSDK}> <Layout locale={locale} title={title} site={site} siteConfig={siteConfig} siteEditToken={siteDto.items[0].editToken} page={page} shouldEmbedSquidexSDK={shouldEmbedSquidexSDK}>
<slot name="head"> <slot name="head">
{ metaDescription && <meta name="description" content={metaDescription} /> } { metaDescription && <meta name="description" content={metaDescription} /> }
{ {
@ -90,10 +90,10 @@ const renderContext = {
isHomePage={false} isHomePage={false}
locale={locale} locale={locale}
page={page} page={page}
pageEditToken={pageEditToken!} pageEditToken={pageEditToken}
marketplace={marketplace} marketplace={marketplace}
site={site} site={site}
siteEditToken={siteEditToken!} siteEditToken={siteEditToken}
/> />
</main> </main>
<span slot="disclaimers"> <span slot="disclaimers">

View File

@ -71,7 +71,7 @@ const renderContext = {
shouldEmbedSquidexSDK, shouldEmbedSquidexSDK,
} }
--- ---
<Layout locale={locale} title={title} site={site} siteConfig={siteConfig} siteEditToken={siteDto.items[0].editToken!} page={page} shouldEmbedSquidexSDK={shouldEmbedSquidexSDK}> <Layout locale={locale} title={title} site={site} siteConfig={siteConfig} siteEditToken={siteDto.items[0].editToken} page={page} shouldEmbedSquidexSDK={shouldEmbedSquidexSDK}>
<slot name="head"> <slot name="head">
{ metaDescription && <meta name="description" content={metaDescription} /> } { metaDescription && <meta name="description" content={metaDescription} /> }
{ {
@ -96,9 +96,9 @@ const renderContext = {
isHomePage={isHomePage} isHomePage={isHomePage}
locale={locale} locale={locale}
page={page} page={page}
pageEditToken={pageEditToken!} pageEditToken={pageEditToken}
site={site} site={site}
siteEditToken={siteEditToken!} siteEditToken={siteEditToken}
/> />
</main> </main>
<span slot="disclaimers"> <span slot="disclaimers">

View File

@ -66,7 +66,7 @@ const renderContext = {
shouldEmbedSquidexSDK, shouldEmbedSquidexSDK,
} }
--- ---
<Layout locale={locale} title={title} site={site} siteConfig={siteConfig} siteEditToken={siteDto.items[0].editToken!} page={page} shouldEmbedSquidexSDK={shouldEmbedSquidexSDK}> <Layout locale={locale} title={title} site={site} siteConfig={siteConfig} siteEditToken={siteDto.items[0].editToken} page={page} shouldEmbedSquidexSDK={shouldEmbedSquidexSDK}>
<slot name="head"> <slot name="head">
{ metaDescription && <meta name="description" content={metaDescription} /> } { metaDescription && <meta name="description" content={metaDescription} /> }
{ {
@ -91,11 +91,11 @@ const renderContext = {
isHomePage={false} isHomePage={false}
locale={locale} locale={locale}
page={page} page={page}
pageEditToken={pageEditToken!} pageEditToken={pageEditToken}
productCategory={productCategory} productCategory={productCategory}
brand={undefined} brand={undefined}
site={site} site={site}
siteEditToken={siteEditToken!} siteEditToken={siteEditToken}
/> />
</main> </main>
<span slot="disclaimers"> <span slot="disclaimers">

View File

@ -69,7 +69,7 @@ const renderContext = {
// disclaimers, // disclaimers,
} }
--- ---
<Layout locale={locale} title={title} site={site} siteConfig={siteConfig} siteEditToken={siteDto.items[0].editToken!} page={page} shouldEmbedSquidexSDK={shouldEmbedSquidexSDK}> <Layout locale={locale} title={title} site={site} siteConfig={siteConfig} siteEditToken={siteDto.items[0].editToken} page={page} shouldEmbedSquidexSDK={shouldEmbedSquidexSDK}>
<slot name="head"> <slot name="head">
{ metaDescription && <meta name="description" content={metaDescription} /> } { metaDescription && <meta name="description" content={metaDescription} /> }
{ {
@ -94,11 +94,11 @@ const renderContext = {
isHomePage={false} isHomePage={false}
locale={locale} locale={locale}
page={page} page={page}
pageEditToken={pageEditToken!} pageEditToken={pageEditToken}
productDto={productDto} productDto={productDto}
brand={undefined} brand={undefined}
site={site} site={site}
siteEditToken={siteEditToken!} siteEditToken={siteEditToken}
/> />
</main> </main>
<span slot="disclaimers"> <span slot="disclaimers">

View File

@ -65,7 +65,7 @@ const renderContext = {
shouldEmbedSquidexSDK, shouldEmbedSquidexSDK,
} }
--- ---
<Layout locale={locale} title={title} site={site} siteConfig={siteConfig} siteEditToken={siteDto.items[0].editToken!} page={page} shouldEmbedSquidexSDK={shouldEmbedSquidexSDK}> <Layout locale={locale} title={title} site={site} siteConfig={siteConfig} siteEditToken={siteDto.items[0].editToken} page={page} shouldEmbedSquidexSDK={shouldEmbedSquidexSDK}>
<slot name="head"> <slot name="head">
{ metaDescription && <meta name="description" content={metaDescription} /> } { metaDescription && <meta name="description" content={metaDescription} /> }
{ {
@ -90,10 +90,10 @@ const renderContext = {
isHomePage={false} isHomePage={false}
locale={locale} locale={locale}
page={page} page={page}
pageEditToken={pageEditToken!} pageEditToken={pageEditToken}
seller={seller} seller={seller}
site={site} site={site}
siteEditToken={siteEditToken!} siteEditToken={siteEditToken}
/> />
</main> </main>
<span slot="disclaimers"> <span slot="disclaimers">