From f7f147cfc196ce4cda31bd16d52a1a91b8ec00c2 Mon Sep 17 00:00:00 2001 From: David Ball Date: Sun, 25 Aug 2024 23:48:09 -0400 Subject: [PATCH 1/5] Updated page template. --- package-lock.json | 8 ++++++++ package.json | 2 ++ src/components/Content.astro | 9 ++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index 2fecd27..3c05d20 100644 --- a/package-lock.json +++ b/package-lock.json @@ -32,6 +32,7 @@ "markdown-it": "^14.0.0", "markdown-it-attrs": "^4.1.6", "memfs": "^4.11.1", + "mime-types": "^2.1.35", "multer": "^1.4.5-lts.1", "ollama": "^0.5.8", "playwright": "*", @@ -49,6 +50,7 @@ "@types/luxon": "^3.4.2", "@types/markdown-it": "^14.1.1", "@types/markdown-it-attrs": "^4.1.3", + "@types/mime-types": "^2.1.4", "@types/multer": "^1.4.11", "@types/node": "^20.0.0", "ts-node": "^10.9.2", @@ -2829,6 +2831,12 @@ "integrity": "sha512-/pyBZWSLD2n0dcHE3hq8s8ZvcETHtEuF+3E7XVt0Ig2nvsVQXdghHVcEkIWjy9A0wKfTn97a/PSDYohKIlnP/w==", "dev": true }, + "node_modules/@types/mime-types": { + "version": "2.1.4", + "resolved": "https://registry.npmjs.org/@types/mime-types/-/mime-types-2.1.4.tgz", + "integrity": "sha512-lfU4b34HOri+kAY5UheuFMWPDOI+OPceBSHZKp69gEyTL/mmJ4cnU6Y/rlme3UL3GyOn6Y42hyIEw0/q8sWx5w==", + "dev": true + }, "node_modules/@types/ms": { "version": "0.7.34", "resolved": "https://registry.npmjs.org/@types/ms/-/ms-0.7.34.tgz", diff --git a/package.json b/package.json index 27197dd..44d3aed 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "markdown-it": "^14.0.0", "markdown-it-attrs": "^4.1.6", "memfs": "^4.11.1", + "mime-types": "^2.1.35", "multer": "^1.4.5-lts.1", "ollama": "^0.5.8", "playwright": "*", @@ -56,6 +57,7 @@ "@types/luxon": "^3.4.2", "@types/markdown-it": "^14.1.1", "@types/markdown-it-attrs": "^4.1.3", + "@types/mime-types": "^2.1.4", "@types/multer": "^1.4.11", "@types/node": "^20.0.0", "ts-node": "^10.9.2", diff --git a/src/components/Content.astro b/src/components/Content.astro index 8554570..856a8af 100644 --- a/src/components/Content.astro +++ b/src/components/Content.astro @@ -14,7 +14,8 @@ const { editToken, text } = Astro.props; .content { margin-bottom: 2rem; border: 1px solid rgba(var(--accent-light), 25%); - background: linear-gradient(rgba(var(--accent-dark), 66%), rgba(var(--accent-dark), 33%)); + /* background: linear-gradient(rgba(var(--accent-dark), 66%), rgba(var(--accent-dark), 33%)); */ + background-color: #13151a; padding: 0.5rem; border-radius: 8px; font-family: "Urbanist", sans-serif; @@ -23,4 +24,10 @@ const { editToken, text } = Astro.props; } a, a:link, a:visited { text-decoration: none; color: #fff } a:hover { text-decoration: underline; color: #fff } + + + \ No newline at end of file From 1ce08dbe40487785e33dd2206250e3bef6f7abbd Mon Sep 17 00:00:00 2001 From: David Ball Date: Mon, 26 Aug 2024 01:35:09 -0400 Subject: [PATCH 2/5] Patch Squidex Markdown editor image src paths to render as paths within our app. --- src/config.ts | 4 ++-- src/lib/rendering.ts | 7 +++++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/config.ts b/src/config.ts index 25231a6..4a78938 100644 --- a/src/config.ts +++ b/src/config.ts @@ -78,8 +78,8 @@ export const getWebhookPort = () => env.WEBHOOK_PORT ? parseInt(env.WEBHOOK_PORT export const getSquidexAppName = () => env.SQUIDEX_APP_NAME || undefined; export const getSquidexClientId = () => env.SQUIDEX_CLIENT_ID || undefined; export const getSquidexClientSecret = () => env.SQUIDEX_CLIENT_SECRET || undefined; -export const getSquidexEnvironment = () => env.SQUIDEX_ENVIRONMENT || undefined; -export const getSquidexPublicUrl = () => env.SQUIDEX_PUBLIC_URL || getSquidexEnvironment(); +export const getSquidexEnvironment = () => trimSlashes(env.SQUIDEX_ENVIRONMENT||'') || undefined; +export const getSquidexPublicUrl = () => trimSlashes(env.SQUIDEX_PUBLIC_URL||'') || getSquidexEnvironment(); export const config: Config = { // AmazonProductAdvertisingAPIAccessKey: getAmazonProductAdvertisingAPIAccessKey(), diff --git a/src/lib/rendering.ts b/src/lib/rendering.ts index 804253d..3fa450f 100644 --- a/src/lib/rendering.ts +++ b/src/lib/rendering.ts @@ -1,6 +1,7 @@ import markdownIt from "markdown-it"; import markdownItAttrs from "markdown-it-attrs"; import vm from 'node:vm'; +import { config } from "../config"; export const md = markdownIt().use(markdownItAttrs, { }); @@ -67,9 +68,15 @@ const renderCodeblock = (lang: string, template: string, templateContext?: any) return template; } +const replaceSquidexAssetPathWithOwn = (html: string) => { + let re = new RegExp(`src\\s*=\\s*["']${config.squidexPublicUrl?.replaceAll(`/`, `\\/`).replaceAll(`.`, `\\.`)||''}\\/api\\/assets/${config.squidexAppName||''}/([\\w-\\.\\/]*)["']`, 'g'); + return html.replaceAll(re, `src="${config.siteUrl}/img/$1"`); +} + export const renderMarkdown = (template: string, templateContext?: any) => { // render code blocks inside of the Markdown template = renderCodeblock('markdown', template, templateContext); template = md.render(interpolateString(template, templateContext)); + template = replaceSquidexAssetPathWithOwn(template); return template; } \ No newline at end of file From c2ffefe251a7d69450e2ae57fefdcb5711e600ec Mon Sep 17 00:00:00 2001 From: David Ball Date: Mon, 26 Aug 2024 03:36:04 -0400 Subject: [PATCH 3/5] Set up redirects from old URLs to new URLs --- src/data/models/multis/Redirect.ts | 1 + src/pages/[...routeLookup].astro | 35 ++++++++++++++---------------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/src/data/models/multis/Redirect.ts b/src/data/models/multis/Redirect.ts index 915be57..7fa6283 100644 --- a/src/data/models/multis/Redirect.ts +++ b/src/data/models/multis/Redirect.ts @@ -3,4 +3,5 @@ import type { NonLocalized } from "../../internals/NonLocalizedT"; export interface Redirect { prevSlug: NonLocalized, newContent: NonLocalized, + newContentSchema: NonLocalized<{ schemaName: string }[]>, } \ No newline at end of file diff --git a/src/pages/[...routeLookup].astro b/src/pages/[...routeLookup].astro index 665d849..1ec9485 100644 --- a/src/pages/[...routeLookup].astro +++ b/src/pages/[...routeLookup].astro @@ -87,27 +87,24 @@ else { const redirectDto = await getRedirectsByPreviousSlug(routeLookup!); console.log("redirectDto:", redirectDto); 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].data?.newContentSchema[locale]); + // let objectId = redirectDto.items[0].data.newContent[locale]; //next line crashes: - let redirectReferencesDto = await client.contents.getReferences({ schema: SCHEMAS.REDIRECTS, id: redirectDto.items[0].id }); - console.log("redirectReferencesDto:", redirectReferencesDto); + // let redirectReferencesDto = await client.contents.getReferences({ schema: SCHEMAS.REDIRECTS, id: redirectDto.items[0].id }); + let schemaName = redirectDto.items[0].data?.newContentSchema[locale][0].schemaName; + let whicheverDto = await client.contents.getContent({schema: schemaName, id: redirectDto.items[0].data?.newContent[locale][0]}); + // console.log("redirectReferencesDto:", redirectReferencesDto); // client.contents.getConten - // switch (redirectDto.items[0].data?.referenceSchema.iv) { - // case SCHEMAS.BRANDS: - // return Astro.rewrite(`/view/brands/${locale}/${objectId}`); - // case SCHEMAS.MARKETPLACES: - // return Astro.rewrite(`/view/marketplaces/${locale}/${objectId}`); - // case SCHEMAS.PAGES: - // return Astro.rewrite(`/view/pages/${locale}/${objectId}`); - // case SCHEMAS.PRODUCT_CATEGORIES: - // return Astro.rewrite(`/view/product-categories/${locale}/${objectId}`); - // case SCHEMAS.PRODUCTS: - // return Astro.rewrite(`/view/products/${locale}/${objectId}`); - // case SCHEMAS.SELLERS: - // return Astro.rewrite(`/view/sellers/${locale}/${objectId}`); - // } - // Astro.response.headers.set('Vary', 'Accept-Language'); - // return Astro.redirect(,303) + switch (schemaName) { + case SCHEMAS.BRANDS: + case SCHEMAS.MARKETPLACES: + case SCHEMAS.PAGES: + case SCHEMAS.PRODUCT_CATEGORIES: + case SCHEMAS.PRODUCTS: + case SCHEMAS.SELLERS: + Astro.response.headers.set('Vary', 'Accept-Language'); + return Astro.redirect(`/${whicheverDto.data.slug[locale]}`, 303); + } } return redirect404NotFound(); } From eb4e0f7f2e8442cba728eded8489f116ba790ab3 Mon Sep 17 00:00:00 2001 From: David Ball Date: Mon, 26 Aug 2024 17:36:29 -0400 Subject: [PATCH 4/5] fix: Some of the release candidate API interface changes were reverted on the upstream. --- src/apiclient/override-squidex-sdk.ts | 104 ---------------- .../catalog/amazon/amazon-append-images.ts | 7 +- src/apps/catalog/common/catalog-helpers.ts | 114 +++++++----------- src/data/api-client.ts | 8 +- src/data/core/client.ts | 11 +- src/lib/page-from-models.ts | 6 +- src/scraper/amazon.ts | 4 +- 7 files changed, 63 insertions(+), 191 deletions(-) delete mode 100644 src/apiclient/override-squidex-sdk.ts diff --git a/src/apiclient/override-squidex-sdk.ts b/src/apiclient/override-squidex-sdk.ts deleted file mode 100644 index 1871946..0000000 --- a/src/apiclient/override-squidex-sdk.ts +++ /dev/null @@ -1,104 +0,0 @@ -import { Assets } from "@squidex/squidex/api/resources/assets/client/Client.js" -import { SquidexClient } from "@squidex/squidex" -import * as environments from "@squidex/squidex/environments.js"; -import * as core from "@squidex/squidex/core/index.js"; -import { Squidex } from "@squidex/squidex"; -import urlJoin from "url-join"; -import * as errors from "@squidex/squidex/errors/index.js"; -import * as serializers from "@squidex/squidex/serialization/index.js"; -import * as fs from "fs"; -import { default as FormData } from "form-data"; - - -/** - * You can only upload one file at a time. The mime type of the file is not calculated by Squidex and is required correctly. - * @throws {@link Squidex.BadRequestError} - * @throws {@link Squidex.NotFoundError} - * @throws {@link Squidex.ContentTooLargeError} - * @throws {@link Squidex.InternalServerError} - */ -export function async customPostAsset( - file: File | fs.ReadStream, - requestOptions?: Assets.RequestOptions -): Promise { - const _request = new FormData(); - _request.append("file", file); - const _response = await (this._options.fetcher ?? core.fetcher)({ - url: urlJoin( - (await core.Supplier.get(this._options.environment)) ?? environments.SquidexEnvironment.Default, - `api/apps/${this._options.appName}/assets` - ), - method: "POST", - headers: { - Authorization: await this._getAuthorizationHeader(), - "X-Fern-Language": "JavaScript", - "X-Fern-SDK-Name": "@squidex/squidex", - "X-Fern-SDK-Version": "1.2.1", - "Content-Length": (await core.getFormDataContentLength(_request)).toString(), - }, - contentType: "multipart/form-data; boundary=" + _request.getBoundary(), - body: _request, - timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, - }); - if (_response.ok) { - return await serializers.AssetDto.parseOrThrow(_response.body, { - unrecognizedObjectKeys: "passthrough", - allowUnrecognizedUnionMembers: true, - allowUnrecognizedEnumValues: true, - breadcrumbsPrefix: ["response"], - }); - } - - if (_response.error.reason === "status-code") { - switch (_response.error.statusCode) { - case 400: - throw new Squidex.BadRequestError( - await serializers.ErrorDto.parseOrThrow(_response.error.body, { - unrecognizedObjectKeys: "passthrough", - allowUnrecognizedUnionMembers: true, - allowUnrecognizedEnumValues: true, - breadcrumbsPrefix: ["response"], - }) - ); - case 404: - throw new Squidex.NotFoundError(_response.error.body); - case 413: - throw new Squidex.ContentTooLargeError( - await serializers.ErrorDto.parseOrThrow(_response.error.body, { - unrecognizedObjectKeys: "passthrough", - allowUnrecognizedUnionMembers: true, - allowUnrecognizedEnumValues: true, - breadcrumbsPrefix: ["response"], - }) - ); - case 500: - throw new Squidex.InternalServerError( - await serializers.ErrorDto.parseOrThrow(_response.error.body, { - unrecognizedObjectKeys: "passthrough", - allowUnrecognizedUnionMembers: true, - allowUnrecognizedEnumValues: true, - breadcrumbsPrefix: ["response"], - }) - ); - default: - throw new errors.SquidexError({ - statusCode: _response.error.statusCode, - body: _response.error.body, - }); - } - } - - switch (_response.error.reason) { - case "non-json": - throw new errors.SquidexError({ - statusCode: _response.error.statusCode, - body: _response.error.rawBody, - }); - case "timeout": - throw new errors.SquidexTimeoutError(); - case "unknown": - throw new errors.SquidexError({ - message: _response.error.errorMessage, - }); - } -}; \ No newline at end of file diff --git a/src/apps/catalog/amazon/amazon-append-images.ts b/src/apps/catalog/amazon/amazon-append-images.ts index 3edfec7..2e2cc00 100644 --- a/src/apps/catalog/amazon/amazon-append-images.ts +++ b/src/apps/catalog/amazon/amazon-append-images.ts @@ -4,6 +4,7 @@ import { getAllAssetsInFolder, isValidASIN, uploadDownloadedImageToSquidexAsAsse import { getMarketplacesUsingJsonQuery, getProductListingsUsingJsonQuery, getProductsUsingJsonQuery } from "../../../data/api-client"; import { SCHEMAS } from "../../../data/models/schemas"; import { logForCommand } from "../common/console"; +import type { ContentsPutContentRequest } from "@squidex/squidex/dist/generated/apis/ContentsApi"; export const COMMAND_NAME = 'append-images'; @@ -97,12 +98,10 @@ export const amazonAppendImagesCommand = (amazonCommand: Command) => } if (didUpdate) { log(`Listing did update, updating product listing with appended images.`); - let updatedDto = await core.client.contents.putContent({ - schema: SCHEMAS.LISTINGS, - id: listingDto.id, + let updatedDto = await core.client.contents.putContent(SCHEMAS.LISTINGS, listingDto.id, { unpublished: false, requestBody: listing as any, - }); + } as ContentsPutContentRequest as any); log(`Listing version ${updatedDto.version} stored.`); } } diff --git a/src/apps/catalog/common/catalog-helpers.ts b/src/apps/catalog/common/catalog-helpers.ts index 70e0ded..aeb0e6e 100644 --- a/src/apps/catalog/common/catalog-helpers.ts +++ b/src/apps/catalog/common/catalog-helpers.ts @@ -28,7 +28,7 @@ export function isValidASIN(asinOrNot: string) { } 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[]) { @@ -48,21 +48,17 @@ export async function lookupAmazonASINs(asins: string[]) { ] } }, requestDate: { iv: requestDate } } - let amazonGetItemDto = await client.contents.postContent({ - schema: SCHEMAS.AMAZON_GET_ITEMS, - publish: true, - requestBody: amazonGetItem as any, - }) + let amazonGetItemDto = await client.contents.postContent(SCHEMAS.AMAZON_GET_ITEMS, { ...amazonGetItem }, { publish: true }) let amazonGetItemsDto = await getContentsByIds(SCHEMAS.AMAZON_GET_ITEMS, amazonGetItemDto.id); return amazonGetItemsDto; } 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() { - return await client.schemas.getSchema({ schema: 'product-marketplace-connection-amazon' }) + return await client.schemas.getSchema('product-marketplace-connection-amazon') } export async function getAmazonMarketplaceDto() { @@ -100,22 +96,19 @@ export async function getBrandDtoByName(brandName: string) { } export async function getAddNewBrandDtoByName(brandName: string) { - let brandDto = await client.contents.postContent({ - schema: SCHEMAS.BRANDS, - requestBody: { - brandName: { - "en-US": brandName!, - "es-US": brandName!, - "fr-CA": brandName! - }, - slug: { - "en-US": `en-US/${slugify(brandName!, { lower: true, trim: true })}`, - "es-US": `es-US/${slugify(brandName!, { lower: true, trim: true })}`, - "fr-CA": `fr-CA/${slugify(brandName!, { lower: true, trim: true })}` - }, - } + let brandDto = await client.contents.postContent(SCHEMAS.BRANDS, { + brandName: { + "en-US": brandName!, + "es-US": brandName!, + "fr-CA": brandName! + }, + slug: { + "en-US": `en-US/${slugify(brandName!, { lower: true, trim: true })}`, + "es-US": `es-US/${slugify(brandName!, { lower: true, trim: true })}`, + "fr-CA": `fr-CA/${slugify(brandName!, { lower: true, trim: true })}` + }, }); - let brandsDto = await client.contents.getContents({ schema: SCHEMAS.BRANDS, unpublished: true, ids: brandDto.id }) as ContentsDto; + let brandsDto = await client.contents.getContents(SCHEMAS.BRANDS, { unpublished: true, ids: brandDto.id }) as ContentsDto; return brandsDto; } @@ -130,22 +123,19 @@ export async function getSellerDtoByName(sellerName: string) { } export async function getAddNewSellerDtoByName(sellerName: string) { - let sellerDto = await client.contents.postContent({ - schema: SCHEMAS.SELLERS, - requestBody: { - sellerName: { - "en-US": sellerName!, - "es-US": sellerName!, - "fr-CA": sellerName! - }, - slug: { - "en-US": `en-US/${slugify(sellerName!, { lower: true, trim: true })}`, - "es-US": `es-US/${slugify(sellerName!, { lower: true, trim: true })}`, - "fr-CA": `fr-CA/${slugify(sellerName!, { lower: true, trim: true })}` - }, - } + let sellerDto = await client.contents.postContent(SCHEMAS.SELLERS, { + sellerName: { + "en-US": sellerName!, + "es-US": sellerName!, + "fr-CA": sellerName! + }, + slug: { + "en-US": `en-US/${slugify(sellerName!, { lower: true, trim: true })}`, + "es-US": `es-US/${slugify(sellerName!, { lower: true, trim: true })}`, + "fr-CA": `fr-CA/${slugify(sellerName!, { lower: true, trim: true })}` + }, }); - let sellersDto = await client.contents.getContents({ schema: SCHEMAS.SELLERS, unpublished: true, ids: sellerDto.id }) as ContentsDto; + let sellersDto = await client.contents.getContents(SCHEMAS.SELLERS, { unpublished: true, ids: sellerDto.id }) as ContentsDto; return sellersDto; } @@ -408,16 +398,14 @@ export async function translateTags_from_en_US_to_fr_CA(tags_en_US: string[]) { } export async function getAddNewProductSubCategoryDto(parentProductCategoryId: NonLocalized, categoryName: Localized, description: Localized) { - let productCategoryDto = await client.contents.postContent({ - schema: SCHEMAS.PRODUCT_CATEGORIES, + let productCategoryDto = await client.contents.postContent(SCHEMAS.PRODUCT_CATEGORIES, { + categoryName, + description, + parentCategory: parentProductCategoryId, + }, { publish: false, - requestBody: { - categoryName, - description, - parentCategory: parentProductCategoryId, - }, }); - let productCategoriesDto = await client.contents.getContents({ schema: SCHEMAS.PRODUCT_CATEGORIES, unpublished: true, ids: productCategoryDto.id }) as ContentsDto; + let productCategoriesDto = await client.contents.getContents(SCHEMAS.PRODUCT_CATEGORIES, { unpublished: true, ids: productCategoryDto.id }) as ContentsDto; return productCategoriesDto; } @@ -448,26 +436,16 @@ export async function translateAmazonDescription_from_en_US_to_fr_CA(brandName: } export async function getAddNewProductDtoByProduct(product: Product) { - let productDto = await client.contents.postContent({ - schema: SCHEMAS.PRODUCTS, - publish: false, - requestBody: { - ...product - }, - }); - let productsDto = await client.contents.getContents({ schema: SCHEMAS.PRODUCTS, unpublished: true, ids: productDto.id }) as ContentsDto; + let productDto = await client.contents.postContent(SCHEMAS.PRODUCTS, { ...product }, { publish: false }); + let productsDto = await client.contents.getContents(SCHEMAS.PRODUCTS, { unpublished: true, ids: productDto.id }) as ContentsDto; return productsDto; } export async function getAddNewProductListingDtoByProduct(listing: Listing) { - let listingDto = await client.contents.postContent({ - schema: SCHEMAS.LISTINGS, + let listingDto = await client.contents.postContent(SCHEMAS.LISTINGS, { ...listing }, { publish: true, - requestBody: { - ...listing - } }); - let listingsDto = await client.contents.getContents({ schema: SCHEMAS.LISTINGS, unpublished: true, ids: listingDto.id }) as ContentsDto; + let listingsDto = await client.contents.getContents(SCHEMAS.LISTINGS, { unpublished: true, ids: listingDto.id }) as ContentsDto; return listingsDto; } @@ -484,7 +462,7 @@ export async function upsertAssetFolder(folderName: string, parentFolderId?: str let assetFolder; let assetFolderLookup = assetFolders.items.filter(folder => folder.folderName === folderName); if (assetFolderLookup.length === 0) { - assetFolder = await client.assets.postAssetFolder({ createAssetFolderDto: { folderName: folderName, parentId: parentFolderId }}); + assetFolder = await client.assets.postAssetFolder({ folderName: folderName, parentId: parentFolderId }); } else { assetFolder = assetFolderLookup[0]; @@ -506,20 +484,14 @@ export async function uploadDownloadedImageToSquidexAsAsset(downloadUrl: string, form.append('fileName', filename); 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'] } }) + let assetDto = await client.assets.postAsset({ file: blob, name: filename, url: filename, parentId: assetFolderId }, { body: form }); + assetDto = await client.assets.putAsset(assetDto.id, { metadata: { ...assetDto.metadata, 'amazon-url': downloadUrl }, tags: ['amazon', 'product'] }); // assetDto = await client.assets.putAssetParent({ id: assetDto.id, moveAssetDto: { parentId: assetFolderId } }); return assetDto; } export async function getAddNewOfferDto(offer: Offer) { - let offerDto = await client.contents.postContent({ - schema: SCHEMAS.OFFERS, - publish: true, - requestBody: offer as any, - }); - let offersDto = await client.contents.getContents({ schema: SCHEMAS.OFFERS, unpublished: true, ids: offerDto.id }) as ContentsDto; + let offerDto = await client.contents.postContent(SCHEMAS.OFFERS, { ...offer }, { publish: true }); + let offersDto = await client.contents.getContents(SCHEMAS.OFFERS, { unpublished: true, ids: offerDto.id }) as ContentsDto; return offersDto; } diff --git a/src/data/api-client.ts b/src/data/api-client.ts index 07551a0..4716f08 100644 --- a/src/data/api-client.ts +++ b/src/data/api-client.ts @@ -320,10 +320,14 @@ export async function performSyncLocalizedSlugs(logFn = console.log) { }); const MAX_TIME_TO_POST_SLUGS = 60;//s logFn("Add", batchAddSlugsQueue.length, "slugs"); - let bulkAddResult = await core.client.contents.postContents({ schema: SCHEMAS.SLUGS, importContentsDto: { datas: batchAddSlugsQueue as any, publish: true } }); + //postContents is deprecated, will loop with postContent + let bulkAddResult = [];//await core.client.contents.postContents(SCHEMAS.SLUGS, { datas: batchAddSlugsQueue as any, publish: true }); + for (let bar = 0; bar < batchAddSlugsQueue.length; bar++) { + bulkAddResult.push(await core.client.contents.postContent(SCHEMAS.SLUGS, batchAddSlugsQueue[bar] as any, { publish: true })); + } logFn("Remove by id", batchRemoveSlugsQueue.length, "slugs"); 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.") } diff --git a/src/data/core/client.ts b/src/data/core/client.ts index e8bc92e..e0ea15c 100644 --- a/src/data/core/client.ts +++ b/src/data/core/client.ts @@ -1,5 +1,6 @@ import { config } from "../../config.js"; import { SquidexClient } from "@squidex/squidex"; +import { InMemoryTokenStore } from "@squidex/squidex/dist/wrapper/SquidexClient.js"; import type { ContentsDto } from "../internals/ContentsDtoT.js"; import type { SupportedLocales } from "../internals/LocalizedT.js"; import type { SCHEMAS } from "../models/schemas.js"; @@ -9,7 +10,7 @@ export const client = new SquidexClient({ clientId: config.squidexClientId!, clientSecret: config.squidexClientSecret!, environment: config.squidexEnvironment!, - tokenStore: new SquidexClient.InMemoryTokenStore(), + tokenStore: new InMemoryTokenStore(), // tokenStore: new SquidexStorageTokenStore() // Keep the tokens in the local store. // tokenStore: new SquidexStorageTokenStore(sessionStorage, "CustomKey") }); @@ -19,21 +20,21 @@ export const TIMEOUT_IN_SECONDS = 10; /** Asset Handling */ export const getAssetById = async (assetId: string) => ( - await client.assets.getAsset({ id: assetId }) + await client.assets.getAsset(assetId) ); /** Generic Content Handling */ export const getAllContents = async (schema: SCHEMAS|string) => ( - await client.contents.getContents({ schema }) + await client.contents.getContents(schema, { }) ) as ContentsDto; export const getContentsByIds = async (schema: SCHEMAS|string, ids: string) => ( - await client.contents.getContents({ schema, ids }) + await client.contents.getContents(schema, { ids }) ) as ContentsDto; export const getContentsUsingJsonQuery = async (schema: SCHEMAS|string, jsonQuery: string|undefined = undefined) => ( - await client.contents.getContents({ schema, q: jsonQuery }) + await client.contents.getContents(schema, { q: jsonQuery }) ) as ContentsDto; export const getContentsByLangSlug = async (schema: SCHEMAS|string, forLang: SupportedLocales|string, slug: string) => ( diff --git a/src/lib/page-from-models.ts b/src/lib/page-from-models.ts index ad969b8..40ca5a7 100644 --- a/src/lib/page-from-models.ts +++ b/src/lib/page-from-models.ts @@ -76,7 +76,7 @@ export const genericPageForBrand = ({ brand, brandId, homePageId }: PageForBrand schemaId: '', schemaName: '', keywords: brand.brandName['en-US'], - metaDescription: brand.shortDescription['en-US'], + metaDescription: brand.shortDescription!['en-US'], metaImage: '', metaSocial: [], metaTitle: brand.brandName['en-US'], @@ -85,7 +85,7 @@ export const genericPageForBrand = ({ brand, brandId, homePageId }: PageForBrand schemaId: '', schemaName: '', keywords: brand.brandName['es-US'], - metaDescription: brand.shortDescription['es-US'], + metaDescription: brand.shortDescription!['es-US'], metaImage: '', metaSocial: [], metaTitle: brand.brandName['es-US'], @@ -94,7 +94,7 @@ export const genericPageForBrand = ({ brand, brandId, homePageId }: PageForBrand schemaId: '', schemaName: '', keywords: brand.brandName['fr-CA'], - metaDescription: brand.shortDescription['fr-CA'], + metaDescription: brand.shortDescription!['fr-CA'], metaImage: '', metaSocial: [], metaTitle: brand.brandName['fr-CA'], diff --git a/src/scraper/amazon.ts b/src/scraper/amazon.ts index 14ec63c..5539589 100644 --- a/src/scraper/amazon.ts +++ b/src/scraper/amazon.ts @@ -3,8 +3,8 @@ */ import cheerio, { type CheerioAPI } from 'cheerio'; -import { type AmazonProductDetails } from '../data/products/amazon-product-details'; -import { type ProductAttribute } from '../data/products/product-attribute'; +import { type AmazonProductDetails } from '../old-data/products/amazon-product-details'; +import { type ProductAttribute } from '../old-data/products/product-attribute'; import { parseNumberFromSelector } from './utils'; /** From caa0d93d91ebddc87747c7901e87993439f43f01 Mon Sep 17 00:00:00 2001 From: David Ball Date: Mon, 26 Aug 2024 18:15:53 -0400 Subject: [PATCH 5/5] Revert "Merge pull request 'fix: Some of the release candidate API interface changes were reverted on the upstream.' (#6) from openapi-sdk-migration into main" This reverts commit 2b87f45069152442ce64ede6305aa1cbd358b1e5, reversing changes made to c2a0633f2b0aae10d44e7e36817ac2742b24e654. There was a forced update on the branch. --- src/apiclient/override-squidex-sdk.ts | 104 ++++++++++++++++ .../catalog/amazon/amazon-append-images.ts | 7 +- src/apps/catalog/common/catalog-helpers.ts | 114 +++++++++++------- src/data/api-client.ts | 8 +- src/data/core/client.ts | 11 +- src/lib/page-from-models.ts | 6 +- src/scraper/amazon.ts | 4 +- 7 files changed, 191 insertions(+), 63 deletions(-) create mode 100644 src/apiclient/override-squidex-sdk.ts diff --git a/src/apiclient/override-squidex-sdk.ts b/src/apiclient/override-squidex-sdk.ts new file mode 100644 index 0000000..1871946 --- /dev/null +++ b/src/apiclient/override-squidex-sdk.ts @@ -0,0 +1,104 @@ +import { Assets } from "@squidex/squidex/api/resources/assets/client/Client.js" +import { SquidexClient } from "@squidex/squidex" +import * as environments from "@squidex/squidex/environments.js"; +import * as core from "@squidex/squidex/core/index.js"; +import { Squidex } from "@squidex/squidex"; +import urlJoin from "url-join"; +import * as errors from "@squidex/squidex/errors/index.js"; +import * as serializers from "@squidex/squidex/serialization/index.js"; +import * as fs from "fs"; +import { default as FormData } from "form-data"; + + +/** + * You can only upload one file at a time. The mime type of the file is not calculated by Squidex and is required correctly. + * @throws {@link Squidex.BadRequestError} + * @throws {@link Squidex.NotFoundError} + * @throws {@link Squidex.ContentTooLargeError} + * @throws {@link Squidex.InternalServerError} + */ +export function async customPostAsset( + file: File | fs.ReadStream, + requestOptions?: Assets.RequestOptions +): Promise { + const _request = new FormData(); + _request.append("file", file); + const _response = await (this._options.fetcher ?? core.fetcher)({ + url: urlJoin( + (await core.Supplier.get(this._options.environment)) ?? environments.SquidexEnvironment.Default, + `api/apps/${this._options.appName}/assets` + ), + method: "POST", + headers: { + Authorization: await this._getAuthorizationHeader(), + "X-Fern-Language": "JavaScript", + "X-Fern-SDK-Name": "@squidex/squidex", + "X-Fern-SDK-Version": "1.2.1", + "Content-Length": (await core.getFormDataContentLength(_request)).toString(), + }, + contentType: "multipart/form-data; boundary=" + _request.getBoundary(), + body: _request, + timeoutMs: requestOptions?.timeoutInSeconds != null ? requestOptions.timeoutInSeconds * 1000 : 60000, + }); + if (_response.ok) { + return await serializers.AssetDto.parseOrThrow(_response.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }); + } + + if (_response.error.reason === "status-code") { + switch (_response.error.statusCode) { + case 400: + throw new Squidex.BadRequestError( + await serializers.ErrorDto.parseOrThrow(_response.error.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }) + ); + case 404: + throw new Squidex.NotFoundError(_response.error.body); + case 413: + throw new Squidex.ContentTooLargeError( + await serializers.ErrorDto.parseOrThrow(_response.error.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }) + ); + case 500: + throw new Squidex.InternalServerError( + await serializers.ErrorDto.parseOrThrow(_response.error.body, { + unrecognizedObjectKeys: "passthrough", + allowUnrecognizedUnionMembers: true, + allowUnrecognizedEnumValues: true, + breadcrumbsPrefix: ["response"], + }) + ); + default: + throw new errors.SquidexError({ + statusCode: _response.error.statusCode, + body: _response.error.body, + }); + } + } + + switch (_response.error.reason) { + case "non-json": + throw new errors.SquidexError({ + statusCode: _response.error.statusCode, + body: _response.error.rawBody, + }); + case "timeout": + throw new errors.SquidexTimeoutError(); + case "unknown": + throw new errors.SquidexError({ + message: _response.error.errorMessage, + }); + } +}; \ No newline at end of file diff --git a/src/apps/catalog/amazon/amazon-append-images.ts b/src/apps/catalog/amazon/amazon-append-images.ts index 2e2cc00..3edfec7 100644 --- a/src/apps/catalog/amazon/amazon-append-images.ts +++ b/src/apps/catalog/amazon/amazon-append-images.ts @@ -4,7 +4,6 @@ import { getAllAssetsInFolder, isValidASIN, uploadDownloadedImageToSquidexAsAsse import { getMarketplacesUsingJsonQuery, getProductListingsUsingJsonQuery, getProductsUsingJsonQuery } from "../../../data/api-client"; import { SCHEMAS } from "../../../data/models/schemas"; import { logForCommand } from "../common/console"; -import type { ContentsPutContentRequest } from "@squidex/squidex/dist/generated/apis/ContentsApi"; export const COMMAND_NAME = 'append-images'; @@ -98,10 +97,12 @@ export const amazonAppendImagesCommand = (amazonCommand: Command) => } if (didUpdate) { log(`Listing did update, updating product listing with appended images.`); - let updatedDto = await core.client.contents.putContent(SCHEMAS.LISTINGS, listingDto.id, { + let updatedDto = await core.client.contents.putContent({ + schema: SCHEMAS.LISTINGS, + id: listingDto.id, unpublished: false, requestBody: listing as any, - } as ContentsPutContentRequest as any); + }); log(`Listing version ${updatedDto.version} stored.`); } } diff --git a/src/apps/catalog/common/catalog-helpers.ts b/src/apps/catalog/common/catalog-helpers.ts index aeb0e6e..70e0ded 100644 --- a/src/apps/catalog/common/catalog-helpers.ts +++ b/src/apps/catalog/common/catalog-helpers.ts @@ -28,7 +28,7 @@ export function isValidASIN(asinOrNot: string) { } export async function getAmazonGetItemsRequestSchemaDto() { - return await client.schemas.getSchema('amazon-pa-get-items-request'); + return await client.schemas.getSchema({ schema: 'amazon-pa-get-items-request' }); } export async function lookupAmazonASINs(asins: string[]) { @@ -48,17 +48,21 @@ export async function lookupAmazonASINs(asins: string[]) { ] } }, requestDate: { iv: requestDate } } - let amazonGetItemDto = await client.contents.postContent(SCHEMAS.AMAZON_GET_ITEMS, { ...amazonGetItem }, { publish: true }) + let amazonGetItemDto = await client.contents.postContent({ + schema: SCHEMAS.AMAZON_GET_ITEMS, + publish: true, + requestBody: amazonGetItem as any, + }) let amazonGetItemsDto = await getContentsByIds(SCHEMAS.AMAZON_GET_ITEMS, amazonGetItemDto.id); return amazonGetItemsDto; } export async function getMarketplaceConnectionSchemaDto() { - return await client.schemas.getSchema('product-marketplace-connection'); + return await client.schemas.getSchema({ schema: 'product-marketplace-connection' }); } export async function getAmazonMarketplaceConnectionSchemaDto() { - return await client.schemas.getSchema('product-marketplace-connection-amazon') + return await client.schemas.getSchema({ schema: 'product-marketplace-connection-amazon' }) } export async function getAmazonMarketplaceDto() { @@ -96,19 +100,22 @@ export async function getBrandDtoByName(brandName: string) { } export async function getAddNewBrandDtoByName(brandName: string) { - let brandDto = await client.contents.postContent(SCHEMAS.BRANDS, { - brandName: { - "en-US": brandName!, - "es-US": brandName!, - "fr-CA": brandName! - }, - slug: { - "en-US": `en-US/${slugify(brandName!, { lower: true, trim: true })}`, - "es-US": `es-US/${slugify(brandName!, { lower: true, trim: true })}`, - "fr-CA": `fr-CA/${slugify(brandName!, { lower: true, trim: true })}` - }, + let brandDto = await client.contents.postContent({ + schema: SCHEMAS.BRANDS, + requestBody: { + brandName: { + "en-US": brandName!, + "es-US": brandName!, + "fr-CA": brandName! + }, + slug: { + "en-US": `en-US/${slugify(brandName!, { lower: true, trim: true })}`, + "es-US": `es-US/${slugify(brandName!, { lower: true, trim: true })}`, + "fr-CA": `fr-CA/${slugify(brandName!, { lower: true, trim: true })}` + }, + } }); - let brandsDto = await client.contents.getContents(SCHEMAS.BRANDS, { unpublished: true, ids: brandDto.id }) as ContentsDto; + let brandsDto = await client.contents.getContents({ schema: SCHEMAS.BRANDS, unpublished: true, ids: brandDto.id }) as ContentsDto; return brandsDto; } @@ -123,19 +130,22 @@ export async function getSellerDtoByName(sellerName: string) { } export async function getAddNewSellerDtoByName(sellerName: string) { - let sellerDto = await client.contents.postContent(SCHEMAS.SELLERS, { - sellerName: { - "en-US": sellerName!, - "es-US": sellerName!, - "fr-CA": sellerName! - }, - slug: { - "en-US": `en-US/${slugify(sellerName!, { lower: true, trim: true })}`, - "es-US": `es-US/${slugify(sellerName!, { lower: true, trim: true })}`, - "fr-CA": `fr-CA/${slugify(sellerName!, { lower: true, trim: true })}` - }, + let sellerDto = await client.contents.postContent({ + schema: SCHEMAS.SELLERS, + requestBody: { + sellerName: { + "en-US": sellerName!, + "es-US": sellerName!, + "fr-CA": sellerName! + }, + slug: { + "en-US": `en-US/${slugify(sellerName!, { lower: true, trim: true })}`, + "es-US": `es-US/${slugify(sellerName!, { lower: true, trim: true })}`, + "fr-CA": `fr-CA/${slugify(sellerName!, { lower: true, trim: true })}` + }, + } }); - let sellersDto = await client.contents.getContents(SCHEMAS.SELLERS, { unpublished: true, ids: sellerDto.id }) as ContentsDto; + let sellersDto = await client.contents.getContents({ schema: SCHEMAS.SELLERS, unpublished: true, ids: sellerDto.id }) as ContentsDto; return sellersDto; } @@ -398,14 +408,16 @@ export async function translateTags_from_en_US_to_fr_CA(tags_en_US: string[]) { } export async function getAddNewProductSubCategoryDto(parentProductCategoryId: NonLocalized, categoryName: Localized, description: Localized) { - let productCategoryDto = await client.contents.postContent(SCHEMAS.PRODUCT_CATEGORIES, { - categoryName, - description, - parentCategory: parentProductCategoryId, - }, { + let productCategoryDto = await client.contents.postContent({ + schema: SCHEMAS.PRODUCT_CATEGORIES, publish: false, + requestBody: { + categoryName, + description, + parentCategory: parentProductCategoryId, + }, }); - let productCategoriesDto = await client.contents.getContents(SCHEMAS.PRODUCT_CATEGORIES, { unpublished: true, ids: productCategoryDto.id }) as ContentsDto; + let productCategoriesDto = await client.contents.getContents({ schema: SCHEMAS.PRODUCT_CATEGORIES, unpublished: true, ids: productCategoryDto.id }) as ContentsDto; return productCategoriesDto; } @@ -436,16 +448,26 @@ export async function translateAmazonDescription_from_en_US_to_fr_CA(brandName: } export async function getAddNewProductDtoByProduct(product: Product) { - let productDto = await client.contents.postContent(SCHEMAS.PRODUCTS, { ...product }, { publish: false }); - let productsDto = await client.contents.getContents(SCHEMAS.PRODUCTS, { unpublished: true, ids: productDto.id }) as ContentsDto; + let productDto = await client.contents.postContent({ + schema: SCHEMAS.PRODUCTS, + publish: false, + requestBody: { + ...product + }, + }); + let productsDto = await client.contents.getContents({ schema: SCHEMAS.PRODUCTS, unpublished: true, ids: productDto.id }) as ContentsDto; return productsDto; } export async function getAddNewProductListingDtoByProduct(listing: Listing) { - let listingDto = await client.contents.postContent(SCHEMAS.LISTINGS, { ...listing }, { + let listingDto = await client.contents.postContent({ + schema: SCHEMAS.LISTINGS, publish: true, + requestBody: { + ...listing + } }); - let listingsDto = await client.contents.getContents(SCHEMAS.LISTINGS, { unpublished: true, ids: listingDto.id }) as ContentsDto; + let listingsDto = await client.contents.getContents({ schema: SCHEMAS.LISTINGS, unpublished: true, ids: listingDto.id }) as ContentsDto; return listingsDto; } @@ -462,7 +484,7 @@ export async function upsertAssetFolder(folderName: string, parentFolderId?: str let assetFolder; let assetFolderLookup = assetFolders.items.filter(folder => folder.folderName === folderName); if (assetFolderLookup.length === 0) { - assetFolder = await client.assets.postAssetFolder({ folderName: folderName, parentId: parentFolderId }); + assetFolder = await client.assets.postAssetFolder({ createAssetFolderDto: { folderName: folderName, parentId: parentFolderId }}); } else { assetFolder = assetFolderLookup[0]; @@ -484,14 +506,20 @@ export async function uploadDownloadedImageToSquidexAsAsset(downloadUrl: string, form.append('fileName', filename); form.append('file', blob, filename); form.append('parentId', assetFolderId); - let assetDto = await client.assets.postAsset({ file: blob, name: filename, url: filename, parentId: assetFolderId }, { body: form }); - assetDto = await client.assets.putAsset(assetDto.id, { metadata: { ...assetDto.metadata, 'amazon-url': downloadUrl }, tags: ['amazon', 'product'] }); + 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; } export async function getAddNewOfferDto(offer: Offer) { - let offerDto = await client.contents.postContent(SCHEMAS.OFFERS, { ...offer }, { publish: true }); - let offersDto = await client.contents.getContents(SCHEMAS.OFFERS, { unpublished: true, ids: offerDto.id }) as ContentsDto; + let offerDto = await client.contents.postContent({ + schema: SCHEMAS.OFFERS, + publish: true, + requestBody: offer as any, + }); + let offersDto = await client.contents.getContents({ schema: SCHEMAS.OFFERS, unpublished: true, ids: offerDto.id }) as ContentsDto; return offersDto; } diff --git a/src/data/api-client.ts b/src/data/api-client.ts index 4716f08..07551a0 100644 --- a/src/data/api-client.ts +++ b/src/data/api-client.ts @@ -320,14 +320,10 @@ export async function performSyncLocalizedSlugs(logFn = console.log) { }); const MAX_TIME_TO_POST_SLUGS = 60;//s logFn("Add", batchAddSlugsQueue.length, "slugs"); - //postContents is deprecated, will loop with postContent - let bulkAddResult = [];//await core.client.contents.postContents(SCHEMAS.SLUGS, { datas: batchAddSlugsQueue as any, publish: true }); - for (let bar = 0; bar < batchAddSlugsQueue.length; bar++) { - bulkAddResult.push(await core.client.contents.postContent(SCHEMAS.SLUGS, batchAddSlugsQueue[bar] as any, { publish: true })); - } + let bulkAddResult = await core.client.contents.postContents({ schema: SCHEMAS.SLUGS, importContentsDto: { datas: batchAddSlugsQueue as any, publish: true } }); logFn("Remove by id", batchRemoveSlugsQueue.length, "slugs"); batchRemoveSlugsQueue.forEach(async (removeId) => { - await core.client.contents.deleteContent(SCHEMAS.SLUGS, removeId) + await core.client.contents.deleteContent({ schema: SCHEMAS.SLUGS, id: removeId }) }) logFn("Finish sync localized slugs.") } diff --git a/src/data/core/client.ts b/src/data/core/client.ts index e0ea15c..e8bc92e 100644 --- a/src/data/core/client.ts +++ b/src/data/core/client.ts @@ -1,6 +1,5 @@ import { config } from "../../config.js"; import { SquidexClient } from "@squidex/squidex"; -import { InMemoryTokenStore } from "@squidex/squidex/dist/wrapper/SquidexClient.js"; import type { ContentsDto } from "../internals/ContentsDtoT.js"; import type { SupportedLocales } from "../internals/LocalizedT.js"; import type { SCHEMAS } from "../models/schemas.js"; @@ -10,7 +9,7 @@ export const client = new SquidexClient({ clientId: config.squidexClientId!, clientSecret: config.squidexClientSecret!, environment: config.squidexEnvironment!, - tokenStore: new InMemoryTokenStore(), + tokenStore: new SquidexClient.InMemoryTokenStore(), // tokenStore: new SquidexStorageTokenStore() // Keep the tokens in the local store. // tokenStore: new SquidexStorageTokenStore(sessionStorage, "CustomKey") }); @@ -20,21 +19,21 @@ export const TIMEOUT_IN_SECONDS = 10; /** Asset Handling */ export const getAssetById = async (assetId: string) => ( - await client.assets.getAsset(assetId) + await client.assets.getAsset({ id: assetId }) ); /** Generic Content Handling */ export const getAllContents = async (schema: SCHEMAS|string) => ( - await client.contents.getContents(schema, { }) + await client.contents.getContents({ schema }) ) as ContentsDto; export const getContentsByIds = async (schema: SCHEMAS|string, ids: string) => ( - await client.contents.getContents(schema, { ids }) + await client.contents.getContents({ schema, ids }) ) as ContentsDto; export const getContentsUsingJsonQuery = async (schema: SCHEMAS|string, jsonQuery: string|undefined = undefined) => ( - await client.contents.getContents(schema, { q: jsonQuery }) + await client.contents.getContents({ schema, q: jsonQuery }) ) as ContentsDto; export const getContentsByLangSlug = async (schema: SCHEMAS|string, forLang: SupportedLocales|string, slug: string) => ( diff --git a/src/lib/page-from-models.ts b/src/lib/page-from-models.ts index 40ca5a7..ad969b8 100644 --- a/src/lib/page-from-models.ts +++ b/src/lib/page-from-models.ts @@ -76,7 +76,7 @@ export const genericPageForBrand = ({ brand, brandId, homePageId }: PageForBrand schemaId: '', schemaName: '', keywords: brand.brandName['en-US'], - metaDescription: brand.shortDescription!['en-US'], + metaDescription: brand.shortDescription['en-US'], metaImage: '', metaSocial: [], metaTitle: brand.brandName['en-US'], @@ -85,7 +85,7 @@ export const genericPageForBrand = ({ brand, brandId, homePageId }: PageForBrand schemaId: '', schemaName: '', keywords: brand.brandName['es-US'], - metaDescription: brand.shortDescription!['es-US'], + metaDescription: brand.shortDescription['es-US'], metaImage: '', metaSocial: [], metaTitle: brand.brandName['es-US'], @@ -94,7 +94,7 @@ export const genericPageForBrand = ({ brand, brandId, homePageId }: PageForBrand schemaId: '', schemaName: '', keywords: brand.brandName['fr-CA'], - metaDescription: brand.shortDescription!['fr-CA'], + metaDescription: brand.shortDescription['fr-CA'], metaImage: '', metaSocial: [], metaTitle: brand.brandName['fr-CA'], diff --git a/src/scraper/amazon.ts b/src/scraper/amazon.ts index 5539589..14ec63c 100644 --- a/src/scraper/amazon.ts +++ b/src/scraper/amazon.ts @@ -3,8 +3,8 @@ */ import cheerio, { type CheerioAPI } from 'cheerio'; -import { type AmazonProductDetails } from '../old-data/products/amazon-product-details'; -import { type ProductAttribute } from '../old-data/products/product-attribute'; +import { type AmazonProductDetails } from '../data/products/amazon-product-details'; +import { type ProductAttribute } from '../data/products/product-attribute'; import { parseNumberFromSelector } from './utils'; /**